public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Bharadiya,Pankaj" <pankaj.laxminarayan.bharadiya@intel.com>
To: Kees Cook <keescook@chromium.org>
Cc: pankaj.bharadiya@gmail.com, andriy.shevchenko@linux.intel.com,
	kernel-hardening@lists.openwall.com, akpm@linux-foundation.org,
	mayhs11saini@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] linux/kernel.h: Add sizeof_member macro
Date: Wed, 25 Sep 2019 09:59:18 +0530	[thread overview]
Message-ID: <20190925042917.GA83131@pktinlab> (raw)
In-Reply-To: <201909240920.AE3CD67E87@keescook>

On Tue, Sep 24, 2019 at 09:22:10AM -0700, Kees Cook wrote:
> On Tue, Sep 24, 2019 at 04:28:35PM +0530, Pankaj Bharadiya wrote:
> > At present we have 3 different macros to calculate the size of a
> > member of a struct:
> >   - SIZEOF_FIELD
> >   - FIELD_SIZEOF
> >   - sizeof_field
> > 
> > To bring uniformity in entire kernel source tree let's add
> > sizeof_member macro.
> > 
> > Replace all occurrences of above 3 macro's with sizeof_member in
> > future patches.
> > 
> > Signed-off-by: Pankaj Bharadiya <pankaj.laxminarayan.bharadiya@intel.com>
> > ---
> >  include/linux/kernel.h | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> 
> Since stddef.h ends up needing this macro, and kernel.h includes
> stddef.h, why not put this macro in stddef.h instead? Then the
> open-coded version of it in stddef (your last patch) can use
> sizeof_member()?
> 

If I understood correctly, Andrew suggested to add such macros in kernel.h
https://www.openwall.com/lists/kernel-hardening/2019/06/11/5

Moreover similar type of other macros (like typeof_member & ARRAY_SIZE)
are defined in kernel.h
But as you pointed out, looks like stddef.h is the right place for this macro.

> Otherwise, yes, looks good. (Though I might re-order the patches so the
> last patch is the tree-wide swap -- then you don't need the exclusions,
> I think?)
>

I went through your tree. 
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=kspp/sizeof_member/full
Thank you for reordering the patches.

Thanks,
Pankaj

> -Kees
> 
> > 
> > diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> > index 4fa360a13c1e..0b80d8bb3978 100644
> > --- a/include/linux/kernel.h
> > +++ b/include/linux/kernel.h
> > @@ -79,6 +79,15 @@
> >   */
> >  #define round_down(x, y) ((x) & ~__round_mask(x, y))
> >  
> > +/**
> > + * sizeof_member - get the size of a struct's member
> > + * @T: the target struct
> > + * @m: the target struct's member
> > + * Return: the size of @m in the struct definition without having a
> > + * declared instance of @T.
> > + */
> > +#define sizeof_member(T, m) (sizeof(((T *)0)->m))
> > +
> >  /**
> >   * FIELD_SIZEOF - get the size of a struct's field
> >   * @t: the target struct
> > -- 
> > 2.17.1
> > 
> 
> -- 
> Kees Cook

  reply	other threads:[~2019-09-25  4:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24 10:58 [PATCH 0/5] Add and use sizeof_member macro to bring uniformity Pankaj Bharadiya
2019-09-24 10:58 ` [PATCH 1/5] linux/kernel.h: Add sizeof_member macro Pankaj Bharadiya
2019-09-24 16:22   ` Kees Cook
2019-09-25  4:29     ` Bharadiya,Pankaj [this message]
2019-09-24 10:58 ` [PATCH 2/5] treewide: Use " Pankaj Bharadiya
2019-09-24 10:58 ` [PATCH 3/5] MIPS: OCTEON: use sizeof_member macro instead of SIZEOF_FIELD Pankaj Bharadiya
2019-09-24 10:58 ` [PATCH 4/5] linux/kernel.h: Remove FIELD_SIZEOF macro Pankaj Bharadiya
2019-09-24 10:58 ` [PATCH 5/5] stddef.h: Remove sizeof_field macro Pankaj Bharadiya
2019-09-24 16:28 ` [PATCH 0/5] Add and use sizeof_member macro to bring uniformity Kees Cook
2019-09-24 17:07   ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190925042917.GA83131@pktinlab \
    --to=pankaj.laxminarayan.bharadiya@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mayhs11saini@gmail.com \
    --cc=pankaj.bharadiya@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox