RE: [PATCH v3 5/5] minmax: Relax check to allow comparison between int and small unsigned constants.

David Laight
2023-08-14T14:52:48Z

From: Linus Torvalds <torvalds@linux-foundation.org>
> Sent: 10 August 2023 20:47
...
> But using an *unsigned* constant 20 when the other side is signed
> means that now somebody is confused. We should warn.

Then you get 'fixes' like:

int do_tcp_getsockopt(struct sock *sk, int level,
int optname, sockptr_t optval, sockptr_t optlen)
{
struct inet_connection_sock *icsk = inet_csk(sk);
struct tcp_sock *tp = tcp_sk(sk);
struct net *net = sock_net(sk);
int val, len;

if (copy_from_sockptr(&len, optlen, sizeof(int)))
return -EFAULT;

len = min_t(unsigned int, len, sizeof(int));

if (len < 0)
return -EINVAL;

(Spotted while looking to see if the generic getsockopt()
code would let now my driver to kernel_getsockopt() on a SCTP
connection to find out the number of streams.
Seems the BPF people haven't yet required the fully generic change.)

David