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: 83efeeeb3d04 ("tty: Allow TIOCSTI to be disabled")
Fixes: a2071573d634 ("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
..
2023-02-20 11:53:11 -08:00
2023-02-20 14:10:36 -08:00
2023-02-20 14:27:21 -08:00
2023-02-21 10:45:51 -08:00
2023-02-20 14:27:21 -08:00
2023-02-20 14:27:21 -08:00
2023-02-21 11:07:23 -08:00
2023-02-20 12:33:41 -08:00
2023-02-20 13:05:24 -08:00
2023-01-19 09:24:28 +01:00
2023-02-20 12:23:40 -08:00
2023-02-20 14:10:36 -08:00
2023-02-20 14:10:36 -08:00
2023-02-21 11:07:23 -08:00
2023-02-20 12:33:41 -08:00
2023-02-20 14:10:36 -08:00
2023-01-31 16:44:08 -08:00
2023-02-20 11:53:11 -08:00
2023-02-20 11:53:11 -08:00
2023-02-20 14:10:36 -08:00
2023-02-20 14:10:36 -08:00
2023-02-15 19:38:53 +01:00
2023-01-19 09:24:28 +01:00
2023-02-20 14:10:36 -08:00
2023-01-19 09:24:28 +01:00
2023-02-20 11:53:11 -08:00
2023-02-21 13:34:07 -08:00
2023-02-20 14:27:21 -08:00
2023-02-20 11:53:11 -08:00
2023-02-20 14:10:36 -08:00
2023-02-21 10:45:51 -08:00
2023-02-20 14:10:36 -08:00
2023-02-20 14:10:36 -08:00
2023-02-20 14:27:21 -08:00
2023-02-20 11:53:11 -08:00
2023-02-21 13:34:07 -08:00
2022-12-23 11:55:54 -08:00
2023-02-21 10:45:51 -08:00
2023-02-20 14:10:36 -08:00
2023-02-20 14:10:36 -08:00
2023-02-20 11:53:11 -08:00
2023-02-20 11:53:11 -08:00
2023-02-03 17:52:24 -08:00
2023-02-20 11:53:11 -08:00
2023-01-31 15:01:20 +01:00
2023-02-20 14:27:21 -08:00
2022-10-10 19:45:17 -07:00
2023-02-20 17:41:08 -08:00
2023-02-20 11:53:11 -08:00
2022-12-15 18:09:48 -08:00
2023-02-20 11:53:11 -08:00
2023-02-20 14:10:36 -08:00
2022-10-10 14:21:11 -07:00
2023-02-20 11:53:11 -08:00
2023-02-21 10:45:51 -08:00
2023-02-20 14:10:36 -08:00
2023-01-19 09:24:30 +01:00
2023-02-20 11:53:11 -08:00
2023-01-19 09:24:30 +01:00
2023-02-20 12:03:55 -08:00
2022-12-21 14:45:25 +01:00
2023-02-20 12:14:33 -08:00
2023-02-20 11:53:11 -08:00
2023-02-20 14:10:36 -08:00
2023-02-20 11:53:11 -08:00
2023-02-20 11:53:11 -08:00