Skip to contentSkip to conversation

sock: ignore TIMESTAMP, RXQ_OVFL, WIFI_STATUS in sock_cmsg_send

PATCH In review Soheil Hassas Yeganeh 5 participants 7 messages May 13, 2016 – May 16, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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
index 08bf97e..1e0bcd0 100644
@@ -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
maintainer
#1 lore raw

From: 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, 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().

Quoted 3 lines

Ignore SO_WIFI_STATUS, SO_TIMESTAMP(NS), and SO_RXQ_OVFL when 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.

#2 lore raw
Quoted 18 lines · David Miller

From: 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, 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().

Quoted 5 lines
Quoted 3 lines

Ignore SO_WIFI_STATUS, SO_TIMESTAMP(NS), and SO_RXQ_OVFL when 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!

#3 lore raw
In reply to Soheil Hassas Yeganeh

Hello.

Quoted 10 lines · Soheil Hassas Yeganeh

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

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 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 +0 -0
index 08bf97e..1e0bcd0 100644

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

#4 lore raw

PATCH 1/1 sock: propagate __sock_cmsg_send() error

In reply to Soheil Hassas Yeganeh

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")
Cc Soheil Hassas Yeganeh <[email protected]>
---
 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
index 5805762d7fc79a702f1d67e802992b822f66f000..71a52f4d4cffba2db9353f43dc817689bf4fab10 100644
@@ -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
index 00d0c2903173a96571983216f2839a93059cad22..37874e2f30edf98f31e2a5097761143d507d5b95 100644
@@ -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;
 		}
 
Acked-by on v1 1/1
#5 lore raw

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")
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
index 5805762d7fc79a702f1d67e802992b822f66f000..71a52f4d4cffba2db9353f43dc817689bf4fab10 100644
@@ -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
index 00d0c2903173a96571983216f2839a93059cad22..37874e2f30edf98f31e2a5097761143d507d5b95 100644
@@ -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 -2
 
                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;
                }
 

Thanks Eric for the fixes.

maintainer Applied
#6 lore raw

Re: [PATCH net-next] sock: propagate __sock_cmsg_send() error

In reply to Eric Dumazet

From: 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")
Cc Soheil Hassas Yeganeh <[email protected]>

Applied.