diff mbox series

[v3] cxl: Fix possible null pointer dereference in read_handle()

Message ID 20240714121404.1385892-1-make24@iscas.ac.cn (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series [v3] cxl: Fix possible null pointer dereference in read_handle() | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 5 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 21 jobs.

Commit Message

Ma Ke July 14, 2024, 12:14 p.m. UTC
In read_handle(), of_get_address() may return NULL which is later
dereferenced. Fix this by adding NULL check.

Based on our customized static analysis tool, extract vulnerability
features[1], then match similar vulnerability features in this function.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit
/?id=2d9adecc88ab678785b581ab021f039372c324cb

Cc: stable@vger.kernel.org
Fixes: 14baf4d9c739 ("cxl: Add guest-specific code")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v3:
- fixed up the changelog text as suggestions.
Changes in v2:
- added an explanation of how the potential vulnerability was discovered,
but not meet the description specification requirements.
---
 drivers/misc/cxl/of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Greg KH July 14, 2024, 1:37 p.m. UTC | #1
On Sun, Jul 14, 2024 at 08:14:04PM +0800, Ma Ke wrote:
> In read_handle(), of_get_address() may return NULL which is later
> dereferenced. Fix this by adding NULL check.
> 
> Based on our customized static analysis tool, extract vulnerability
> features[1], then match similar vulnerability features in this function.

Please follow the documented rules for researchers submitting patches
based on non-public tools.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/misc/cxl/of.c b/drivers/misc/cxl/of.c
index bcc005dff1c0..d8dbb3723951 100644
--- a/drivers/misc/cxl/of.c
+++ b/drivers/misc/cxl/of.c
@@ -58,7 +58,7 @@  static int read_handle(struct device_node *np, u64 *handle)
 
 	/* Get address and size of the node */
 	prop = of_get_address(np, 0, &size, NULL);
-	if (size)
+	if (!prop || size)
 		return -EINVAL;
 
 	/* Helper to read a big number; size is in cells (not bytes) */