From: Jean-Paul Sergent <jpsergent@gmail.com>
To: Ilya Maximets <i.maximets@ovn.org>
Cc: Jean-Paul Sergent <jpsergent@gmail.com>,
netdev@vger.kernel.org, Kees Cook <kees@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Sridhar Samudrala <sridhar.samudrala@intel.com>,
stable@vger.kernel.org
Subject: Re: [PATCH net v2] net: dst_metadata: fix fortify trap + overread in skb_metadata_dst_cmp
Date: Sat, 3 Oct 2026 15:50:08 -0700 [thread overview]
Message-ID: <20261003225008.1634351-1-jpsergent@gmail.com> (raw)
In-Reply-To: <787c2c1e-1260-43ae-bee0-9798e1e53c2b@ovn.org>
On Sat, Oct 03, 2026 at 03:31:07PM +0200, Ilya Maximets wrote:
> On 10/3/26 3:24 AM, Jean-Paul Sergent wrote:
> > memcmp: detected buffer overflow: 108 byte read of buffer size 96
> > ...
> > Geneve carries 108 bytes of options, and the combined struct+options
> > memcmp trips CONFIG_FORTIFY_SOURCE when built with clang. ...
>
> This doesn't make sense to me. The problem in tun_dst_unclone was
> at the initialization time, where we couldn't write the options_len
> together with the options while the currently stored value is zero.
>
> Here the function just compares two blocks and they must be already
> fully initialized and have options_len properly set. If they have
> options, but the length is zero, that's a bug somewhere else.
Thank you for the review, and I apologize for the noise. You are
completely right on this. I re-tested the case properly with a userspace
test mimicking the FORTIFY_SOURCE check (clang __builtin_dynamic_object_size
on a __counted_by flexible array matching ip_tunnel_info geometry: 96-byte
struct, options at offset 96):
- Equal options_len (12/12): compiler bound 108, memcmp length 108 ->
no trip.
- Unequal options_len (12/0): compiler bound 96, memcmp length 108 ->
trips with the exact reported message: "108 byte read of buffer size 96".
- Same unequal case under ASan: real heap-buffer-overflow, READ of size
108 past b's 96-byte allocation.
So my initial "false positive at allocation time" theory was completely
wrong. The metadata is fully initialized at comparison time, the trip
happens because of unequal options_len, and the out-of-bounds read past
b's allocation is real.
> > While here, fix a related overread: the memcmp length uses
> > a->u.tun_info.options_len for BOTH sides, so when b carries fewer
> > options than a the comparison reads past b's allocation. Pre-check
> > that both sides carry the same options_len
>
> This makes sense and may be the real bug here? If options actually
> have different length for some reason, then the memcmp will rightly
> trigger the fortification check as it should.
>
> However, someone more familiar with GRO should probably look at this
> to see how the comparison should behave when options are different as
> it sounds a little weird that they are.
Yes, this unequal options_len overread is the real bug.
Regarding GRO behavior: in v3 I kept the original pre-2017 semantics
(unequal options_len -> return 1, no aggregation). Aggregating skbs
with differing tunnel options would drop one packet's options, so
rejecting aggregation seems right. I have CC'd the GRO and networking
maintainers to weigh in.
We are also investigating why the two skbs have differing options_len in
our Cilium geneve setup in the first place, but regardless of the cause,
the comparison helper must not overread past b's buffer.
> > and compare the options
> > through ip_tunnel_info_opts() so the counted_by view matches the read
> > length (the same two-stage shape the unclone fix uses).
>
> This makes no sense. Single memcmp should work just fine as long as the
> compared size doesn't exceed the actual size of both memory regions.
>
> Do you still see the fortification issue trigger with just the length
> comparison change?
No, the fortification issue does not trigger with just the length check.
With equal lengths, the compiler bound tracks the allocation and the
single memcmp is completely fine.
v3 drops the two-stage compare entirely and restores the options_len
check before the memcmp.
> > Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
>
> This is likely wrong and should point to the commit that added the
> tunnel info comparison.
Right again. Git history shows that the options_len equality check was
present in the original GRO lightweight tunnel support (commit
ce87fc6ce3f9, "gro: Make GRO aware of lightweight tunnels", 2016), but
was inadvertently dropped when commit 3fcece12bc1b ("net: store
port/representator id in metadata_dst", 2017) switched to a metadata_type
enum.
v3 uses:
Fixes: 3fcece12bc1b ("net: store port/representator id in metadata_dst")
> > Cc: stable@vger.kernel.org
> > Reported-by: Jean-Paul Sergent <jpsergent@gmail.com>
>
> If you are the author you need a sign-off instead of a reported-by.
>
> Also, you're missing a lot of maintainers in the Cc list.
Fixed. Added Signed-off-by and dropped Reported-by. Maintainers from
get_maintainer.pl have been added to the Cc list.
> > Closes: https://lore.kernel.org/netdev/20261003005449.2675.1@jpsergent.gmail.com/
>
> There is no point linking the same thread where you're posting a patch,
> it will be linked anyway on commit.
Dropped the Closes: tag.
> > Assisted-by: LLM
> >
> > v2: fix subject prefix to [PATCH net]; no code changes.
>
> This should not be in the commit message. Also, there should be a link
> to the previous version here.
Moved the changelog below the '---' line with lore links to previous
versions.
> > + /* Options lengths must match, or the options memcmp below
> > + * would read past b's allocation when b carries fewer
> > + * options than a.
> > + */
>
> This is obvious, drop the comment.
>
> > + /* Compare the options through the flex-array member so the
> ...
>
> This part of the change doesn't make much sense, but anyway, when asking
> LLMs to write comments, please ask them to be concise. There is too much
> stuff in there that makes no sense in the context of the code, e.g. the
> mentioning of the "tun_dst_unclone fix", and the comment is generally way
> too long for what it tries to accomplish. It should be 2 lines at most
> in this particular case.
>
> Same applies to the commit message, there is too much fluff in there that
> makes it harder to read.
>
> So, please, do some quality control before sending patches, read what
> you're sending. Don't just shoot out AI slop. Next person may not be
> that kind in their replies.
Point taken, and my sincere apologies. The criticism is entirely fair.
I took an unverified explanation at face value and skipped the build
testing I should have done.
For v3:
- Both comments and the two-stage compare are gone; the fix is a simple
options_len equality check before the memcmp.
- The commit message is rewritten and concise.
- Build-tested locally against net/core/gro.o with clang 22 and
CONFIG_FORTIFY_SOURCE=y (the affected system's kernel config).
- In accordance with netdev rules, I will observe the 24-hour waiting
period from v2 before posting the v3 patch series in a separate thread.
Thanks again for the thorough review.
--
Jean-Paul Sergent
next prev parent reply other threads:[~2026-10-03 22:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-03 1:22 [Bug Report] fortify false-positive + real overread in skb_metadata_dst_cmp (geneve, gro_cell_poll) Jean-Paul Sergent
2026-10-03 1:24 ` [PATCH] net: dst_metadata: fix fortify trap + overread in skb_metadata_dst_cmp Jean-Paul Sergent
2026-10-03 1:24 ` [PATCH net v2] " Jean-Paul Sergent
2026-10-03 13:31 ` Ilya Maximets
2026-10-03 22:50 ` Jean-Paul Sergent [this message]
2026-10-04 1:23 ` Jean-Paul Sergent
2026-10-04 1:26 ` netdev-bot+sashiko
2026-10-04 1:26 ` [PATCH] " netdev-bot+sashiko
2026-10-03 22:33 ` [Bug Report] fortify false-positive + real overread in skb_metadata_dst_cmp (geneve, gro_cell_poll) Sasha Levin
2026-10-03 23:05 ` Jean-Paul Sergent
2026-10-04 16:29 ` Sasha Levin
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=20261003225008.1634351-1-jpsergent@gmail.com \
--to=jpsergent@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=i.maximets@ovn.org \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sridhar.samudrala@intel.com \
--cc=stable@vger.kernel.org \
/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