]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
platform/x86/amd/hsmp: Ensure sock->metric_tbl_addr is non-NULL
authorSuma Hegde <suma.hegde@amd.com>
Thu, 7 Aug 2025 10:06:37 +0000 (10:06 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Oct 2025 13:09:00 +0000 (14:09 +0100)
commit 2c78fb287e1f430b929f2e49786518350d15605c upstream.

If metric table address is not allocated, accessing metrics_bin will
result in a NULL pointer dereference, so add a check.

Fixes: 5150542b8ec5 ("platform/x86/amd/hsmp: add support for metrics tbl")
Signed-off-by: Suma Hegde <suma.hegde@amd.com>
Link: https://lore.kernel.org/r/20250807100637.952729-1-suma.hegde@amd.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
[ Minor context change fixed. ]
Signed-off-by: Alva Lan <alvalan9@foxmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/platform/x86/amd/hsmp.c

index 8fcf38eed7f00ee01aade6e3e55e20402458d5aa..66deb475f807ac7d6bcc89bce2a7ee97be73cd80 100644 (file)
@@ -569,6 +569,11 @@ static ssize_t hsmp_metric_tbl_read(struct file *filp, struct kobject *kobj,
        if (!sock)
                return -EINVAL;
 
+       if (!sock->metric_tbl_addr) {
+               dev_err(sock->dev, "Metrics table address not available\n");
+               return -ENOMEM;
+       }
+
        /* Do not support lseek(), reads entire metric table */
        if (count < bin_attr->size) {
                dev_err(sock->dev, "Wrong buffer size\n");