Skip to content

Commit 559d4c6

Browse files
t-8chJoelgranados
authored andcommitted
sysctl: avoid spurious permanent empty tables
The test if a table is a permanently empty one, inspects the address of the registered ctl_table argument. However as sysctl_mount_point is an empty array and does not occupy and space it can end up sharing an address with another object in memory. If that other object itself is a "struct ctl_table" then registering that table will fail as it's incorrectly recognized as permanently empty. Avoid this issue by adding a dummy element to the array so that is not empty anymore. Explicitly register the table with zero elements as otherwise the dummy element would be recognized as a sentinel element which would lead to a runtime warning from the sysctl core. While the issue seems not being encountered at this time, this seems mostly to be due to luck. Also a future change, constifying sysctl_mount_point and root_table, can reliably trigger this issue on clang 18. Given that empty arrays are non-standard in the first place it seems prudent to avoid them if possible. Fixes: 4a7b29f ("sysctl: move sysctl type to ctl_table_header") Fixes: a35dd3a ("sysctl: drop now unnecessary out-of-bounds check") Cc: [email protected] Signed-off-by: Thomas Weißschuh <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Signed-off-by: Joel Granados <[email protected]>
1 parent 5be63fc commit 559d4c6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

fs/proc/proc_sysctl.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ static const struct inode_operations proc_sys_inode_operations;
2929
static const struct file_operations proc_sys_dir_file_operations;
3030
static const struct inode_operations proc_sys_dir_operations;
3131

32-
/* Support for permanently empty directories */
33-
static struct ctl_table sysctl_mount_point[] = { };
32+
/*
33+
* Support for permanently empty directories.
34+
* Must be non-empty to avoid sharing an address with other tables.
35+
*/
36+
static struct ctl_table sysctl_mount_point[] = {
37+
{ }
38+
};
3439

3540
/**
3641
* register_sysctl_mount_point() - registers a sysctl mount point
@@ -42,7 +47,7 @@ static struct ctl_table sysctl_mount_point[] = { };
4247
*/
4348
struct ctl_table_header *register_sysctl_mount_point(const char *path)
4449
{
45-
return register_sysctl(path, sysctl_mount_point);
50+
return register_sysctl_sz(path, sysctl_mount_point, 0);
4651
}
4752
EXPORT_SYMBOL(register_sysctl_mount_point);
4853

0 commit comments

Comments
 (0)