sock: ignore TIMESTAMP, RXQ_OVFL, WIFI_STATUS in sock_cmsg_send
Subsystems (4)
PATCH 1/1 sock: ignore TIMESTAMP, RXQ_OVFL, WIFI_STATUS in sock_cmsg_send
From: Soheil Hassas Yeganeh <[email protected]>
SO_TIMESTAMP(NS), RXQ_OVFL, and WIFI_STATUS can be returned as receive-side control messages from recvmsg(). Although invalid, some applications may reflect those receive-side control messages back to sendmsg(). Since socket-level control messages were being ignored in ipv4 and ipv6, such applications would not get an error.
24025c4 (ipv4: process socket-level control messages in IPv4) and ad1e46 (ipv6: process socket-level control messages in IPv6) add support for socket-level control messages in ipv4 and ipv6 on sendmsg(). This results in getting -EINVAL, if the application passes in a message with SO_WIFI_STATUS, SO_RXQ_OVFL, SO_TIMESTAMP and/or SO_TIMESTAMPNS that might have been received in recvmsg().
Ignore SO_WIFI_STATUS, SO_TIMESTAMP(NS), and SO_RXQ_OVFL when processing socket-level control messages in send-side to remain backward compatible.
--- net/core/sock.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/core/sock.c +6 -0
@@ -1938,6 +1938,12 @@ int __sock_cmsg_send(struct sock *sk, struct msghdr *msg, struct cmsghdr *cmsg, sockc->tsflags &= ~SOF_TIMESTAMPING_TX_RECORD_MASK ; sockc->tsflags |= tsflags;break ; +/* Ignore the following types on send to remain backward compatible. */ +case SO_RXQ_OVFL :/* Fall through */ +case SO_TIMESTAMP :/* Fall through */ +case SO_TIMESTAMPNS :/* Fall through */ +case SO_WIFI_STATUS : +break ;default :return -EINVAL ; }
Signature · 1 line
2.8.0.rc3.226.g39d4020
David Miller
maintainerFrom: Soheil Hassas Yeganeh <[email protected]>
Date: Fri, 13 May 2016 00:47:10 -0400
Quoted 15 lines
From: Soheil Hassas Yeganeh <[email protected]>
SO_TIMESTAMP(NS),RXQ_OVFL, andWIFI_STATUScan be returned as receive-side control messages fromrecvmsg(). Although invalid, some applications may reflect those receive-side control messages back tosendmsg(). Since socket-level control messages were being ignored in ipv4 and ipv6, such applications would not get an error.24025c4 (ipv4: process socket-level control messages in IPv4) and ad1e46 (ipv6: process socket-level control messages in IPv6) add support for socket-level control messages in ipv4 and ipv6 on
sendmsg(). This results in getting-EINVAL, if the application passes in a message withSO_WIFI_STATUS,SO_RXQ_OVFL,SO_TIMESTAMPand/orSO_TIMESTAMPNSthat might have been received inrecvmsg().
Quoted 3 lines
Ignore
SO_WIFI_STATUS,SO_TIMESTAMP(NS), andSO_RXQ_OVFLwhen processing socket-level control messages in send-side to remain backward compatible.
This patch is missing a proper Signed-Off-By: tag.
But I think this change is wrong. Just because we silently accepted garbage in the past doesn't mean more strict checking is invalid.
Applications blindly echoing control messages from recvmsg to sendmsg must be fixed.
Quoted 18 lines · David Miller
From: Soheil Hassas Yeganeh <[email protected]>
Date: Fri, 13 May 2016 00:47:10 -0400Quoted 15 lines
From: Soheil Hassas Yeganeh <[email protected]>
SO_TIMESTAMP(NS),RXQ_OVFL, andWIFI_STATUScan be returned as receive-side control messages fromrecvmsg(). Although invalid, some applications may reflect those receive-side control messages back tosendmsg(). Since socket-level control messages were being ignored in ipv4 and ipv6, such applications would not get an error.24025c4 (ipv4: process socket-level control messages in IPv4) and ad1e46 (ipv6: process socket-level control messages in IPv6) add support for socket-level control messages in ipv4 and ipv6 on
sendmsg(). This results in getting-EINVAL, if the application passes in a message withSO_WIFI_STATUS,SO_RXQ_OVFL,SO_TIMESTAMPand/orSO_TIMESTAMPNSthat might have been received inrecvmsg().
Quoted 5 lines
Quoted 3 lines
Ignore
SO_WIFI_STATUS,SO_TIMESTAMP(NS), andSO_RXQ_OVFLwhen processing socket-level control messages in send-side to remain backward compatible.This patch is missing a proper Signed-Off-By: tag.
Oops, sorry. :(
Quoted 5 lines
But I think this change is wrong. Just because we silently accepted garbage in the past doesn't mean more strict checking is invalid.
Applications blindly echoing control messages from recvmsg to sendmsg must be fixed.
Agreed, by this patch, I just wanted to note such potential issues and make sure I haven't broken any user-space application. Thanks David!
Hello.
Quoted 10 lines · Soheil Hassas Yeganeh
From: Soheil Hassas Yeganeh <[email protected]>
SO_TIMESTAMP(NS),RXQ_OVFL, andWIFI_STATUScan be returned as receive-side control messages fromrecvmsg(). Although invalid, some applications may reflect those receive-side control messages back tosendmsg(). Since socket-level control messages were being ignored in ipv4 and ipv6, such applications would not get an error.24025c4 (ipv4: process socket-level control messages in IPv4) and ad1e46 (ipv6: process socket-level control messages in IPv6) add
scripts/checkpatch.pl now enforces certain commit citing style, yours
doesn't quite match -- SHA1 should be at least 12 digits and the summary enclosed in ("").
Quoted 17 lines
support for socket-level control messages in ipv4 and ipv6 on
sendmsg(). This results in getting-EINVAL, if the application passes in a message withSO_WIFI_STATUS,SO_RXQ_OVFL,SO_TIMESTAMPand/orSO_TIMESTAMPNSthat might have been received inrecvmsg().Ignore
SO_WIFI_STATUS,SO_TIMESTAMP(NS), andSO_RXQ_OVFLwhen processing socket-level control messages in send-side to remain backward compatible.--- net/core/sock.c | 6 ++++++ 1 file changed, 6 insertions(+)net/core/sock.c +0
-0
net/core/sock.c int __sock_cmsg_send(struct sock *sk, struct msghdr *msg, struct cmsghdr *cmsg, · line 1944
Quoted 7 lines
net/core/sock.c +4
-0@@ -1938,6 +1938,12 @@ int __sock_cmsg_send(struct sock *sk, struct msghdr *msg, struct cmsghdr *cmsg, sockc->tsflags &= ~SOF_TIMESTAMPING_TX_RECORD_MASK ; sockc->tsflags |= tsflags;break ; +/* Ignore the following types on send to remain backward compatible. */ +case SO_RXQ_OVFL :/* Fall through */ +case SO_TIMESTAMP :/* Fall through */ +case SO_TIMESTAMPNS :/* Fall through */
^^^^^^^^^^^^^^^^^^
There's no need for such comments here.
net/core/sock.c int __sock_cmsg_send(struct sock *sk, struct msghdr *msg, struct cmsghdr *cmsg, · line 1949
Quoted 5 lines
net/core/sock.c +2
-0+case SO_WIFI_STATUS : +break ;default :return -EINVAL ; }
MBR, Sergei
PATCH 1/1 sock: propagate __sock_cmsg_send() error
In reply to Soheil Hassas YeganehFrom: Eric Dumazet <[email protected]>
__sock_cmsg_send() might return different error codes, not only -EINVAL.
--- net/ipv4/ip_sockglue.c | 5 +++-- net/ipv6/datagram.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
net/ipv4/ip_sockglue.c +3 -2
@@ -247,8 +247,9 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc, }#endif if (cmsg->cmsg_level ==SOL_SOCKET ) { -if (__sock_cmsg_send (sk, msg, cmsg, &ipc->sockc)) -return -EINVAL ; + err =__sock_cmsg_send (sk, msg, cmsg, &ipc->sockc); +if (err) +return err;continue ; }
net/ipv6/datagram.c +3 -2
@@ -746,8 +746,9 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk, }if (cmsg->cmsg_level ==SOL_SOCKET ) { -if (__sock_cmsg_send (sk, msg, cmsg, sockc)) -return -EINVAL ; + err =__sock_cmsg_send (sk, msg, cmsg, sockc); +if (err) +return err;continue ; }
Re: [PATCH net-next] sock: propagate __sock_cmsg_send() error
Quoted 8 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
__sock_cmsg_send()might return different error codes, not only-EINVAL.Fixes 24025c465f77 ("ipv4: process socket-level control messages in IPv4")Fixes ad1e46a83716 ("ipv6: process socket-level control messages in IPv6")Signed-off-by Eric Dumazet <[email protected]>Cc Soheil Hassas Yeganeh <[email protected]>
Quoted 29 lines
--- net/ipv4/ip_sockglue.c | 5 +++-- net/ipv6/datagram.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)net/ipv4/ip_sockglue.c +3
-2@@ -247,8 +247,9 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc, }#endif if (cmsg->cmsg_level ==SOL_SOCKET ) { -if (__sock_cmsg_send (sk, msg, cmsg, &ipc->sockc)) -return -EINVAL ; + err =__sock_cmsg_send (sk, msg, cmsg, &ipc->sockc); +if (err) +return err;continue ; }net/ipv6/datagram.c +0
-0@@ -746,8 +746,9 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk, }
net/ipv6/datagram.c int ip6_datagram_send_ctl(struct net *net, struct sock *sk, · line 754
Quoted 10 lines
net/ipv6/datagram.c +3
-2if (cmsg->cmsg_level ==SOL_SOCKET ) { -if (__sock_cmsg_send (sk, msg, cmsg, sockc)) -return -EINVAL ; + err =__sock_cmsg_send (sk, msg, cmsg, sockc); +if (err) +return err;continue ; }
Thanks Eric for the fixes.
Re: [PATCH net-next] sock: propagate __sock_cmsg_send() error
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
Date: Fri, 13 May 2016 06:14:37 -0700
Quoted 8 lines
From: Eric Dumazet <[email protected]>
__sock_cmsg_send()might return different error codes, not only-EINVAL.Fixes 24025c465f77 ("ipv4: process socket-level control messages in IPv4")Fixes ad1e46a83716 ("ipv6: process socket-level control messages in IPv6")Signed-off-by Eric Dumazet <[email protected]>Cc Soheil Hassas Yeganeh <[email protected]>
Applied.