linux/fs/proc
Ondrej Mosnacek f1aa2eb5ea sysctl: fix proc_dobool() usability
Currently proc_dobool expects a (bool *) in table->data, but sizeof(int)
in table->maxsize, because it uses do_proc_dointvec() directly.

This is unsafe for at least two reasons:
1. A sysctl table definition may use { .data = &variable, .maxsize =
   sizeof(variable) }, not realizing that this makes the sysctl unusable
   (see the Fixes: tag) and that they need to use the completely
   counterintuitive sizeof(int) instead.
2. proc_dobool() will currently try to parse an array of values if given
   .maxsize >= 2*sizeof(int), but will try to write values of type bool
   by offsets of sizeof(int), so it will not work correctly with neither
   an (int *) nor a (bool *). There is no .maxsize validation to prevent
   this.

Fix this by:
1. Constraining proc_dobool() to allow only one value and .maxsize ==
   sizeof(bool).
2. Wrapping the original struct ctl_table in a temporary one with .data
   pointing to a local int variable and .maxsize set to sizeof(int) and
   passing this one to proc_dointvec(), converting the value to/from
   bool as needed (using proc_dou8vec_minmax() as an example).
3. Extending sysctl_check_table() to enforce proc_dobool() expectations.
4. Fixing the proc_dobool() docstring (it was just copy-pasted from
   proc_douintvec, apparently...).
5. Converting all existing proc_dobool() users to set .maxsize to
   sizeof(bool) instead of sizeof(int).

Fixes: 83efeeeb3d ("tty: Allow TIOCSTI to be disabled")
Fixes: a2071573d6 ("sysctl: introduce new proc handler proc_dobool")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
2023-02-21 13:34:07 -08:00
..
array.c ucounts: Split rlimit and ucount values and max values 2022-10-09 16:24:05 -07:00
base.c fs: port ->permission() to pass mnt_idmap 2023-01-19 09:24:28 +01:00
bootconfig.c proc: bootconfig: Add null pointer check 2022-04-02 08:40:09 -04:00
cmdline.c proc: give /proc/cmdline size 2022-11-18 13:55:07 -08:00
consoles.c proc: consoles: use console_list_lock for list iteration 2022-12-02 11:25:02 +01:00
cpuinfo.c x86/aperfmperf: Replace aperfmperf_get_khz() 2022-04-27 20:22:19 +02:00
devices.c proc: mark more files as permanent 2022-10-03 14:21:45 -07:00
fd.c fs.idmapped.v6.3 2023-02-20 11:53:11 -08:00
fd.h fs: port ->permission() to pass mnt_idmap 2023-01-19 09:24:28 +01:00
generic.c fs: port ->getattr() to pass mnt_idmap 2023-01-19 09:24:25 +01:00
inode.c take care to handle NULL ->proc_lseek() 2022-08-14 15:16:18 -04:00
internal.h fs: port ->getattr() to pass mnt_idmap 2023-01-19 09:24:25 +01:00
interrupts.c proc: introduce proc_create_seq{,_data} 2018-05-16 07:23:35 +02:00
Kconfig proc: make config PROC_CHILDREN depend on PROC_FS 2022-10-03 14:21:43 -07:00
kcore.c mm: remove kern_addr_valid() completely 2022-11-08 17:37:18 -08:00
kmsg.c printk changes for 6.1 2022-10-10 11:24:19 -07:00
loadavg.c proc: mark more files as permanent 2022-10-03 14:21:45 -07:00
Makefile proc: bootconfig: Add /proc/bootconfig to show boot config list 2020-01-13 13:19:39 -05:00
meminfo.c proc/meminfo: fix spacing in SecPageTables 2022-11-22 18:50:44 -08:00
namespaces.c Merge branch 'work.openat2' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2020-01-29 11:20:24 -08:00
nommu.c proc: delete unused <linux/uaccess.h> includes 2022-07-17 17:31:39 -07:00
page.c mm: Add PG_arch_3 page flag 2022-11-29 09:26:07 +00:00
proc_net.c fs: port ->getattr() to pass mnt_idmap 2023-01-19 09:24:25 +01:00
proc_sysctl.c sysctl: fix proc_dobool() usability 2023-02-21 13:34:07 -08:00
proc_tty.c proc: delete unused <linux/uaccess.h> includes 2022-07-17 17:31:39 -07:00
root.c fs: port ->getattr() to pass mnt_idmap 2023-01-19 09:24:25 +01:00
self.c Revert "proc: don't allow async path resolution of /proc/self components" 2021-02-23 20:32:11 -07:00
softirqs.c proc: mark more files as permanent 2022-10-03 14:21:45 -07:00
stat.c fs/proc/uptime.c: Fix idle time reporting in /proc/uptime 2021-10-05 15:51:35 +02:00
task_mmu.c mm: hugetlb: proc: check for hugetlb shared PMD in /proc/PID/smaps 2023-01-31 16:44:09 -08:00
task_nommu.c proc: remove VMA rbtree use from nommu 2022-09-26 19:46:16 -07:00
thread_self.c Revert "proc: don't allow async path resolution of /proc/thread-self components" 2021-02-23 20:32:11 -07:00
uptime.c proc: mark more files as permanent 2022-10-03 14:21:45 -07:00
util.c fs/proc/util.c: include fs/proc/internal.h for name_to_int() 2019-01-04 13:13:45 -08:00
version.c proc: mark more files as permanent 2022-10-03 14:21:45 -07:00
vmcore.c iov_iter work; most of that is about getting rid of 2022-12-12 18:29:54 -08:00