tcp-zerocopy: Update returned getsockopt() optlen.
Subsystems (3)
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().
Signed-off-by Arjun Roy <[email protected]>
Signed-off-by Eric Dumazet <[email protected]>
Signed-off-by Soheil Hassas Yeganeh <[email protected]>
Signed-off-by Willem de Bruijn <[email protected]>
--- net/ipv4/tcp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +6 -2
@@ -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 &©_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
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 ofgetsockopt().
Quoted 4 lines
Signed-off-by Arjun Roy <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Signed-off-by Soheil Hassas Yeganeh <[email protected]>Signed-off-by Willem de Bruijn <[email protected]>
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@@ -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 &©_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