net-timestamp: address blinding and batching
Subsystems (7)
Willem de Bruijn
maintainercover net-timestamp: address blinding and batching
From: Willem de Bruijn <[email protected]>
Two issues were raised during recent timestamping discussions:
1. looping full packets on the error queue exposes packet headers
2. TCP timestamping with retransmissions generates many timestamps
This RFC patchset is an attempt at addressing both without breaking legacy behavior.
Patch 1 reintroduces the "no payload" timestamp option, which loops timestamps onto an empty skb. Patch 2 then gives administrators the power to block all timestamp requests by unprivileged users that contain data. I proposed this earlier as a backward compatible workaround in the discussion of
net-timestamp: pull headers for SOCK_STREAM
http://patchwork.ozlabs.org/patch/414810/
Patch 3 only updates the txtimestamp example to test this option.
When looping timestamps without data, there is no need to associate a timestamp with a specific packet. Patch 4 loops multiple timestamps onto a single outstanding packet if this has no payload. It is a variant of the cookies approach that David proposed in
net-timestamp: TCP timestamping
http://patchwork.ozlabs.org/patch/376513/
That patch turns out to introduce a quite a bit of code to save relatively few bytes because
1. no-payload already limits the per-skb size that is queued and
2. batching is limited by send() failing as soon as there is an outstanding packet on the error queue. Therefore, I'm fine
with dropping this. By now, it is at least recorded in patchwork.
Patch 5, finally, creates a new short SO_TIMESTAMPING option, SOF_TIMESTAMPING_TX, that combines all recent options, as a push to get future applications to use the new ID and no-payload based API by default.
Willem de Bruijn (5):
net-timestamp: no-payload option
net-timestamp: no-payload only sysctl
net-timestamp: no-payload option in txtimestamp test
net-timestamp: tx timestamp cookies
net-timestamp: tx timestamping default mode flag
.../networking/timestamping/txtimestamp.c | 28 ++++- include/linux/skbuff.h | 12 ++ include/net/sock.h | 4 +- include/uapi/linux/errqueue.h | 1 + include/uapi/linux/net_tstamp.h | 11 +- net/core/skbuff.c | 134 ++++++++++++++++++--- net/core/sock.c | 3 + net/core/sysctl_net_core.c | 9 ++ net/ipv4/ip_sockglue.c | 9 +- net/ipv6/datagram.c | 4 +- net/rxrpc/ar-error.c | 5 + net/socket.c | 64 +++++++++- 12 files changed, 250 insertions(+), 34 deletions(-)
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Willem de Bruijn
maintainerRFC PATCH 1/5 net-timestamp: no-payload option
From: Willem de Bruijn <[email protected]>
Add timestamping option SOF_TIMESTAMPING_OPT_TSONLY. For transmit timestamps, this loops timestamps on top of empty packets.
Doing so reduces the pressure on SO_RCVBUF. Payload inspection and cmsg reception (aside from timestamps) are no longer possible. This works together with a follow on patch that allows administrators to only allow tx timestamping if it does not loop payload or metadata.
--- include/uapi/linux/net_tstamp.h | 3 ++- net/core/skbuff.c | 19 ++++++++++++++----- net/ipv4/ip_sockglue.c | 9 +++++---- net/ipv6/datagram.c | 4 ++-- net/rxrpc/ar-error.c | 5 +++++ 5 files changed, 28 insertions(+), 12 deletions(-)
include/uapi/linux/net_tstamp.h +2 -1
@@ -24,8 +24,9 @@ enum {SOF_TIMESTAMPING_TX_SCHED = (1 <<8 ),SOF_TIMESTAMPING_TX_ACK = (1 <<9 ),SOF_TIMESTAMPING_OPT_CMSG = (1 <<10 ), +SOF_TIMESTAMPING_OPT_TSONLY = (1 <<11 ), -SOF_TIMESTAMPING_LAST =SOF_TIMESTAMPING_OPT_CMSG , +SOF_TIMESTAMPING_LAST =SOF_TIMESTAMPING_OPT_TSONLY ,SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST -1 ) | SOF_TIMESTAMPING_LAST };
net/core/skbuff.c +14 -5
@@ -3710,19 +3710,28 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, struct sock *sk, int tstype) {struct sk_buff *skb; +bool tsonly = sk->sk_tsflags &SOF_TIMESTAMPING_OPT_TSONLY ;if (!sk)return ; -if (hwtstamps) - *skb_hwtstamps (orig_skb) = *hwtstamps; +if (tsonly) + skb =alloc_skb (0 ,GFP_ATOMIC );else - orig_skb->tstamp =ktime_get_real (); - - skb =skb_clone (orig_skb,GFP_ATOMIC ); + skb =skb_clone (orig_skb,GFP_ATOMIC );if (!skb)return ; +if (tsonly) { +skb_shinfo (skb)->tx_flags =skb_shinfo (orig_skb)->tx_flags; +skb_shinfo (skb)->tskey =skb_shinfo (orig_skb)->tskey; + } + +if (hwtstamps) + *skb_hwtstamps (skb) = *hwtstamps; +else + skb->tstamp =ktime_get_real (); +__skb_complete_tx_timestamp (skb, sk, tstype); }EXPORT_SYMBOL_GPL (__skb_tstamp_tx);
net/ipv4/ip_sockglue.c +5 -4
@@ -440,7 +440,7 @@ static bool ipv4_pktinfo_prepare_errqueue(const struct sock *sk,if ((ee_origin !=SO_EE_ORIGIN_TIMESTAMPING ) || (!(sk->sk_tsflags &SOF_TIMESTAMPING_OPT_CMSG )) || - (!skb->dev)) + (!skb->dev) || (!skb->len))return false; info->ipi_spec_dst.s_addr =ip_hdr (skb)->saddr;
@@ -483,7 +483,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) serr =SKB_EXT_ERR (skb); -if (sin) { +if (sin && skb->len) { sin->sin_family =AF_INET ; sin->sin_addr.s_addr = *(__be32 *)(skb_network_header (skb) + serr->addr_offset);
@@ -496,8 +496,9 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) sin = &errhdr.offender; sin->sin_family =AF_UNSPEC ; -if (serr->ee.ee_origin ==SO_EE_ORIGIN_ICMP || -ipv4_pktinfo_prepare_errqueue (sk, skb, serr->ee.ee_origin)) { +if (skb->len && + (serr->ee.ee_origin ==SO_EE_ORIGIN_ICMP || +ipv4_pktinfo_prepare_errqueue (sk, skb, serr->ee.ee_origin))) {struct inet_sock *inet =inet_sk (sk); sin->sin_family =AF_INET ;
net/ipv6/datagram.c +2 -2
@@ -369,7 +369,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) serr =SKB_EXT_ERR (skb); -if (sin) { +if (sin && skb->len) {const unsigned char *nh =skb_network_header (skb); sin->sin6_family =AF_INET6 ; sin->sin6_flowinfo =0 ;
@@ -394,7 +394,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)memcpy (&errhdr.ee, &serr->ee,sizeof (struct sock_extended_err )); sin = &errhdr.offender; sin->sin6_family =AF_UNSPEC ; -if (serr->ee.ee_origin !=SO_EE_ORIGIN_LOCAL ) { +if (serr->ee.ee_origin !=SO_EE_ORIGIN_LOCAL && skb->len) { sin->sin6_family =AF_INET6 ; sin->sin6_flowinfo =0 ; sin->sin6_port =0 ;
net/rxrpc/ar-error.c +5 -0
@@ -42,6 +42,11 @@ void rxrpc_UDP_error_report(struct sock *sk)_leave ("UDP socket errqueue empty" );return ; } +if (!skb->len) { +_leave ("UDP empty message" ); +kfree_skb (skb); +return ; + }rxrpc_new_skb (skb);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Re: [PATCH net-next RFC 1/5] net-timestamp: no-payload option
Quoted 9 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Add timestamping option
SOF_TIMESTAMPING_OPT_TSONLY. For transmit timestamps, this loops timestamps on top of empty packets.Doing so reduces the pressure on
SO_RCVBUF. Payload inspection and cmsg reception (aside from timestamps) are no longer possible. This works together with a follow on patch that allows administrators to only allow tx timestamping if it does not loop payload or metadata.
If this loses IP_PKTINFO, that will be a bit unfortunate.
--Andy
Quoted 138 lines
Signed-off-by Willem de Bruijn <[email protected]>--- include/uapi/linux/net_tstamp.h | 3 ++- net/core/skbuff.c | 19 ++++++++++++++----- net/ipv4/ip_sockglue.c | 9 +++++---- net/ipv6/datagram.c | 4 ++-- net/rxrpc/ar-error.c | 5 +++++ 5 files changed, 28 insertions(+), 12 deletions(-)include/uapi/linux/net_tstamp.h +2
-1@@ -24,8 +24,9 @@ enum {SOF_TIMESTAMPING_TX_SCHED = (1 <<8 ),SOF_TIMESTAMPING_TX_ACK = (1 <<9 ),SOF_TIMESTAMPING_OPT_CMSG = (1 <<10 ), +SOF_TIMESTAMPING_OPT_TSONLY = (1 <<11 ), -SOF_TIMESTAMPING_LAST =SOF_TIMESTAMPING_OPT_CMSG , +SOF_TIMESTAMPING_LAST =SOF_TIMESTAMPING_OPT_TSONLY ,SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST -1 ) | SOF_TIMESTAMPING_LAST };net/core/skbuff.c +14
-5@@ -3710,19 +3710,28 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, struct sock *sk, int tstype) {struct sk_buff *skb; +bool tsonly = sk->sk_tsflags &SOF_TIMESTAMPING_OPT_TSONLY ;if (!sk)return ; -if (hwtstamps) - *skb_hwtstamps (orig_skb) = *hwtstamps; +if (tsonly) + skb =alloc_skb (0 ,GFP_ATOMIC );else - orig_skb->tstamp =ktime_get_real (); - - skb =skb_clone (orig_skb,GFP_ATOMIC ); + skb =skb_clone (orig_skb,GFP_ATOMIC );if (!skb)return ; +if (tsonly) { +skb_shinfo (skb)->tx_flags =skb_shinfo (orig_skb)->tx_flags; +skb_shinfo (skb)->tskey =skb_shinfo (orig_skb)->tskey; + } + +if (hwtstamps) + *skb_hwtstamps (skb) = *hwtstamps; +else + skb->tstamp =ktime_get_real (); +__skb_complete_tx_timestamp (skb, sk, tstype); }EXPORT_SYMBOL_GPL (__skb_tstamp_tx);net/ipv4/ip_sockglue.c +5
-4@@ -440,7 +440,7 @@ static bool ipv4_pktinfo_prepare_errqueue(const struct sock *sk,if ((ee_origin !=SO_EE_ORIGIN_TIMESTAMPING ) || (!(sk->sk_tsflags &SOF_TIMESTAMPING_OPT_CMSG )) || - (!skb->dev)) + (!skb->dev) || (!skb->len))return false; info->ipi_spec_dst.s_addr =ip_hdr (skb)->saddr;@@ -483,7 +483,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) serr =SKB_EXT_ERR (skb); -if (sin) { +if (sin && skb->len) { sin->sin_family =AF_INET ; sin->sin_addr.s_addr = *(__be32 *)(skb_network_header (skb) + serr->addr_offset);@@ -496,8 +496,9 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) sin = &errhdr.offender; sin->sin_family =AF_UNSPEC ; -if (serr->ee.ee_origin ==SO_EE_ORIGIN_ICMP || -ipv4_pktinfo_prepare_errqueue (sk, skb, serr->ee.ee_origin)) { +if (skb->len && + (serr->ee.ee_origin ==SO_EE_ORIGIN_ICMP || +ipv4_pktinfo_prepare_errqueue (sk, skb, serr->ee.ee_origin))) {struct inet_sock *inet =inet_sk (sk); sin->sin_family =AF_INET ;net/ipv6/datagram.c +2
-2@@ -369,7 +369,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) serr =SKB_EXT_ERR (skb); -if (sin) { +if (sin && skb->len) {const unsigned char *nh =skb_network_header (skb); sin->sin6_family =AF_INET6 ; sin->sin6_flowinfo =0 ;@@ -394,7 +394,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)memcpy (&errhdr.ee, &serr->ee,sizeof (struct sock_extended_err )); sin = &errhdr.offender; sin->sin6_family =AF_UNSPEC ; -if (serr->ee.ee_origin !=SO_EE_ORIGIN_LOCAL ) { +if (serr->ee.ee_origin !=SO_EE_ORIGIN_LOCAL && skb->len) { sin->sin6_family =AF_INET6 ; sin->sin6_flowinfo =0 ; sin->sin6_port =0 ;net/rxrpc/ar-error.c +5
-1@@ -42,6 +42,11 @@ void rxrpc_UDP_error_report(struct sock *sk)_leave ("UDP socket errqueue empty" );return ; } +if (!skb->len) { +_leave ("UDP empty message" ); +kfree_skb (skb); +return ; + }rxrpc_new_skb (skb); --2.2.0.rc0.207.ga3a616c
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Willem de Bruijn
maintainerRe: [PATCH net-next RFC 1/5] net-timestamp: no-payload option
Quoted 6 lines · Andy Lutomirski
Quoted 5 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Add timestamping option
SOF_TIMESTAMPING_OPT_TSONLY. For transmit timestamps, this loops timestamps on top of empty packets.
Quoted 7 lines
Quoted 4 lines
Doing so reduces the pressure on
SO_RCVBUF. Payload inspection and cmsg reception (aside from timestamps) are no longer possible. This works together with a follow on patch that allows administrators to only allow tx timestamping if it does not loop payload or metadata.If this loses
IP_PKTINFO, that will be a bit unfortunate.
If it doesn't, then we might as well loop the entire payload. For applications that need pktinfo or other cmsg, do not select the option.
Re: [PATCH net-next RFC 1/5] net-timestamp: no-payload option
Quoted 12 lines · Willem de Bruijn
Quoted 11 lines · Andy Lutomirski
Quoted 9 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Add timestamping option
SOF_TIMESTAMPING_OPT_TSONLY. For transmit timestamps, this loops timestamps on top of empty packets.Doing so reduces the pressure on
SO_RCVBUF. Payload inspection and cmsg reception (aside from timestamps) are no longer possible. This works together with a follow on patch that allows administrators to only allow tx timestamping if it does not loop payload or metadata.
Quoted 5 lines
Quoted 2 lines
If this loses
IP_PKTINFO, that will be a bit unfortunate.If it doesn't, then we might as well loop the entire payload. For applications that need pktinfo or other cmsg, do not select the option.
Right, but it loses the ability to get the ifindex if the sysctl is set to the conservative option, which I don't think is desirable.
--Andy
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Willem de Bruijn
maintainerRe: [PATCH net-next RFC 1/5] net-timestamp: no-payload option
Quoted 13 lines · Andy Lutomirski
Quoted 12 lines · Willem de Bruijn
Quoted 11 lines · Andy Lutomirski
Quoted 9 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Add timestamping option
SOF_TIMESTAMPING_OPT_TSONLY. For transmit timestamps, this loops timestamps on top of empty packets.Doing so reduces the pressure on
SO_RCVBUF. Payload inspection and cmsg reception (aside from timestamps) are no longer possible. This works together with a follow on patch that allows administrators to only allow tx timestamping if it does not loop payload or metadata.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
If this loses
IP_PKTINFO, that will be a bit unfortunate.If it doesn't, then we might as well loop the entire payload. For applications that need pktinfo or other cmsg, do not select the option.
Right, but it loses the ability to get the ifindex if the sysctl is set to the conservative option, which I don't think is desirable.
Understood. I just find the alternative, where the no-data policy is weakened by exceptions, even less desirable. That makes it harder to explain what the sysctl/option do and what the security implications are.
Re: [PATCH net-next RFC 1/5] net-timestamp: no-payload option
Quoted 20 lines · Willem de Bruijn
Quoted 19 lines · Andy Lutomirski
Quoted 17 lines · Willem de Bruijn
Quoted 6 lines · Andy Lutomirski
Quoted 5 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Add timestamping option
SOF_TIMESTAMPING_OPT_TSONLY. For transmit timestamps, this loops timestamps on top of empty packets.Quoted 7 lines
Quoted 4 lines
Doing so reduces the pressure on
SO_RCVBUF. Payload inspection and cmsg reception (aside from timestamps) are no longer possible. This works together with a follow on patch that allows administrators to only allow tx timestamping if it does not loop payload or metadata.If this loses
IP_PKTINFO, that will be a bit unfortunate.If it doesn't, then we might as well loop the entire payload. For applications that need pktinfo or other cmsg, do not select the option.
Quoted 7 lines
Quoted 2 lines
Right, but it loses the ability to get the ifindex if the sysctl is set to the conservative option, which I don't think is desirable.
Understood. I just find the alternative, where the no-data policy is weakened by exceptions, even less desirable. That makes it harder to explain what the sysctl/option do and what the security implications are.
Agreed.
If there was no-payload but not no-cmsg, then it would be a nice middle ground, but I guess that's bad for some reason involving accounting?
--Andy
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Willem de Bruijn
maintainerRe: [PATCH net-next RFC 1/5] net-timestamp: no-payload option
Quoted 29 lines · Andy Lutomirski
Quoted 20 lines · Willem de Bruijn
Quoted 19 lines · Andy Lutomirski
Quoted 17 lines · Willem de Bruijn
Quoted 6 lines · Andy Lutomirski
Quoted 5 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Add timestamping option
SOF_TIMESTAMPING_OPT_TSONLY. For transmit timestamps, this loops timestamps on top of empty packets.Quoted 7 lines
Quoted 4 lines
Doing so reduces the pressure on
SO_RCVBUF. Payload inspection and cmsg reception (aside from timestamps) are no longer possible. This works together with a follow on patch that allows administrators to only allow tx timestamping if it does not loop payload or metadata.If this loses
IP_PKTINFO, that will be a bit unfortunate.If it doesn't, then we might as well loop the entire payload. For applications that need pktinfo or other cmsg, do not select the option.
Quoted 7 lines
Quoted 2 lines
Right, but it loses the ability to get the ifindex if the sysctl is set to the conservative option, which I don't think is desirable.
Understood. I just find the alternative, where the no-data policy is weakened by exceptions, even less desirable. That makes it harder to explain what the sysctl/option do and what the security implications are.
Quoted 5 lines
Agreed.
If there was no-payload but not no-cmsg, then it would be a nice middle ground, but I guess that's bad for some reason involving accounting?
Enabling all cmsg opens up quite a few holes, including the tos options that we previously discussed. Also, these are implemented by reading the relevant bits from the payload at recvmsg time, so at least we would have to queue the full payload (though not necessarily return it).
Quoted 5 lines
--Andy
--
Andy Lutomirski
AMA Capital Management, LLC
Re: [PATCH net-next RFC 1/5] net-timestamp: no-payload option
OK, makes sense.
Quoted 47 lines · Willem de Bruijn
Quoted 29 lines · Andy Lutomirski
Quoted 20 lines · Willem de Bruijn
Quoted 19 lines · Andy Lutomirski
Quoted 17 lines · Willem de Bruijn
Quoted 6 lines · Andy Lutomirski
Quoted 5 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Add timestamping option
SOF_TIMESTAMPING_OPT_TSONLY. For transmit timestamps, this loops timestamps on top of empty packets.Quoted 7 lines
Quoted 4 lines
Doing so reduces the pressure on
SO_RCVBUF. Payload inspection and cmsg reception (aside from timestamps) are no longer possible. This works together with a follow on patch that allows administrators to only allow tx timestamping if it does not loop payload or metadata.If this loses
IP_PKTINFO, that will be a bit unfortunate.If it doesn't, then we might as well loop the entire payload. For applications that need pktinfo or other cmsg, do not select the option.
Quoted 7 lines
Quoted 2 lines
Right, but it loses the ability to get the ifindex if the sysctl is set to the conservative option, which I don't think is desirable.
Understood. I just find the alternative, where the no-data policy is weakened by exceptions, even less desirable. That makes it harder to explain what the sysctl/option do and what the security implications are.
Quoted 5 lines
Agreed.
If there was no-payload but not no-cmsg, then it would be a nice middle ground, but I guess that's bad for some reason involving accounting?
Enabling all cmsg opens up quite a few holes, including the tos options that we previously discussed. Also, these are implemented by reading the relevant bits from the payload at recvmsg time, so at least we would have to queue the full payload (though not necessarily return it).
Quoted 5 lines
--Andy
--
Andy Lutomirski
AMA Capital Management, LLC
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH net-next RFC 1/5] net-timestamp: no-payload option
In reply to Willem de Bruijnnet/ipv4/ip_sockglue.c static bool ipv4_pktinfo_prepare_errqueue(const struct sock *sk, · line 444
Quoted 11 lines · Willem de Bruijn
net/ipv4/ip_sockglue.c +1
-1@@ -440,7 +440,7 @@ static bool ipv4_pktinfo_prepare_errqueue(const struct sock *sk,if ((ee_origin !=SO_EE_ORIGIN_TIMESTAMPING ) || (!(sk->sk_tsflags &SOF_TIMESTAMPING_OPT_CMSG )) || - (!skb->dev)) + (!skb->dev) || (!skb->len))return false;
Nit: You have already tested for the condition (!skb->len) ...
Quoted 12 lines
net/ipv4/ip_sockglue.c +1
-1info->ipi_spec_dst.s_addr =ip_hdr (skb)->saddr;@@ -483,7 +483,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) serr =SKB_EXT_ERR (skb); -if (sin) { +if (sin && skb->len) { sin->sin_family =AF_INET ; sin->sin_addr.s_addr = *(__be32 *)(skb_network_header (skb) + serr->addr_offset);
net/ipv4/ip_sockglue.c int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) · line 501
Quoted 8 lines
net/ipv4/ip_sockglue.c +3
-2@@ -496,8 +496,9 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) sin = &errhdr.offender; sin->sin_family =AF_UNSPEC ; -if (serr->ee.ee_origin ==SO_EE_ORIGIN_ICMP || -ipv4_pktinfo_prepare_errqueue (sk, skb, serr->ee.ee_origin)) { +if (skb->len && + (serr->ee.ee_origin ==SO_EE_ORIGIN_ICMP || +ipv4_pktinfo_prepare_errqueue (sk, skb, serr->ee.ee_origin))) {
... here.
net/ipv4/ip_sockglue.c int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) · line 504
Quoted 3 lines
net/ipv4/ip_sockglue.c +0
-0struct inet_sock *inet =inet_sk (sk); sin->sin_family =AF_INET ;
Thanks,
Richard
Willem de Bruijn
maintainerRe: [PATCH net-next RFC 1/5] net-timestamp: no-payload option
Quoted 7 lines · Richard Cochran
Quoted 6 lines · Willem de Bruijn
net/ipv4/ip_sockglue.c +0
-0@@ -440,7 +440,7 @@ static bool ipv4_pktinfo_prepare_errqueue(const struct sock *sk,
Quoted 7 lines
net/ipv4/ip_sockglue.c static bool ipv4_pktinfo_prepare_errqueue(const struct sock *sk, · line 444
Quoted 5 lines
net/ipv4/ip_sockglue.c +1
-1if ((ee_origin !=SO_EE_ORIGIN_TIMESTAMPING ) || (!(sk->sk_tsflags &SOF_TIMESTAMPING_OPT_CMSG )) || - (!skb->dev)) + (!skb->dev) || (!skb->len))return false;Nit: You have already tested for the condition (!skb->len) ...
Thanks! I'll fix that when I send v1.
I had planned to do that today, but will hold off a bit to avoid merge conflicts with a fix queued for net (http://patchwork.ozlabs.org/patch/429553/)
I will drop patches 4 and 5 when sending out v1, btw.
Quoted 30 lines
Quoted 13 lines
net/ipv4/ip_sockglue.c +1
-1info->ipi_spec_dst.s_addr =ip_hdr (skb)->saddr;@@ -483,7 +483,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) serr =SKB_EXT_ERR (skb); -if (sin) { +if (sin && skb->len) { sin->sin_family =AF_INET ; sin->sin_addr.s_addr = *(__be32 *)(skb_network_header (skb) + serr->addr_offset);net/ipv4/ip_sockglue.c int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) · line 501
Quoted 8 lines
net/ipv4/ip_sockglue.c +3
-2@@ -496,8 +496,9 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) sin = &errhdr.offender; sin->sin_family =AF_UNSPEC ; -if (serr->ee.ee_origin ==SO_EE_ORIGIN_ICMP || -ipv4_pktinfo_prepare_errqueue (sk, skb, serr->ee.ee_origin)) { +if (skb->len && + (serr->ee.ee_origin ==SO_EE_ORIGIN_ICMP || +ipv4_pktinfo_prepare_errqueue (sk, skb, serr->ee.ee_origin))) {... here.
net/ipv4/ip_sockglue.c int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) · line 504
Quoted 3 lines
net/ipv4/ip_sockglue.c +0
-0struct inet_sock *inet =inet_sk (sk); sin->sin_family =AF_INET ;Thanks,
Richard
Willem de Bruijn
maintainerRFC PATCH 2/5 net-timestamp: no-payload only sysctl
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
Tx timestamps are looped onto the error queue on top of an skb. This mechanism leaks packet headers to processes unless the no-payload options SOF_TIMESTAMPING_OPT_TSONLY is set.
Add a sysctl that optionally drops looped timestamps with data for unprivileged users.
The policy is checked when timestamps are generated in the stack. It is possible for timestamps with data to be reported after the sysctl is set, if these were queued internally earlier.
No vulnerability is immediately known that exploits knowledge gleaned from packet headers, but it may still be preferable to allow administrators to lock down this path at the cost of possible breakage of legacy applications.
--- include/net/sock.h | 1 + net/core/skbuff.c | 11 ++++++++++- net/core/sock.c | 3 +++ net/core/sysctl_net_core.c | 9 +++++++++ 4 files changed, 23 insertions(+), 1 deletion(-)
include/net/sock.h +1 -0
@@ -2262,6 +2262,7 @@ bool sk_net_capable(const struct sock *sk, int cap);extern __u32 sysctl_wmem_max;extern __u32 sysctl_rmem_max; +extern int sysctl_tstamp_allow_data;extern int sysctl_optmem_max;extern __u32 sysctl_wmem_default;
net/core/skbuff.c +10 -1
@@ -3690,11 +3690,20 @@ static void __skb_complete_tx_timestamp(struct sk_buff *skb,kfree_skb (skb); } +static bool skb_may_tx_timestamp (struct sock *sk) +{ +return sysctl_tstamp_allow_data ||capable (CAP_NET_RAW ) || + sk->sk_tsflags &SOF_TIMESTAMPING_OPT_TSONLY ; +} +void skb_complete_tx_timestamp (struct sk_buff *skb,struct skb_shared_hwtstamps *hwtstamps) {struct sock *sk = skb->sk; +if (!skb_may_tx_timestamp (sk)) +return ; +/* take a reference to prevent skb_orphan() from freeing the socket */ sock_hold (sk);
@@ -3712,7 +3721,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,struct sk_buff *skb;bool tsonly = sk->sk_tsflags &SOF_TIMESTAMPING_OPT_TSONLY ; -if (!sk) +if (!sk || !skb_may_tx_timestamp (sk))return ;if (tsonly)
net/core/sock.c +3 -0
@@ -325,6 +325,8 @@ __u32 sysctl_rmem_default __read_mostly = SK_RMEM_MAX;int sysctl_optmem_max__read_mostly =sizeof (unsigned long )*(2 *UIO_MAXIOV +512 );EXPORT_SYMBOL (sysctl_optmem_max); +int sysctl_tstamp_allow_data__read_mostly =1 ; +struct static_key memalloc_socks =STATIC_KEY_INIT_FALSE ;EXPORT_SYMBOL_GPL (memalloc_socks);
@@ -840,6 +842,7 @@ set_rcvbuf: ret = -EINVAL ;break ; } +if (val &SOF_TIMESTAMPING_OPT_ID && !(sk->sk_tsflags &SOF_TIMESTAMPING_OPT_ID )) {if (sk->sk_protocol ==IPPROTO_TCP ) {
net/core/sysctl_net_core.c +9 -0
@@ -321,6 +321,15 @@ static struct ctl_table net_core_table[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "tstamp_allow_data", + .data = &sysctl_tstamp_allow_data, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one + },#ifdef CONFIG_RPS { .procname = "rps_sock_flow_entries",
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Willem de Bruijn
maintainerRFC PATCH 3/5 net-timestamp: no-payload option in txtimestamp test
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
Demonstrate how SOF_TIMESTAMPING_OPT_TSONLY can be used and test the implementation.
--- .../networking/timestamping/txtimestamp.c | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)
Documentation/networking/timestamping/txtimestamp.c +24 -4
@@ -68,6 +68,7 @@ static int do_ipv6 = 1;static int cfg_payload_len =10 ;static bool cfg_show_payload;static bool cfg_do_pktinfo; +static bool cfg_loop_nodata;static uint16_t dest_port =9000 ;static struct sockaddr_in daddr;
@@ -139,6 +140,9 @@ static void print_payload(char *data, int len) {int i; +if (!len) +return ; +if (len >70 ) len =70 ;
@@ -175,6 +179,7 @@ static void __recv_errmsg_cmsg(struct msghdr *msg, int payload_len)struct sock_extended_err *serr =NULL ;struct scm_timestamping *tss =NULL ;struct cmsghdr *cm; +int batch =0 ; for (cm = CMSG_FIRSTHDR(msg); cm && cm->cmsg_len;
@@ -207,10 +212,18 @@ static void __recv_errmsg_cmsg(struct msghdr *msg, int payload_len) }else fprintf (stderr,"unknown cmsg %d,%d\n" , cm->cmsg_level, cm->cmsg_type); + +if (serr && tss) { +print_timestamp (tss, serr->ee_info, serr->ee_data, + payload_len); + serr =NULL ; + tss =NULL ; + batch++; + } } -if (serr && tss) -print_timestamp (tss, serr->ee_info, serr->ee_data, payload_len); +if (batch >1 ) +fprintf (stderr,"batched %d timestamps\n" , batch); }static int recv_errmsg (int fd)
@@ -242,7 +255,7 @@ static int recv_errmsg(int fd)if (ret ==-1 && errno !=EAGAIN )error (1 , errno,"recvmsg" ); -if (ret >0 ) { +if (ret >=0 ) {__recv_errmsg_cmsg (&msg, ret);if (cfg_show_payload)print_payload (data, cfg_payload_len);
@@ -307,6 +320,9 @@ static void do_test(int family, unsigned int opt) opt |=SOF_TIMESTAMPING_SOFTWARE |SOF_TIMESTAMPING_OPT_CMSG |SOF_TIMESTAMPING_OPT_ID ; +if (cfg_loop_nodata) + opt |=SOF_TIMESTAMPING_OPT_TSONLY ; +if (setsockopt (fd,SOL_SOCKET ,SO_TIMESTAMPING , (char *) &opt,sizeof (opt)))error (1 ,0 ,"setsockopt timestamping" );
@@ -376,6 +392,7 @@ static void __attribute__((noreturn)) usage(const char *filepath)" -h: show this message\n" " -I: request PKTINFO\n" " -l N: send N bytes at a time\n" +" -n: set no-payload option\n" " -r: use raw\n" " -R: use raw (IP_HDRINCL)\n" " -p N: connect to port N\n"
@@ -390,7 +407,7 @@ static void parse_opt(int argc, char **argv)int proto_count =0 ;char c; -while ((c =getopt (argc, argv,"46hIl:p:rRux" )) !=-1 ) { +while ((c =getopt (argc, argv,"46hIl:np:rRux" )) !=-1 ) {switch (c) {case '4' : do_ipv6 =0 ;
@@ -401,6 +418,9 @@ static void parse_opt(int argc, char **argv)case 'I' : cfg_do_pktinfo = true;break ; +case 'n' : + cfg_loop_nodata = true; +break ;case 'r' : proto_count++; cfg_proto =SOCK_RAW ;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Willem de Bruijn
maintainerRFC PATCH 4/5 net-timestamp: tx timestamp cookies
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
Support looping multiple timestamps on top of a single skb on the error queue.
Tx timestamps are returned on top of an skb. TCP timestamping and other timestamp points enabled multiple timestamps for each buffer passed in send. Due to retransmissions, this number may be high, using lots of SO_RCVBUF space and kernel mode switches.
When returning without payload (SOF_TIMESTAMPING_OPT_TSONLY), the total truesize is smaller, but still O(n). Without payload, the constraint that a timestamp belongs to a specific skb also goes away.
Instead of queuing multiple skbs onto the error queue, queue successive timestamps onto the skb on top of the error queue. For this purpose, introduce a timestamp cookie and use a list of cookies instead of skb->tstamp.
The number of batched cookies is limited by having sends fail with EAGAIN or ENOMSG as soon as a single packet is waiting on the receive queue. If merging this functionality, a TODO is to add a hard cap, so that processes can estimate the maximum msg_controllen needed to read all timestamps.
The implementation returns the same structures as before, that is, one struct sock_extended_err and one struct scm_timestamping for each timestamp. The list is returned in reverse chronological
order: newest first. This choice is partially determined by the callers (e.g., ip_recv_error) generating the final sock_extended_err.
--- include/linux/skbuff.h | 12 +++++ include/net/sock.h | 3 +- include/uapi/linux/errqueue.h | 1 + net/core/skbuff.c | 104 ++++++++++++++++++++++++++++++++++++------ net/socket.c | 64 ++++++++++++++++++++++++-- 5 files changed, 167 insertions(+), 17 deletions(-)
include/linux/skbuff.h +12 -0
@@ -298,6 +298,13 @@ struct ubuf_info {unsigned long desc; }; +struct skb_tstamp_cookie { +u32 tskey; +u32 tstype; +ktime_t tstamp; +struct skb_tstamp_cookie *next; +}; +/* This data is invariant across clones and lives at * the end of the header data, ie. at skb->end. */
@@ -442,6 +449,8 @@ static inline u32 skb_mstamp_us_delta(const struct skb_mstamp *t1,* @next: Next buffer in list * @prev: Previous buffer in list * @tstamp: Time we arrived/left +* @skb_mstamp: tstamp variant used only within the TCP stack +* @tscookies: tstamp variant used only with no-payload errqueue packets * @rbnode: RB tree node, alternative to next/prev for netem/tcp * @sk: Socket we are owned by * @dev: Device we arrived on/are leaving by
@@ -516,6 +525,7 @@ struct sk_buff {union {ktime_t tstamp;struct skb_mstamp skb_mstamp; +struct skb_tstamp_cookie *tscookies; }; };struct rb_node rbnode;/* used in netem & tcp stack */
@@ -2861,6 +2871,8 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,struct skb_shared_hwtstamps *hwtstamps, struct sock *sk, int tstype); +bool skb_has_tscookies (struct sk_buff *skb); +/** * skb_tstamp_tx - queue clone of skb with send time stamps * @orig_skb: the original outgoing packet
include/net/sock.h +2 -1
@@ -2149,7 +2149,8 @@ sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)*/ if (sock_flag (sk,SOCK_RCVTSTAMP ) || (sk->sk_tsflags &SOF_TIMESTAMPING_RX_SOFTWARE ) || - (kt.tv64 && sk->sk_tsflags &SOF_TIMESTAMPING_SOFTWARE ) || + ((kt.tv64 ||skb_has_tscookies (skb)) && + sk->sk_tsflags &SOF_TIMESTAMPING_SOFTWARE ) || (hwtstamps->hwtstamp.tv64 && (sk->sk_tsflags &SOF_TIMESTAMPING_RAW_HARDWARE )))__sock_recv_timestamp (msg, sk, skb);
include/uapi/linux/errqueue.h +1 -0
@@ -41,6 +41,7 @@ enum {SCM_TSTAMP_SND ,/* driver passed skb to NIC, or HW */ SCM_TSTAMP_SCHED ,/* data entered the packet scheduler */ SCM_TSTAMP_ACK ,/* data acknowledged by peer */ + SCM_TSTAMP_HW, /* internal use: HW generated */ };#endif /* _UAPI_LINUX_ERRQUEUE_H */
net/core/skbuff.c +91 -13
149 lines not on this page · raw message
net/socket.c +61 -3
76 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Willem de Bruijn
maintainerRFC PATCH 5/5 net-timestamp: tx timestamping default mode flag
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
The number of timestamping points along the transmit path has grown, as have the options. Preferred behavior is to request timestamps with ID, without data (which enables batching) and for all supported timestamp points. Define a short option that enables all these defaults.
--- include/uapi/linux/net_tstamp.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/uapi/linux/net_tstamp.h +8 -0
@@ -27,6 +27,14 @@ enum {SOF_TIMESTAMPING_OPT_TSONLY = (1 <<11 ),SOF_TIMESTAMPING_LAST =SOF_TIMESTAMPING_OPT_TSONLY , + +SOF_TIMESTAMPING_TX =SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_TX_SCHED | +SOF_TIMESTAMPING_TX_ACK | +SOF_TIMESTAMPING_OPT_ID | +SOF_TIMESTAMPING_OPT_TSONLY , +SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST -1 ) | SOF_TIMESTAMPING_LAST };
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Re: [PATCH net-next RFC 5/5] net-timestamp: tx timestamping default mode flag
Quoted 7 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
The number of timestamping points along the transmit path has grown, as have the options. Preferred behavior is to request timestamps with ID, without data (which enables batching) and for all supported timestamp points. Define a short option that enables all these defaults.
This "preferred behavior" is subjective, and it depends on the application. I am sure it reflects your own interest, but for people doing PTP over UDP or raw, it is a bit misleading.
I would drop this default and just let applications define their own.
Thanks,
Richard
Willem de Bruijn
maintainerRe: [PATCH net-next RFC 5/5] net-timestamp: tx timestamping default mode flag
Quoted 9 lines · Richard Cochran
Quoted 7 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
The number of timestamping points along the transmit path has grown, as have the options. Preferred behavior is to request timestamps with ID, without data (which enables batching) and for all supported timestamp points. Define a short option that enables all these defaults.
Quoted 5 lines
This "preferred behavior" is subjective, and it depends on the application. I am sure it reflects your own interest, but for people doing PTP over UDP or raw, it is a bit misleading.
I would drop this default and just let applications define their own.
Okay. I indeed hadn't considered that use-case.
Just so I understand: ptp has no use for the sw tstamps that would be generated with this flag, but is otherwise okay with enabling counters to order tx timestamps (OPT_ID) and disabling payload (OPT_TSONLY)?
In the documentation, I would like to strongly suggest all processes to enable these, even in absence of this default. because that is more robust wrt the sysctl (if merged).
Quoted 2 lines
Thanks,
Thanks for taking a look at the patches.
Quoted 1 line
Richard
Re: [PATCH net-next RFC 5/5] net-timestamp: tx timestamping default mode flag
Quoted 4 lines · Willem de Bruijn
Just so I understand: ptp has no use for the sw tstamps that would be generated with this flag, but is otherwise okay with enabling counters to order tx timestamps (
OPT_ID) and disabling payload (OPT_TSONLY)?
Yes.
Quoted 3 lines
In the documentation, I would like to strongly suggest all processes to enable these, even in absence of this default. because that is more robust wrt the sysctl (if merged).
Sounds good.
Thanks,
Richard