]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
tcp-zerocopy: Update returned getsockopt() optlen.
authorArjun Roy <arjunroy@google.com>
Tue, 25 Feb 2020 20:38:54 +0000 (12:38 -0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 27 Feb 2020 04:24:22 +0000 (20:24 -0800)
TCP receive zerocopy currently does not update the returned optlen for
getsockopt() if the user passed in a larger than expected value.
Thus, userspace cannot properly determine if all the fields are set in
the passed-in struct. This patch sets the optlen for this case before
returning, in keeping with the expected operation of getsockopt().

Fixes: c8856c051454 ("tcp-zerocopy: Return inq along with tcp receive zerocopy.")
Signed-off-by: Arjun Roy <arjunroy@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/tcp.c

index 1b685485a5b5236213fbf6906342406e0911f58f..48aa457a95161979c561a5aebcc924d827002c85 100644 (file)
@@ -3669,8 +3669,11 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
                        return -EFAULT;
                if (len < offsetofend(struct tcp_zerocopy_receive, length))
                        return -EINVAL;
-               if (len > sizeof(zc))
+               if (len > sizeof(zc)) {
                        len = sizeof(zc);
+                       if (put_user(len, optlen))
+                               return -EFAULT;
+               }
                if (copy_from_user(&zc, optval, len))
                        return -EFAULT;
                lock_sock(sk);