Re: [PATCH net] ipv4: clamp MCAST_MSFILTER getsockopt to optlen, not gf_numsrc
From: Greg Kroah-Hartman
Date: Thu Apr 23 2026 - 10:26:30 EST
On Thu, Apr 23, 2026 at 03:57:55PM +0200, Paolo Abeni wrote:
> On 4/20/26 9:26 PM, Greg Kroah-Hartman wrote:
> > @@ -1486,8 +1491,12 @@ static int compat_ip_get_mcast_msfilter(struct sock *sk, sockptr_t optval,
> > gf.gf_interface = gf32.gf_interface;
> > gf.gf_fmode = gf32.gf_fmode;
> > num = gf.gf_numsrc = gf32.gf_numsrc;
> > - gf.gf_group = gf32.gf_group;
> >
> > + if (num > (len - size0) / sizeof(struct sockaddr_storage))
> > + num = (len - size0) / sizeof(struct sockaddr_storage);
> > + gf.gf_numsrc = num;
>
> Since this is exactly the same code added above, likely a common helper
> would be useful.
Useful where else?
> I guess we don't care if this would break bad application passing optval
> area properly sized for gf_numsrc sockets and a small optval, right? I
> don't see how to eventually save them.
I couldn't see how to save them either, and if an application sends bad
data we should be rejecting it, right? Especially as this overflows
things as-is :(
thanks,
greg k-h