Re: [PATCH] net: sctp, forbid negative length
From: David Miller
Date: Sun Oct 23 2016 - 17:44:12 EST
From: Jiri Slaby <jslaby@xxxxxxx>
Date: Fri, 21 Oct 2016 14:13:24 +0200
> Most of getsockopt handlers in net/sctp/socket.c check len against
> sizeof some structure like:
> if (len < sizeof(int))
> return -EINVAL;
>
> On the first look, the check seems to be correct. But since len is int
> and sizeof returns size_t, int gets promoted to unsigned size_t too. So
> the test returns false for negative lengths. Yes, (-1 < sizeof(long)) is
> false.
>
> Fix this in sctp by explicitly checking len < 0 before any getsockopt
> handler is called.
>
> Note that sctp_getsockopt_events already handled the negative case.
> Since we added the < 0 check elsewhere, this one can be removed.
>
> If not checked, this is the result:
...
> Signed-off-by: Jiri Slaby <jslaby@xxxxxxx>
Applied and queued up for -stable, thanks.