Skip to contentSkip to conversation

tcp: really ignore MSG_ZEROCOPY if no SO_ZEROCOPY

PATCH In review Vincent Whitchurch 3 participants 3 messages Sep 6, 2018 – Sep 8, 2018

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

PATCH 1/1 tcp: really ignore MSG_ZEROCOPY if no SO_ZEROCOPY

According to the documentation in msg_zerocopy.rst, the SO_ZEROCOPY flag was introduced because send(2) ignores unknown message flags and any legacy application which was accidentally passing the equivalent of MSG_ZEROCOPY earlier should not see any new behaviour.

Before commit f214f915e7db ("tcp: enable MSG_ZEROCOPY"), a send(2) call which passed the equivalent of MSG_ZEROCOPY without setting SO_ZEROCOPY would succeed. However, after that commit, it fails with -ENOBUFS. So it appears that the SO_ZEROCOPY flag fails to fulfill its intended purpose. Fix it.

Fixes f214f915e7db ("tcp: enable MSG_ZEROCOPY")
---
 net/core/skbuff.c | 3 ---
 net/ipv4/tcp.c    | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
net/core/skbuff.c +0 -3
index c996c09d095f..b2c807f67aba 100644
@@ -939,9 +939,6 @@ struct ubuf_info *sock_zerocopy_alloc(struct sock *sk, size_t size)
 
 	WARN_ON_ONCE(!in_task());
 
-	if (!sock_flag(sk, SOCK_ZEROCOPY))
-		return NULL;
-
 	skb = sock_omalloc(sk, 0, GFP_KERNEL);
 	if (!skb)
 		return NULL;
net/ipv4/tcp.c +1 -1
index b8af2fec5ad5..10c6246396cc 100644
@@ -1185,7 +1185,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
 
 	flags = msg->msg_flags;
 
-	if (flags & MSG_ZEROCOPY && size) {
+	if (flags & MSG_ZEROCOPY && size && sock_flag(sk, SOCK_ZEROCOPY)) {
 		if (sk->sk_state != TCP_ESTABLISHED) {
 			err = -EINVAL;
 			goto out_err;
Signature · 1 line
2.11.0
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Vincent Whitchurch

According to the documentation in msg_zerocopy.rst, the SO_ZEROCOPY flag was introduced because send(2) ignores unknown message flags and any legacy application which was accidentally passing the equivalent of MSG_ZEROCOPY earlier should not see any new behaviour.

Before commit f214f915e7db ("tcp: enable MSG_ZEROCOPY"), a send(2) call which passed the equivalent of MSG_ZEROCOPY without setting SO_ZEROCOPY would succeed. However, after that commit, it fails with -ENOBUFS. So it appears that the SO_ZEROCOPY flag fails to fulfill its intended purpose. Fix it.

Quoted 3 lines
Fixes f214f915e7db ("tcp: enable MSG_ZEROCOPY")

Good catch, thanks for fixing this.

Please remember to mark patches with PATCH net

maintainer
#2 lore raw
In reply to Vincent Whitchurch

From: Vincent Whitchurch <[email protected]>
Date: Thu, 6 Sep 2018 15:54:59 +0200

Quoted 5 lines

According to the documentation in msg_zerocopy.rst, the SO_ZEROCOPY flag was introduced because send(2) ignores unknown message flags and any legacy application which was accidentally passing the equivalent of MSG_ZEROCOPY earlier should not see any new behaviour.

Quoted 8 lines

Before commit f214f915e7db ("tcp: enable MSG_ZEROCOPY"), a send(2) call which passed the equivalent of MSG_ZEROCOPY without setting SO_ZEROCOPY would succeed. However, after that commit, it fails with -ENOBUFS. So it appears that the SO_ZEROCOPY flag fails to fulfill its intended purpose. Fix it.

Fixes f214f915e7db ("tcp: enable MSG_ZEROCOPY")

Applied and queued up for -stable, thanks.