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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153945.GA2507795@dev-arch.thelio-3990X>
Date: Thu, 11 Apr 2024 08:39:45 -0700
From: Nathan Chancellor <nathan@...nel.org>
To: John Stultz <jstultz@...gle.com>
Cc: LKML <linux-kernel@...r.kernel.org>, Shuah Khan <shuah@...nel.org>,
	Anna-Maria Behnsen <anna-maria@...utronix.de>,
	Frederic Weisbecker <frederic@...nel.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Stephen Boyd <sboyd@...nel.org>,
	Nick Desaulniers <ndesaulniers@...gle.com>,
	Bill Wendling <morbo@...gle.com>,
	Justin Stitt <justinstitt@...gle.com>,
	Oleg Nesterov <oleg@...hat.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Edward Liaw <edliaw@...gle.com>,
	Carlos Llamas <cmllamas@...gle.com>, kernel-team@...roid.com,
	linux-kselftest@...r.kernel.org
Subject: Re: [PATCH 2/3] selftests: timers: Fix uninitialized variable
 warning in ksft_min_kernel_version

On Wed, Apr 10, 2024 at 04:26:29PM -0700, John Stultz wrote:
> Building with clang, I see the following warning:
> 
> In file included from posix_timers.c:17:
> ./../kselftest.h:398:6: warning: variable 'major' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized]
>         if (uname(&info) || sscanf(info.release, "%u.%u.", &major, &minor) != 2)
>             ^~~~~~~~~~~~
> ./../kselftest.h:401:9: note: uninitialized use occurs here
>         return major > min_major || (major == min_major && minor >= min_minor);
>                ^~~~~
> 
> This is a bit of a red-herring as if the uname() call did fail,
> we would hit ksft_exit_fail_msg() which should exit.

Correct, although we have not really conveyed that to the compiler,
right? exit() is noreturn, which means all functions that call exit()
unconditionally are also noreturn, such as ksft_exit_fail_msg(). LLVM
will figure this out once it performs inlining and such but that happens
after clang's static analysis phase that this warning occurs in. I think
a better solution would be to add __noreturn to the functions in
tools/testing/selftests/kselftest.h that call exit(), so that the
compiler is aware of this through all pipeline phases, maybe something
like this? It resolves the wawrning for me.

diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 050c5fd01840..29364c9f3332 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -83,6 +83,7 @@
 #define KSFT_XPASS 3
 #define KSFT_SKIP  4
 
+#define __noreturn       __attribute__((__noreturn__))
 #define __printf(a, b)   __attribute__((format(printf, a, b)))
 
 /* counters */
@@ -324,13 +325,13 @@ void ksft_test_result_code(int exit_code, const char *test_name,
 		break;						\
 	} } while (0)
 
-static inline int ksft_exit_pass(void)
+static inline __noreturn int ksft_exit_pass(void)
 {
 	ksft_print_cnts();
 	exit(KSFT_PASS);
 }
 
-static inline int ksft_exit_fail(void)
+static inline __noreturn int ksft_exit_fail(void)
 {
 	ksft_print_cnts();
 	exit(KSFT_FAIL);
@@ -357,7 +358,7 @@ static inline int ksft_exit_fail(void)
 		  ksft_cnt.ksft_xfail +	\
 		  ksft_cnt.ksft_xskip)
 
-static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
+static inline __noreturn __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
 {
 	int saved_errno = errno;
 	va_list args;
@@ -372,7 +373,7 @@ static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
 	exit(KSFT_FAIL);
 }
 
-static inline void ksft_exit_fail_perror(const char *msg)
+static inline __noreturn void ksft_exit_fail_perror(const char *msg)
 {
 #ifndef NOLIBC
 	ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
@@ -385,19 +386,19 @@ static inline void ksft_exit_fail_perror(const char *msg)
 #endif
 }
 
-static inline int ksft_exit_xfail(void)
+static inline __noreturn int ksft_exit_xfail(void)
 {
 	ksft_print_cnts();
 	exit(KSFT_XFAIL);
 }
 
-static inline int ksft_exit_xpass(void)
+static inline __noreturn int ksft_exit_xpass(void)
 {
 	ksft_print_cnts();
 	exit(KSFT_XPASS);
 }
 
-static inline __printf(1, 2) int ksft_exit_skip(const char *msg, ...)
+static inline __noreturn __printf(1, 2) int ksft_exit_skip(const char *msg, ...)
 {
 	int saved_errno = errno;
 	va_list args;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ