Skip to contentSkip to conversation

tcp-zerocopy: Update returned getsockopt() optlen.

PATCH In review Arjun Roy 2 participants 2 messages Feb 25, 2020

Subsystems (3)
lore
Share & tools
lore

Arjun Roy

author
#0 lore raw

PATCH 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(). Thus, userspace cannot properly determine if all the fields are set in the passed-in struct. This patch sets the optlen before return, in keeping with the expected operation of getsockopt().

---
 net/ipv4/tcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +6 -2
index 600deb39f17de..fb9894d3d30e9 100644
@@ -4148,8 +4148,12 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
 zerocopy_rcv_inq:
 		zc.inq = tcp_inq_hint(sk);
 zerocopy_rcv_out:
-		if (!err && copy_to_user(optval, &zc, len))
-			err = -EFAULT;
+		if (!err) {
+			if (put_user(len, optlen))
+				return -EFAULT;
+			if (copy_to_user(optval, &zc, len))
+				return -EFAULT;
+		}
 		return err;
 	}
 #endif
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
#1 lore raw
Quoted 8 lines · Arjun Roy

From: Arjun Roy <[email protected]>

TCP receive zerocopy currently does not update the returned optlen for getsockopt(). Thus, userspace cannot properly determine if all the fields are set in the passed-in struct. This patch sets the optlen before return, in keeping with the expected operation of getsockopt().

Quoted 4 lines

Please add a proper Fixes: tag :)

Thanks.

Quoted 27 lines
---
 net/ipv4/tcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +6 -3
index 600deb39f17de..fb9894d3d30e9 100644
@@ -4148,8 +4148,12 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
 zerocopy_rcv_inq:
                zc.inq = tcp_inq_hint(sk);
 zerocopy_rcv_out:
-               if (!err && copy_to_user(optval, &zc, len))
-                       err = -EFAULT;
+               if (!err) {
+                       if (put_user(len, optlen))
+                               return -EFAULT;
+                       if (copy_to_user(optval, &zc, len))
+                               return -EFAULT;
+               }
                return err;
        }
 #endif
--

2.25.0.265.gbab2e86ba0-goog