Re: [PATCH net 1/2] ipv4: mcast: getsockopt: do not overwrite past optlen

Breno Leitao <[email protected]>
Newsgroups org.kernel.vger.netdev,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.