lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK7LNARvJEhEOwg_PHe3WKT9BkSchnGOmeiUaB+7E__NS9qrVw@mail.gmail.com>
Date:   Tue, 26 Jul 2022 18:25:51 +0900
From:   Masahiro Yamada <masahiroy@...nel.org>
To:     Mauricio Faria de Oliveira <mfo@...onical.com>
Cc:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        linux-modules <linux-modules@...r.kernel.org>,
        Linux Kbuild mailing list <linux-kbuild@...r.kernel.org>,
        Linux FS-devel Mailing List <linux-fsdevel@...r.kernel.org>,
        Michal Marek <michal.lkml@...kovi.net>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Luis Chamberlain <mcgrof@...nel.org>,
        Kees Cook <keescook@...omium.org>,
        Iurii Zaikin <yzaikin@...gle.com>
Subject: Re: [RFC PATCH 3/6] sysctl, mod_devicetable: shadow struct
 ctl_table.procname for file2alias

On Fri, Jul 22, 2022 at 11:24 AM Mauricio Faria de Oliveira
<mfo@...onical.com> wrote:
>
> In order to expose a sysctl entry to modpost (file2alias.c, precisely)
> we have to shadow 'struct ctl_table' in mod_devicetable.h, as scripts
> should not access kernel headers or its types (see file2alias.c).
>
> The required field is '.procname' (basename of '/proc/sys/.../entry').
>
> Since 'struct ctl_table' is annotated for structure randomization and
> we need a known offset for '.procname' (remember, no kernel headers),
> take it out of the randomized portion (as in, eg, 'struct task_struct').
>
> Of course, add build-time checks for struct size and .procname offset
> between both structs. (This has to be done on kernel side; for headers.)
>
> With that in place, use the regular macros in devicetable-offsets.c to
> define SIZE_... and OFF_... macros for the shadow struct and the field
> of interest.
>
> Signed-off-by: Mauricio Faria de Oliveira <mfo@...onical.com>
> ---
>  fs/proc/proc_sysctl.c             | 19 +++++++++++++++++++
>  include/linux/mod_devicetable.h   | 25 +++++++++++++++++++++++++
>  include/linux/sysctl.h            | 11 ++++++++++-
>  kernel/sysctl.c                   |  1 +
>  scripts/mod/devicetable-offsets.c |  3 +++
>  5 files changed, 58 insertions(+), 1 deletion(-)
>
> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> index 021e83fe831f..ebbf8702387e 100644
> --- a/fs/proc/proc_sysctl.c
> +++ b/fs/proc/proc_sysctl.c
> @@ -19,6 +19,24 @@
>  #include <linux/kmemleak.h>
>  #include "internal.h"
>
> +#ifdef CONFIG_MODULES
> +#include <linux/mod_devicetable.h>
> +
> +static void check_struct_sysctl_device_id(void)
> +{
> +       /*
> +        * The shadow struct sysctl_device_id for file2alias.c needs
> +        * the same size of struct ctl_table and offset for procname.
> +        */
> +       BUILD_BUG_ON(sizeof(struct sysctl_device_id)
> +                       != sizeof(struct ctl_table));
> +       BUILD_BUG_ON(offsetof(struct sysctl_device_id, procname)
> +                       != offsetof(struct ctl_table, procname));


Nit:

If you use static_assert(), you can remove
 check_struct_sysctl_device_id().


You can write static_assert() out of a function.



> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 223376959d29..15073621cfa8 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -2487,6 +2487,7 @@ int __init sysctl_init_bases(void)
>
>         return 0;
>  }
> +


Noise.




>  #endif /* CONFIG_SYSCTL */
>  /*
>   * No sense putting this after each symbol definition, twice,
> diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
> index c0d3bcb99138..43b2549940d2 100644
> --- a/scripts/mod/devicetable-offsets.c
> +++ b/scripts/mod/devicetable-offsets.c
> @@ -262,5 +262,8 @@ int main(void)
>         DEVID(ishtp_device_id);
>         DEVID_FIELD(ishtp_device_id, guid);
>
> +       DEVID(sysctl_device_id);
> +       DEVID_FIELD(sysctl_device_id, procname);
> +
>         return 0;
>  }
> --
> 2.25.1
>


-- 
Best Regards
Masahiro Yamada

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ