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:   Wed, 24 Aug 2022 13:56:37 +0800
From:   Zhouyi Zhou <zhouzhouyi@...il.com>
To:     akpm@...ux-foundation.org, nathan@...nel.org,
        ndesaulniers@...gle.com, trix@...hat.com, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, llvm@...ts.linux.dev
Cc:     Zhouyi Zhou <zhouzhouyi@...il.com>
Subject: [PATCH linux-next] mm: fix used but uninitialized variable

In function walk_hugetlb_range, the local variable err may
be used uninitialzed when:
ops->pte_hole in side of "else if (ops->pte_hole)" is false.

Signed-off-by: Zhouyi Zhou <zhouzhouyi@...il.com>
---
Dear mm Developers:

When I build kernel using "make CC=clang-14"
the compiler complains following:

CC      mm/pagewalk.o
mm/pagewalk.c:318:12: error: variable 'err' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
                else if (ops->pte_hole)
                         ^~~~~~~~~~~~~
mm/pagewalk.c:321:7: note: uninitialized use occurs here
                if (err)
                    ^~~
mm/pagewalk.c:318:8: note: remove the 'if' if its condition is always true
                else if (ops->pte_hole)
                     ^~~~~~~~~~~~~~~~~~
mm/pagewalk.c:311:10: note: initialize the variable 'err' to silence this warning
                int err;
                       ^
                        = 0
1 error generated.
make[1]: *** [scripts/Makefile.build:250: mm/pagewalk.o] Error 1
make: *** [Makefile:2006: mm] Error 2

I initialize that variable outside of the for loop because we can assign 0 to err
only once in this function.

After my fix, I can compile the kernel. 

Many Thanks
Zhouyi
--
 mm/pagewalk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index 54b2a1beeeb3..b6eb330e8ecd 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -306,9 +306,9 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end,
 	unsigned long hmask = huge_page_mask(h);
 	unsigned long sz = huge_page_size(h);
 	const struct mm_walk_ops *ops = walk->ops;
+	int err = 0;
 
 	for (; addr < end; addr = next) {
-		int err;
 		pte_t *pte = huge_pte_offset(walk->mm, addr & hmask, sz);
 
 		next = hugetlb_entry_end(h, addr, end);
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ