]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
sysctl: avoid spurious permanent empty tables
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 5 Aug 2024 09:39:35 +0000 (11:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Oct 2024 10:03:59 +0000 (12:03 +0200)
commit6ad6e167f7fb0babc6cac6850c13d2edb5b725c2
tree0f4a0746a5b57a84cdfccc9dcc58a7d1c1211ff7
parent27b55724d3f781dd6e635e89dc6e2fd78fa81a00
sysctl: avoid spurious permanent empty tables

commit 559d4c6a9d3b60f239493239070eb304edaea594 upstream.

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: 4a7b29f65094 ("sysctl: move sysctl type to ctl_table_header")
Fixes: a35dd3a786f5 ("sysctl: drop now unnecessary out-of-bounds check")
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Closes: https://lore.kernel.org/oe-lkp/202408051453.f638857e-lkp@intel.com
Signed-off-by: Joel Granados <j.granados@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/proc/proc_sysctl.c