Re: [PATCH] lkdtm/usercopy: Avoid unsequenced accesses to cache_size in lkdtm_usercopy_init()
From: Arnd Bergmann
Date: Sun Nov 15 2026 - 10:19:00 EST
On Sun, Nov 15, 2026, at 05:37, Nathan Chancellor wrote:
> After a recent improvement in clang to warn on unsequenced accesses to
> volatile variables [1], an instance appears in lkdtm_usercopy_init(),
> which can break the build with CONFIG_WERROR=y / W=e:
>
> drivers/misc/lkdtm/usercopy.c:431:9: error: unsequenced accesses to
> volatile qualified 'cache_size' [-Werror,-Wunsequenced]
> 429 | kmem_cache_create_usercopy("lkdtm-usercopy",
> cache_size,
> |
> ~~~~~~~~~~
> 430 | 0, 0,
> 431 | cache_size / 4,
> | ^
>
> Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11
> 6.5.2, unsequenced side effects on the same scalar object are undefined
> behavior. Per C11 6.5.2.2.10/12, the evaluation of arguments in a
> function call is indeterminately sequenced, meaning any side effects in
> the arguments are unsequenced.
>
> cache_size is marked as volatile to hide its value from the compile time
> constant checks in the hardened usercopy routines. Refactor the
> calculations based on cache_size into their own volatile variables to
> keep the values hidden while avoiding unsequenced accesses on the same
> object.
>
> Cc: stable@xxxxxxxxxxxxxxx
> Fixes: e47e311843de ("lkdtm: Update usercopy tests for whitelisting")
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2195
> Link:
> https://github.com/llvm/llvm-project/commit/955715460eaf9188c241c74750637fc82dfcc423
> [1]
> Signed-off-by: Nathan Chancellor <nathan@xxxxxxxxxx>
lgtm,
Acked-by: Arnd Bergmann <arnd@xxxxxxxx>