lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 27 Apr 2021 11:36:24 -0700
From:   trix@...hat.com
To:     stuyoder@...il.com, laurentiu.tudor@....com, nathan@...nel.org,
        ndesaulniers@...gle.com, gregkh@...uxfoundation.org
Cc:     linux-kernel@...r.kernel.org, clang-built-linux@...glegroups.com,
        Tom Rix <trix@...hat.com>
Subject: [PATCH] bus: fsl-mc: fix improper free of mc_dev

From: Tom Rix <trix@...hat.com>

Clang static analysis reports this error

fsl-mc-bus.c:891:2: warning: Attempt to free released memory
        kfree(mc_dev);
        ^~~~~~~~~~~~~

In this block of code

if (strcmp(obj_desc->type, "dprc") == 0) {
..
  mc_bus = kzalloc(..)
  mc_dev = &mc_bus->mc_dev;

mc_dev is not alloc-ed, so it should not be freed.
Old handler triggers a false positive from checkpatch, so add a
comment and change logic a bit.

Fixes: a042fbed0290 ("staging: fsl-mc: simplify couple of deallocations")
Signed-off-by: Tom Rix <trix@...hat.com>
---
 drivers/bus/fsl-mc/fsl-mc-bus.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
index 380ad1fdb745..fb3e1d8a7f63 100644
--- a/drivers/bus/fsl-mc/fsl-mc-bus.c
+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
@@ -887,8 +887,10 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
 
 error_cleanup_dev:
 	kfree(mc_dev->regions);
+	/* mc_dev is only allocated when it is not part of mc_bus */
+	if (!mc_bus)
+		kfree(mc_dev);
 	kfree(mc_bus);
-	kfree(mc_dev);
 
 	return error;
 }
-- 
2.26.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ