Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fsverity: use register_sysctl_init() to avoid kmemleak warning

Since the fsverity sysctl registration runs as a builtin initcall, there
is no corresponding sysctl deregistration and the resulting struct
ctl_table_header is not used. This can cause a kmemleak warning just
after the system boots up. (A pointer to the ctl_table_header is stored
in the fsverity_sysctl_header static variable, which kmemleak should
detect; however, the compiler can optimize out that variable.) Avoid
the kmemleak warning by using register_sysctl_init() which is intended
for use by builtin initcalls and uses kmemleak_not_leak().

Reported-by: Yi Zhang <yi.zhang@redhat.com>
Closes: https://lore.kernel.org/r/CAHj4cs8DTSvR698UE040rs_pX1k-WVe7aR6N2OoXXuhXJPDC-w@mail.gmail.com
Cc: stable@vger.kernel.org
Reviewed-by: Joel Granados <j.granados@samsung.com>
Link: https://lore.kernel.org/r/20240501025331.594183-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>

+1 -6
+1 -6
fs/verity/init.c
··· 10 10 #include <linux/ratelimit.h> 11 11 12 12 #ifdef CONFIG_SYSCTL 13 - static struct ctl_table_header *fsverity_sysctl_header; 14 - 15 13 static struct ctl_table fsverity_sysctl_table[] = { 16 14 #ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES 17 15 { ··· 26 28 27 29 static void __init fsverity_init_sysctl(void) 28 30 { 29 - fsverity_sysctl_header = register_sysctl("fs/verity", 30 - fsverity_sysctl_table); 31 - if (!fsverity_sysctl_header) 32 - panic("fsverity sysctl registration failed"); 31 + register_sysctl_init("fs/verity", fsverity_sysctl_table); 33 32 } 34 33 #else /* CONFIG_SYSCTL */ 35 34 static inline void fsverity_init_sysctl(void)