From: Breno Leitao <leitao@debian.org>
To: David Laight <david.laight.linux@gmail.com>
Cc: David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com, stable@vger.kernel.org
Subject: Re: [PATCH net 1/2] ipv4: mcast: getsockopt: do not overwrite past optlen
Date: Tue, 11 Aug 2026 05:19:17 -0700 [thread overview]
Message-ID: <ansQ8gHcKdS_Q_ji@gmail.com> (raw)
In-Reply-To: <20260810222159.409357fa@pumpkin>
On Mon, Aug 10, 2026 at 10:21:59PM +0100, David Laight wrote:
> > You are saying that we have userspace program in the wild that doesn't honour
> > the contract above, right?
>
> I've just looked at the old history, since the code was added in 2.4.22 'optlen'
> has only needed to be the size of the fixed structure on entry and has been
> been updated to be the total size on exit.
> The maximum size of the buffer comes from its sl_count field.
> Code that doesn't use the glibc wrapper could be relying on it.
>
> There were definitely places where the driver code has traditionally not
> checked the length at all - and userspace wouldn't have set it.
> The last might have been in the decnet code.
> I'm pretty sure there are other places where the length provided to getsockopt()
> is only that of the fixed header, variable data then follows the header.
>
> IIRC there is a recently added one for async io.
> Can't remember where.
> It checks the 'header' size and takes the full length from within the header.
> That one definitely requires (and checks) for the short length.
Right, but I want to back up and figure out whether this is a bug that
should be fixed, or a bug that would break userpsace if we fix it.
I'm saying the kernel shouldn't write past optlen. If userspace
doesn't provide a big enough buffer, it shouldn't assume there is one
behind it to write into.
Looking at the existing users, I haven't found any that pass a smaller
optlen than needed, so I don't see anyone being impacted.
On the other hand, you're saying this is how it has always behaved
and there is userspace out there relying on it, so changing it now
would break things, right?
Depending on the answer, we have two paths ahead:
1) We declare these bugs and fix them, and proceed with sanity
2) We need to implement quirks in the getsockopt, which will resize
"optlen" mid-air by looking at headers fields
So my question to you: can you point me to actual software that
passes a "small" optlen and expects the kernel to write past it? That
would help to decide about the two options above.
Thanks,
--breno
next prev parent reply other threads:[~2026-08-11 12:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 9:41 [PATCH net 0/2] net: mcast: do not write past optlen in the source filter getsockopt Breno Leitao
2026-08-06 9:42 ` [PATCH net 1/2] ipv4: mcast: getsockopt: do not overwrite past optlen Breno Leitao
2026-08-07 16:44 ` David Laight
2026-08-10 12:48 ` Breno Leitao
2026-08-10 21:21 ` David Laight
2026-08-11 12:19 ` Breno Leitao [this message]
2026-08-11 15:15 ` Jakub Kicinski
2026-08-11 17:51 ` David Laight
2026-08-06 9:42 ` [PATCH net 2/2] ipv6: mcast: do not write past optlen in the source filter getsockopt Breno Leitao
2026-08-07 16:44 ` David Laight
2026-08-07 14:38 ` [PATCH net 0/2] net: " Simon Horman
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=ansQ8gHcKdS_Q_ji@gmail.com \
--to=leitao@debian.org \
--cc=davem@davemloft.net \
--cc=david.laight.linux@gmail.com \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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