Skip to content

Commit 2107d45

Browse files
arjunroykuba-moo
authored andcommitted
tcp: Fix sign comparison bug in getsockopt(TCP_ZEROCOPY_RECEIVE)
getsockopt(TCP_ZEROCOPY_RECEIVE) has a bug where we read a user-provided "len" field of type signed int, and then compare the value to the result of an "offsetofend" operation, which is unsigned. Negative values provided by the user will be promoted to large positive numbers; thus checking that len < offsetofend() will return false when the intention was that it return true. Note that while len is originally checked for negative values earlier on in do_tcp_getsockopt(), subsequent calls to get_user() re-read the value from userspace which may have changed in the meantime. Therefore, re-add the check for negative values after the call to get_user in the handler code for TCP_ZEROCOPY_RECEIVE. Fixes: c8856c0 ("tcp-zerocopy: Return inq along with tcp receive zerocopy.") Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Arjun Roy <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6a4d723 commit 2107d45

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/ipv4/tcp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4143,7 +4143,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
41434143

41444144
if (get_user(len, optlen))
41454145
return -EFAULT;
4146-
if (len < offsetofend(struct tcp_zerocopy_receive, length))
4146+
if (len < 0 ||
4147+
len < offsetofend(struct tcp_zerocopy_receive, length))
41474148
return -EINVAL;
41484149
if (unlikely(len > sizeof(zc))) {
41494150
err = check_zeroed_user(optval + sizeof(zc),

0 commit comments

Comments
 (0)