[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2024030121-starring-party-7e34@gregkh>
Date: Fri, 1 Mar 2024 12:41:52 +0100
From: Greg KH <gregkh@...uxfoundation.org>
To: Jakub Kicinski <kuba@...nel.org>
Cc: Kees Cook <keescook@...omium.org>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Paolo Abeni <pabeni@...hat.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
netdev@...r.kernel.org, linux-hardening@...r.kernel.org,
Simon Horman <horms@...nel.org>, Jiri Pirko <jiri@...nulli.us>,
Daniel Borkmann <daniel@...earbox.net>,
Coco Li <lixiaoyan@...gle.com>,
Amritha Nambiar <amritha.nambiar@...el.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] netdev: Use flexible array for trailing private bytes
On Thu, Feb 29, 2024 at 10:59:10PM -0800, Jakub Kicinski wrote:
> On Thu, 29 Feb 2024 13:30:22 -0800 Kees Cook wrote:
> > Introduce a new struct net_device_priv that contains struct net_device
> > but also accounts for the commonly trailing bytes through the "size" and
> > "data" members.
>
> I'm a bit unclear on the benefit. Perhaps I'm unaccustomed to "safe C".
>
> > As many dummy struct net_device instances exist still,
> > it is non-trivial to but this flexible array inside struct net_device
>
> put
>
> Non-trivial, meaning what's the challenge?
> We also do somewhat silly things with netdev lifetime, because we can't
> assume netdev gets freed by netdev_free(). Cleaning up the "embedders"
> would be beneficial for multiple reasons.
>
> > itself. But we can add a sanity check in netdev_priv() to catch any
> > attempts to access the private data of a dummy struct.
> >
> > Adjust allocation logic to use the new full structure.
> >
> > Signed-off-by: Kees Cook <keescook@...omium.org>
>
> > diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> > index 118c40258d07..b476809d0bae 100644
> > --- a/include/linux/netdevice.h
> > +++ b/include/linux/netdevice.h
> > @@ -1815,6 +1815,8 @@ enum netdev_stat_type {
> > NETDEV_PCPU_STAT_DSTATS, /* struct pcpu_dstats */
> > };
> >
> > +#define NETDEV_ALIGN 32
>
> Unless someone knows what this is for it should go.
> Align priv to cacheline size.
>
> > /**
> > * struct net_device - The DEVICE structure.
> > *
>
> > @@ -2665,7 +2673,14 @@ void dev_net_set(struct net_device *dev, struct net *net)
> > */
> > static inline void *netdev_priv(const struct net_device *dev)
> > {
> > - return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
> > + struct net_device_priv *priv;
> > +
> > + /* Dummy struct net_device have no trailing data. */
> > + if (WARN_ON_ONCE(dev->reg_state == NETREG_DUMMY))
> > + return NULL;
>
> This is a static inline with roughly 11,000 call sites, according to
> a quick grep. Aren't WARN_ONCE() in static inlines creating a "once"
> object in every compilation unit where they get used?
It also, if this every trips, will reboot the box for those that run
with panic-on-warn set, is that something that you all really want?
thanks,
greg k-h
Powered by blists - more mailing lists