Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1652205

Re: [PATCH v2] LSM: Convert security_hook_heads into explicit array of struct list_head

From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject Re: [PATCH v2] LSM: Convert security_hook_heads into explicit array of struct list_head
Date 2017-05-28 23:20 +0200
Message-ID <tMdLs-7hB-9@gated-at.bofh.it> (permalink)
References <tLHVg-2Df-13@gated-at.bofh.it> <tMd8K-6Ob-23@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sun, May 28, 2017 at 1:29 PM, Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
> Commit 3dfc9b02864b19f4 ("LSM: Initialize security_hook_heads upon
> registration.") treats "struct security_hook_heads" as an implicit array
> of "struct list_head" so that we can eliminate code for static
> initialization. Although we haven't encountered compilers which do not
> treat sizeof(security_hook_heads) != sizeof(struct list_head) *
> (sizeof(security_hook_heads) / sizeof(struct list_head)), Casey does not
> like the assumption that a structure of N elements can be assumed to be
> the same as an array of N elements.
>
> Now that Kees found that randstruct complains about such casting
>
>   security/security.c: In function 'security_init':
>   security/security.c:59:20: note: found mismatched op0 struct pointer types: 'struct list_head' and 'struct security_hook_heads'
>
>     struct list_head *list = (struct list_head *) &security_hook_heads;
>
> and Christoph thinks that we should fix it rather than make randstruct
> whitelist it, this patch fixes it.
>
> It would be possible to revert commit 3dfc9b02864b19f4, but this patch
> converts security_hook_heads into an explicit array of struct list_head
> by introducing an enum, due to reasons explained below.
>
> Igor proposed a sealable memory allocator, and the LSM hooks
> ("struct security_hook_heads security_hook_heads" and
> "struct security_hook_list ...[]") will benefit from that allocator via
> protection using set_memory_ro()/set_memory_rw(), and that allocator
> will remove CONFIG_SECURITY_WRITABLE_HOOKS config option. Thus, we will
> likely be moving to that direction.
>
> This means that these structures will be allocated at run time using
> that allocator, and therefore the address of these structures will be
> determined at run time rather than compile time.
>
> But currently, LSM_HOOK_INIT() macro depends on the address of
> security_hook_heads being known at compile time. If we use an enum
> so that LSM_HOOK_INIT() macro does not need to know absolute address of
> security_hook_heads, it will help us to use that allocator for LSM hooks.
>
> As a result of introducing an enum, security_hook_heads becomes a local
> variable. In order to pass 80 columns check by scripts/checkpatch.pl ,
> rename security_hook_heads to hook_heads.
>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Stephen Smalley <sds@tycho.nsa.gov>
> Cc: Casey Schaufler <casey@schaufler-ca.com>
> Cc: James Morris <james.l.morris@oracle.com>
> Cc: Igor Stoppa <igor.stoppa@huawei.com>
> Cc: Christoph Hellwig <hch@infradead.org>

Looks good to me; thanks for persisting! :)

Acked-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook
Pixel Security

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] LSM: Convert security_hook_heads into explicit array of struct list_head Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2017-05-27 13:20 +0200
  Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head Casey Schaufler <casey@schaufler-ca.com> - 2017-05-28 00:40 +0200
    Re: [PATCH] LSM: Convert security_hook_heads into explicit array of struct list_head Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2017-05-28 02:40 +0200
  Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head Kees Cook <keescook@chromium.org> - 2017-05-28 03:10 +0200
    Re: [PATCH] LSM: Convert security_hook_heads into explicit array of struct list_head Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2017-05-28 03:30 +0200
      Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head Casey Schaufler <casey@schaufler-ca.com> - 2017-05-28 20:00 +0200
      Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head James Morris <jmorris@namei.org> - 2017-05-30 12:30 +0200
        Re: [PATCH] LSM: Convert security_hook_heads into explicit array of struct list_head Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2017-05-30 16:40 +0200
          Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head Alan Cox <gnomes@lxorguk.ukuu.org.uk> - 2017-05-30 17:30 +0200
            Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head James Morris <jmorris@namei.org> - 2017-05-31 01:10 +0200
              Re: [PATCH] LSM: Convert security_hook_heads into explicit array of struct list_head Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2017-05-31 12:50 +0200
                Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head James Morris <jmorris@namei.org> - 2017-05-31 13:10 +0200
                Re: [PATCH] LSM: Convert security_hook_heads into explicit array of struct list_head Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2017-05-31 13:40 +0200
                Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head Alan Cox <gnomes@lxorguk.ukuu.org.uk> - 2017-05-31 16:50 +0200
                Re: [PATCH] LSM: Convert security_hook_heads into explicit array of struct list_head Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2017-05-31 17:20 +0200
                Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head Alan Cox <gnomes@lxorguk.ukuu.org.uk> - 2017-05-31 17:20 +0200
          Re: [PATCH] LSM: Convert security_hook_heads into explicit array of  struct list_head José Bollo <jobol@nonadev.net> - 2017-05-31 12:00 +0200
  [PATCH v2] LSM: Convert security_hook_heads into explicit array of struct list_head Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2017-05-28 22:40 +0200
    Re: [PATCH v2] LSM: Convert security_hook_heads into explicit array  of struct list_head Kees Cook <keescook@chromium.org> - 2017-05-28 23:20 +0200
    Re: [PATCH v2] LSM: Convert security_hook_heads into explicit array  of struct list_head Casey Schaufler <casey@schaufler-ca.com> - 2017-05-29 19:40 +0200
    Re: [PATCH v2] LSM: Convert security_hook_heads into explicit array  of struct list_head James Morris <jmorris@namei.org> - 2017-05-30 12:40 +0200
      Re: [PATCH v2] LSM: Convert security_hook_heads into explicit array  of struct list_head Igor Stoppa <igor.stoppa@huawei.com> - 2017-05-31 23:00 +0200
        Re: [PATCH v2] LSM: Convert security_hook_heads into explicit array  of struct list_head James Morris <jmorris@namei.org> - 2017-06-01 01:00 +0200

csiph-web