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]
Message-Id: <20200714130509.11791-1-trix@redhat.com>
Date:   Tue, 14 Jul 2020 06:05:09 -0700
From:   trix@...hat.com
To:     jack@...e.cz, william.kucharski@...cle.com, jeffm@...e.com,
        willy@...radead.org, joseph.qi@...ux.alibaba.com,
        liao.pingfang@....com.cn
Cc:     reiserfs-devel@...r.kernel.org, linux-kernel@...r.kernel.org,
        Tom Rix <trix@...hat.com>
Subject: [PATCH] reiserfs : fix improper free in reiserfs_get_block

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

clang static analysis flags this error

inode.c:1083:5: warning: Argument to kfree() is the address of the
  local variable 'unf_single', which is not memory allocated by
  malloc() [unix.Malloc]
                                kfree(un);
                                ^~~~~~~~~
Assignment of 'un'

	/*
	 * We use this in case we need to allocate
	 * only one block which is a fastpath
	 */
	unp_t unf_single = 0;

	...

	if (blocks_needed == 1) {
		un = &unf_single;
	} else {
		un = kcalloc(min(blocks_needed, max_to_insert),
			     UNFM_P_SIZE, GFP_NOFS);
		if (!un) {
			un = &unf_single;
			blocks_needed = 1;
			max_to_insert = 0;
		}
	}

The logic to free 'un'

	if (blocks_needed != 1)
		kfree(un);

Because the kcalloc failure falls back to using unf_single,
the if-check for the free is wrong.

So improve the check.

Signed-off-by: Tom Rix <trix@...hat.com>
---
 fs/reiserfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 1509775da040..4d62148e43e6 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -1079,7 +1079,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
 						     UNFM_P_SIZE *
 						     blocks_needed);
 
-			if (blocks_needed != 1)
+			if (un != &unf_single)
 				kfree(un);
 
 			if (retval) {
-- 
2.18.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ