summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArjun Roy <arjunroy@google.com>2021-02-25 15:26:28 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-03-17 17:06:11 +0100
commite95ebe1ed6abc259b897abc1f92622504750747c (patch)
tree6369500370a55c616353378c4e96fc75132ac652
parent473bce9b9393a3a990ed7c9708af38df553f2712 (diff)
downloadlinux-stable-e95ebe1ed6abc259b897abc1f92622504750747c.tar.gz
linux-stable-e95ebe1ed6abc259b897abc1f92622504750747c.tar.bz2
linux-stable-e95ebe1ed6abc259b897abc1f92622504750747c.zip
tcp: Fix sign comparison bug in getsockopt(TCP_ZEROCOPY_RECEIVE)
commit 2107d45f17bedd7dbf4178462da0ac223835a2a7 upstream. 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: c8856c051454 ("tcp-zerocopy: Return inq along with tcp receive zerocopy.") Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Arjun Roy <arjunroy@google.com> Link: https://lore.kernel.org/r/20210225232628.4033281-1-arjunroy.kdev@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--net/ipv4/tcp.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 41d03683b13d..e20ee7f0827c 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3829,7 +3829,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
if (get_user(len, optlen))
return -EFAULT;
- if (len < offsetofend(struct tcp_zerocopy_receive, length))
+ if (len < 0 ||
+ len < offsetofend(struct tcp_zerocopy_receive, length))
return -EINVAL;
if (len > sizeof(zc)) {
len = sizeof(zc);