All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Xiang Mei <xmei5@asu.edu>
Cc: netdev@vger.kernel.org, davem@davemloft.net, yotam.gi@gmail.com,
	edumazet@google.com, pabeni@redhat.com, horms@kernel.org,
	bestswngs@gmail.com
Subject: Re: [PATCH net] psample: zero the netlink attribute padding in PSAMPLE_ATTR_DATA
Date: Sat, 13 Jun 2026 17:10:52 -0700	[thread overview]
Message-ID: <20260613171052.0dbdfea4@kernel.org> (raw)
In-Reply-To: <CAPpSM+RuCaNoYFN7JKGDeUScK2-xLjSULA4i8bnChmG05hBaNA@mail.gmail.com>

On Sat, 13 Jun 2026 17:02:39 -0700 Xiang Mei wrote:
> > >       if (data_len) {
> > > -             int nla_len = nla_total_size(data_len);
> > >               struct nlattr *nla;
> > >
> > > -             nla = skb_put(nl_skb, nla_len);
> > > -             nla->nla_type = PSAMPLE_ATTR_DATA;
> > > -             nla->nla_len = nla_attr_size(data_len);
> > > +             nla = nla_reserve(nl_skb, PSAMPLE_ATTR_DATA, data_len);
> > > +             if (!nla)
> > > +                     goto error;
> > >
> > >               if (skb_copy_bits(skb, 0, nla_data(nla), data_len))
> > >                       goto error;
> > >
> > > Let me know if the new patch makes sense.  
> >
> > I assumed the author intentionally was avoiding the memset for
> > the memory we will override with data. Otherwise the whole dance
> > could be avoided and nla_put() would have been the answer.  
> 
> The reason nla_put() isn't used here is that the payload source is the
> sampled skb, which can be nonlinear, so the data has to be gathered with
> skb_copy_bits() rather than a flat memcpy().

That too.

> There is no nla_put() variant that takes an skb source, hence the
> reserve-then-copy.
> 
> But that doesn't require open-coding the attribute: nla_reserve() only
> memsets the alignment padding (nla_padlen), never the data region, so
> nla_reserve() + skb_copy_bits() writes every byte exactly once with no
> redundant memset over the payload. The bug was that the open-coded
> version dropped that padding-zero step.

I find it hard to believe that nla_reserve() was not considered.
It's a widely used function in the networking stack.
Please move on.

  reply	other threads:[~2026-06-14  0:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-07  3:16 [PATCH net] psample: zero the netlink attribute padding in PSAMPLE_ATTR_DATA Xiang Mei
2026-06-07  5:23 ` Xiang Mei
2026-06-10  1:30 ` Jakub Kicinski
2026-06-13 23:33   ` Xiang Mei
2026-06-13 23:48     ` Jakub Kicinski
2026-06-14  0:02       ` Xiang Mei
2026-06-14  0:10         ` Jakub Kicinski [this message]
2026-06-14  3:50           ` Xiang Mei

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=20260613171052.0dbdfea4@kernel.org \
    --to=kuba@kernel.org \
    --cc=bestswngs@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=xmei5@asu.edu \
    --cc=yotam.gi@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.