netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 net-next] tcp-zerocopy: Update returned getsockopt() optlen.
@ 2020-02-25 20:38 Arjun Roy
  2020-02-27  4:24 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Arjun Roy @ 2020-02-25 20:38 UTC (permalink / raw)
  To: davem, netdev; +Cc: arjunroy, soheil, edumazet, willemb

From: Arjun Roy <arjunroy@google.com>

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>

---
 net/ipv4/tcp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 600deb39f17de..9644047262ece 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -4124,8 +4124,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);
-- 
2.25.0.265.gbab2e86ba0-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 net-next] tcp-zerocopy: Update returned getsockopt() optlen.
  2020-02-25 20:38 [PATCH v2 net-next] tcp-zerocopy: Update returned getsockopt() optlen Arjun Roy
@ 2020-02-27  4:24 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-02-27  4:24 UTC (permalink / raw)
  To: arjunroy.kdev; +Cc: netdev, arjunroy, soheil, edumazet, willemb

From: Arjun Roy <arjunroy.kdev@gmail.com>
Date: Tue, 25 Feb 2020 12:38:54 -0800

> From: Arjun Roy <arjunroy@google.com>
> 
> 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>

Applied, thank you.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-27  4:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-25 20:38 [PATCH v2 net-next] tcp-zerocopy: Update returned getsockopt() optlen Arjun Roy
2020-02-27  4:24 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).