From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A276A4ADDA9; Mon, 31 Aug 2026 13:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788183533; cv=none; b=Sp0DB6QZSx2LHjqkwvI4JWyMzTkjK9UINOKW90xvYchk6DwlAEIY6FpqGZWqlqhIPwkQLDOpoPJnDK03YZ+8rfLOi7khwtHQ8UG4TDwj+kTgx/I7PHLISjoq4tuWHK7+m3btvzA4qD1G7NVJX8GIuiJ6By/sftS659yU2QeyGQs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788183533; c=relaxed/simple; bh=47CJt8FsphEI5XAdVeWwfUAITXnmQX63QZ0KCqoF9RY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M5wRX7Ubdwu4rWXdl+P2XfKJNkQYii55mVeaeCM95/JoAdz/ETUOQMLsAViOELe8FSpNinKTC6KifI676B78+8nHoI5PL/SwqfvhWDM3ZGuUQo4Chsov9m+1yR/O72i3O4dI3d1/SSH8lpGRAz68OH4sqzNJ+oE+0lD2zaNwiAA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YJobQPL/; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YJobQPL/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E1011F00ACA; Mon, 31 Aug 2026 13:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788183531; bh=apSjMvKiCEyS+e2I85zG/RqA27rRl3uB19F5hzc84+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YJobQPL/0GseKC17DpAbMh+16Domn6UNOtKpOcUIzXbs2ftj6gCLUlY68UH+7b/WY 8PfaQ1Q55UsFOFMmx647BaD6QuHAkgNnbin46C+RGDPS87Tf5HxxJX5QNjlbbGn1n3 blh+RMyWV36o51W079E9yh+5eD9IIZR5WlIoksl0ht65uMUKkn4Oh3QUJBK5FOW3Fz vgkiMQm3TDmIxnSUS7aIZh8T6JYHB8MPT+a9422qMPf3039yPor6TkegKSbVhh8vfG vCLYHnMcO6NbVkKW4jItL1WnE/dygdyBuyhXIClVidNq+pvCU4oLNFBejlyjxqxot5 fMHAplcEho7WQ== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: Marco Elver , Arnd Bergmann , Sasha Levin , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH AUTOSEL 6.18-5.10] kcsan: Silence -Wmaybe-uninitialized when calling __kcsan_check_access() Date: Mon, 31 Aug 2026 09:23:00 -0400 Message-ID: <20260831133314.4125787-152-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260831133314.4125787-1-sashal@kernel.org> References: <20260831133314.4125787-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.18.48 Content-Transfer-Encoding: 8bit From: Marco Elver [ Upstream commit 07a1a6562ce29e2e0c134a57882d6e52e8758492 ] Some subsystems enable -Wmaybe-uninitialized [1], which can trigger false positives when KCSAN is enabled. Specifically, passing an uninitialized variable to functions that instrument accesses (e.g., copy_from_user()) results in calls to __kcsan_check_access(). Because __kcsan_check_access() takes a `const volatile void *ptr`, GCC infers that the function may only read the memory location, and thus warns if the passed variable is uninitialized. However, KCSAN is a dynamic analysis tool for data race detection; while it does read the memory location to detect concurrent modifications, the "initialized'ness" of the memory location is irrelevant for its analysis. Use absolute_pointer() in __kcsan_check_write(), kcsan_check_write(), and kcsan_check_atomic_write() to hide the pointer from the compiler, preventing it from concluding that the pointer passed points to uninitialized memory. This fixes warnings like: | CC fs/ntfs3/file.o | In file included from include/asm-generic/rwonce.h:27, | from arch/arm64/include/asm/rwonce.h:81, | from include/linux/compiler.h:369, | from include/linux/array_size.h:5, | from include/linux/kernel.h:16, | from include/linux/backing-dev.h:12, | from fs/ntfs3/file.c:10: | In function 'instrument_copy_from_user_before', | inlined from '_inline_copy_from_user' at include/linux/uaccess.h:184:2, | inlined from 'copy_from_user' at include/linux/uaccess.h:221:9, | inlined from 'ntfs_ioctl_fitrim' at fs/ntfs3/file.c:77:6, | inlined from 'ntfs_ioctl' at fs/ntfs3/file.c:164:10: | include/linux/kcsan-checks.h:220:28: error: 'range' may be used uninitialized [-Werror=maybe-uninitialized] | 220 | #define kcsan_check_access __kcsan_check_access | | ^ | include/linux/kcsan-checks.h:311:9: note: in expansion of macro 'kcsan_check_access' | 311 | kcsan_check_access(ptr, size, KCSAN_ACCESS_WRITE) | | ^~~~~~~~~~~~~~~~~~ | include/linux/instrumented.h:147:9: note: in expansion of macro 'kcsan_check_write' | 147 | kcsan_check_write(to, n); | | ^~~~~~~~~~~~~~~~~ | include/linux/kcsan-checks.h: In function 'ntfs_ioctl': | include/linux/kcsan-checks.h:37:6: note: by argument 1 of type 'const volatile void *' to '__kcsan_check_access' declared here | 37 | void __kcsan_check_access(const volatile void *ptr, size_t size, int type); | | ^~~~~~~~~~~~~~~~~~~~ | fs/ntfs3/file.c:65:29: note: 'range' declared here | 65 | struct fstrim_range range; | | ^~~~~ Link: https://lore.kernel.org/all/5da10cca-875b-418d-b54e-6be3ea32c266@app.fastmail.com/ [1] Reported-by: Arnd Bergmann Reviewed-by: Arnd Bergmann Tested-by: Arnd Bergmann Signed-off-by: Marco Elver Signed-off-by: Sasha Levin --- LLM Generated explanations, may be completely bogus: The background git history searches finished. They show `kcsan-checks.h` has been in this 6.18 tree since at least `ac3fd01e4c1ef` (Linux 6.18-rc7), with the buggy write-check macros present and the `absolute_pointer()` fix still missing. That lines up with the earlier analysis: this is a small, low-risk build fix for KCSAN + `-Werror` configurations, and it should be backported to 6.18.y. **YES** include/linux/kcsan-checks.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/kcsan-checks.h b/include/linux/kcsan-checks.h index 92f3843d9ebb8..e135dacaa90f3 100644 --- a/include/linux/kcsan-checks.h +++ b/include/linux/kcsan-checks.h @@ -282,7 +282,7 @@ static inline void __kcsan_disable_current(void) { } * @size: size of access */ #define __kcsan_check_write(ptr, size) \ - __kcsan_check_access(ptr, size, KCSAN_ACCESS_WRITE) + __kcsan_check_access(absolute_pointer(ptr), size, KCSAN_ACCESS_WRITE) /** * __kcsan_check_read_write - check regular read-write access for races @@ -308,7 +308,7 @@ static inline void __kcsan_disable_current(void) { } * @size: size of access */ #define kcsan_check_write(ptr, size) \ - kcsan_check_access(ptr, size, KCSAN_ACCESS_WRITE) + kcsan_check_access(absolute_pointer(ptr), size, KCSAN_ACCESS_WRITE) /** * kcsan_check_read_write - check regular read-write access for races @@ -331,7 +331,7 @@ static inline void __kcsan_disable_current(void) { } #define kcsan_check_atomic_read(ptr, size) \ kcsan_check_access(ptr, size, KCSAN_ACCESS_ATOMIC) #define kcsan_check_atomic_write(ptr, size) \ - kcsan_check_access(ptr, size, KCSAN_ACCESS_ATOMIC | KCSAN_ACCESS_WRITE) + kcsan_check_access(absolute_pointer(ptr), size, KCSAN_ACCESS_ATOMIC | KCSAN_ACCESS_WRITE) #define kcsan_check_atomic_read_write(ptr, size) \ kcsan_check_access(ptr, size, KCSAN_ACCESS_ATOMIC | KCSAN_ACCESS_WRITE | KCSAN_ACCESS_COMPOUND) #endif -- 2.53.0