Skip to contentSkip to conversation

net: test nouarg before dereferencing zerocopy pointers

PATCH In review Willem de Bruijn 2 participants 2 messages May 15, 2019 – May 16, 2019

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

PATCH 1/1 net: test nouarg before dereferencing zerocopy pointers

From: Willem de Bruijn <[email protected]>

Zerocopy skbs without completion notification were added for packet sockets with PACKET_TX_RING user buffers. Those signal completion through the TP_STATUS_USER bit in the ring. Zerocopy annotation was added only to avoid premature notification after clone or orphan, by triggering a copy on these paths for these packets.

The mechanism had to define a special "no-uarg" mode because packet sockets already use skb_uarg(skb) == skb_shinfo(skb)->destructor_arg for a different pointer.

Before deferencing skb_uarg(skb), verify that it is a real pointer.

Fixes 5cd8d46ea1562 ("packet: copy user buffers before orphan or clone")
---
 include/linux/skbuff.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
include/linux/skbuff.h +6 -3
index 6d58fa8a65fde..2ee5e63195c02 100644
@@ -1434,10 +1434,12 @@ static inline void skb_zcopy_clear(struct sk_buff *skb, bool zerocopy)
 	struct ubuf_info *uarg = skb_zcopy(skb);
 
 	if (uarg) {
-		if (uarg->callback == sock_zerocopy_callback) {
+		if (skb_zcopy_is_nouarg(skb)) {
+			/* no notification callback */
+		} else if (uarg->callback == sock_zerocopy_callback) {
 			uarg->zerocopy = uarg->zerocopy && zerocopy;
 			sock_zerocopy_put(uarg);
-		} else if (!skb_zcopy_is_nouarg(skb)) {
+		} else {
 			uarg->callback(uarg, zerocopy);
 		}
 
@@ -2691,7 +2693,8 @@ static inline int skb_orphan_frags(struct sk_buff *skb, gfp_t gfp_mask)
 {
 	if (likely(!skb_zcopy(skb)))
 		return 0;
-	if (skb_uarg(skb)->callback == sock_zerocopy_callback)
+	if (!skb_zcopy_is_nouarg(skb) &&
+	    skb_uarg(skb)->callback == sock_zerocopy_callback)
 		return 0;
 	return skb_copy_ubufs(skb, gfp_mask);
 }
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
maintainer
#1 lore raw

From: Willem de Bruijn <[email protected]>
Date: Wed, 15 May 2019 13:29:16 -0400

Quoted 8 lines

From: Willem de Bruijn <[email protected]>

Zerocopy skbs without completion notification were added for packet sockets with PACKET_TX_RING user buffers. Those signal completion through the TP_STATUS_USER bit in the ring. Zerocopy annotation was added only to avoid premature notification after clone or orphan, by triggering a copy on these paths for these packets.

Quoted 8 lines

The mechanism had to define a special "no-uarg" mode because packet sockets already use skb_uarg(skb) == skb_shinfo(skb)->destructor_arg for a different pointer.

Before deferencing skb_uarg(skb), verify that it is a real pointer.

Fixes 5cd8d46ea1562 ("packet: copy user buffers before orphan or clone")

Applied and queued up for -stable, thanks.