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().
zerocopy.")
--- 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 6 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]>Fixes c8856c051454 ("tcp-zerocopy: Return inq along with tcp receivezerocopy")
OK, please note for next time :
Fixes: tag should not wrap : It should be a single line. Preferably it should be the first tag (before your Sob)
Add v2 as in [PATCH v2 net-next] : so that reviewers can easily see which version is the more recent one.
net/ipv4/tcp.c static int do_tcp_getsockopt(struct sock *sk, int level, · line 4153
Quoted 4 lines
net/ipv4/tcp.c +3
-0+if (!err) { +if (put_user (len, optlen)) +return -EFAULT ;
Sorry for not asking this before during our internal review :
Is the cost of the extra STAC / CLAC (on x86) being high enough that it is worth trying to call put_user() only if user provided a different length ?
Quoted 28 lines · Eric Dumazet
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 6 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]>Fixes c8856c051454 ("tcp-zerocopy: Return inq along with tcp receivezerocopy")
OK, please note for next time :
Fixes: tag should not wrap : It should be a single line. Preferably it should be the first tag (before your Sob)
Add v2 as in [PATCH v2 net-next] : so that reviewers can easily see which version is the more recent one.
Quoted 1 line
Quoted 8 lines
net/ipv4/tcp.c static int do_tcp_getsockopt(struct sock *sk, int level, · line 4153
Quoted 3 lines
net/ipv4/tcp.c +3
-0+if (!err) { +if (put_user (len, optlen)) +return -EFAULT ;Sorry for not asking this before during our internal review :
Is the cost of the extra STAC / CLAC (on x86) being high enough that it is worth trying to call
put_user()only if user provided a different length ?
I'll have to defer to someone with more understanding of the overheads involved in this case.
-Arjun
Quoted 34 lines · Arjun Roy
Quoted 32 lines · Eric Dumazet
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 6 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]>Fixes c8856c051454 ("tcp-zerocopy: Return inq along with tcp receivezerocopy")
OK, please note for next time :
Fixes: tag should not wrap : It should be a single line. Preferably it should be the first tag (before your Sob)
Add v2 as in [PATCH v2 net-next] : so that reviewers can easily see which version is the more recent one.
Quoted 4 lines
net/ipv4/tcp.c +3
-0+if (!err) { +if (put_user (len, optlen)) +return -EFAULT ;
Quoted 8 lines
Quoted 4 lines
Sorry for not asking this before during our internal review :
Is the cost of the extra STAC / CLAC (on x86) being high enough that it is worth trying to call
put_user()only if user provided a different length ?I'll have to defer to someone with more understanding of the overheads involved in this case.
Actually, now that I think about it, the (hopefully) common case is indeed that the kernel and userspace agree on the size of the struct, so I think just having just that one extra branch to check before issuing a put_user() would be well worth it compared to all the instructions in put_user(). I'll send a v2 patch with the change.
Thanks,
-Arjun
Quoted 1 line
-Arjun
Quoted 45 lines · Arjun Roy
Quoted 34 lines · Arjun Roy
Quoted 32 lines · Eric Dumazet
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 6 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]>Fixes c8856c051454 ("tcp-zerocopy: Return inq along with tcp receivezerocopy")
OK, please note for next time :
Fixes: tag should not wrap : It should be a single line. Preferably it should be the first tag (before your Sob)
Add v2 as in [PATCH v2 net-next] : so that reviewers can easily see which version is the more recent one.
Quoted 4 lines
net/ipv4/tcp.c +3
-0+if (!err) { +if (put_user (len, optlen)) +return -EFAULT ;Quoted 8 lines
Quoted 4 lines
Sorry for not asking this before during our internal review :
Is the cost of the extra STAC / CLAC (on x86) being high enough that it is worth trying to call
put_user()only if user provided a different length ?I'll have to defer to someone with more understanding of the overheads involved in this case.
Quoted 5 lines
Actually, now that I think about it, the (hopefully) common case is indeed that the kernel and userspace agree on the size of the struct, so I think just having just that one extra branch to check before issuing a
put_user()would be well worth it compared to all the instructions input_user(). I'll send a v2 patch with the change.
Thank you, Arjun. Given that most TCP socket options overwrite the optlen even when returning error, I think we can avoid having the extra branch by simply moving put_user right after the check for "len == sizeof(zc)" and before "switch(len)".
Thanks,
Soheil
Quoted 4 lines
Thanks,
-ArjunQuoted 1 line
-Arjun
Quoted 53 lines · Soheil Hassas Yeganeh
Quoted 45 lines · Arjun Roy
Quoted 34 lines · Arjun Roy
Quoted 32 lines · Eric Dumazet
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 6 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]>Fixes c8856c051454 ("tcp-zerocopy: Return inq along with tcp receivezerocopy")
OK, please note for next time :
Fixes: tag should not wrap : It should be a single line. Preferably it should be the first tag (before your Sob)
Add v2 as in [PATCH v2 net-next] : so that reviewers can easily see which version is the more recent one.
Quoted 4 lines
net/ipv4/tcp.c +3
-0+if (!err) { +if (put_user (len, optlen)) +return -EFAULT ;Quoted 8 lines
Quoted 4 lines
Sorry for not asking this before during our internal review :
Is the cost of the extra STAC / CLAC (on x86) being high enough that it is worth trying to call
put_user()only if user provided a different length ?I'll have to defer to someone with more understanding of the overheads involved in this case.
Quoted 5 lines
Actually, now that I think about it, the (hopefully) common case is indeed that the kernel and userspace agree on the size of the struct, so I think just having just that one extra branch to check before issuing a
put_user()would be well worth it compared to all the instructions input_user(). I'll send a v2 patch with the change.
Quoted 8 lines
Thank you, Arjun. Given that most TCP socket options overwrite the optlen even when returning error, I think we can avoid having the extra branch by simply moving
put_userright after the check for "len == sizeof(zc)" and before "switch(len)".Thanks,
Soheil
Unfortunately I don't that works in this case - there's a point before then that could set len to sizeof(zc) (if len was > sizeof(zc) to begin with) which would disrupt what we want.
Accounting for that would probably add more complication and still require a branch, so I'm going with the simpler move in this case. Will send a v2 patch out momentarily.
Thanks,
-Arjun
Quoted 4 lines
Quoted 4 lines
Thanks,
-ArjunQuoted 1 line
-Arjun