Skip to contentSkip to conversation

tcp-zerocopy: Update returned getsockopt() optlen.

PATCH Applied Arjun Roy 2 participants 2 messages Feb 25, 2020 – Feb 27, 2020

Subsystems (3)
lore
Share & tools
lore

Arjun Roy

author
#0 lore raw

PATCH v2 1/1 tcp-zerocopy: Update returned getsockopt() optlen.

From: Arjun Roy <[email protected]>

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.")
---
 net/ipv4/tcp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp.c +4 -1
index 600deb39f17de..9644047262ece 100644
@@ -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);
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
maintainer Applied
#1 lore raw

From: Arjun Roy <[email protected]>
Date: Tue, 25 Feb 2020 12:38:54 -0800

Quoted 8 lines

From: Arjun Roy <[email protected]>

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().

Quoted 5 lines
Fixes c8856c051454 ("tcp-zerocopy: Return inq along with tcp receive zerocopy.")

Applied, thank you.