Skip to contentSkip to conversation

tap: fix incorrect variable used for USO check in set_offload()

PATCH Applied Rongguang Wei 3 participants 6 messages Aug 7 – Aug 10

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

PATCH v2 1/1 tap: fix incorrect variable used for USO check in set_offload()

From: Rongguang Wei <[email protected]>

The USO features in set_offload() incorrectly uses feature_mask and features argument.

The USO feature was written to the local features variable instead of feature_mask. All other offload bits (TSO, TSO_ECN) are stored in feature_mask which becomes tap->tap_features and is used by tap_handle_frame() for GSO segmentation. Without NETIF_F_GSO_UDP_L4 in tap->tap_features, making USO on tap effectively non-functional.

Keeping the USO handling inside the TUN_F_CSUM block avoids enabling GRO/LRO when userspace requests USO without CSUM.

Fixes 399e0827642f ("driver/net/tun: Added features for USO.")

---
v2: Fix more incorrect variable in USO check.

    https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/
---
 drivers/net/tap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/tap.c +2 -3
index 5d2d34d24ce8..d4ca2fee538b 100644
@@ -883,7 +883,7 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
 
 		/* TODO: for now USO4 and USO6 should work simultaneously */
 		if ((arg & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
-			features |= NETIF_F_GSO_UDP_L4;
+			feature_mask |= NETIF_F_GSO_UDP_L4;
 	}
 
 	/* tun/tap driver inverts the usage for TSO offloads, where
@@ -894,8 +894,7 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
 	 * When user space turns off TSO, we turn off GSO/LRO so that
 	 * user-space will not receive TSO frames.
 	 */
-	if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6) ||
-	    (feature_mask & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
+	if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_UDP_L4))
 		features |= RX_OFFLOADS;
 	else
 		features &= ~RX_OFFLOADS;
Signature · 5 lines
2.25.1


No virus found
		Checked by Hillstone Network AntiVirus
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Rongguang Wei

From: Rongguang Wei <[email protected]>

The USO features in set_offload() incorrectly uses feature_mask and features argument.

The USO feature was written to the local features variable instead of feature_mask. All other offload bits (TSO, TSO_ECN) are stored in feature_mask which becomes tap->tap_features and is used by tap_handle_frame() for GSO segmentation. Without NETIF_F_GSO_UDP_L4 in tap->tap_features, making USO on tap effectively non-functional.

Quoted 6 lines

Keeping the USO handling inside the TUN_F_CSUM block avoids enabling GRO/LRO when userspace requests USO without CSUM.

Fixes 399e0827642f ("driver/net/tun: Added features for USO.")

Substantially changed patch, please don't keep Reviewed-by tags across non-trivial changes. That said, I do agree, so adding it again.

Quoted 13 lines

---
v2: Fix more incorrect variable in USO check.

    https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/
---
 drivers/net/tap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/tap.c +0 -0
index 5d2d34d24ce8..d4ca2fee538b 100644

drivers/net/tap.c static int set_offload(struct tap_queue *q, unsigned long arg) · line 886

Quoted 5 lines
drivers/net/tap.c +1 -1
@@ -883,7 +883,7 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
 
 		/* TODO: for now USO4 and USO6 should work simultaneously */
 		if ((arg & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
-			features |= NETIF_F_GSO_UDP_L4;
+			feature_mask |= NETIF_F_GSO_UDP_L4;

Drivers/net/tun seems to have this same issue.

Do you want to take a look or shall I?

Quoted 13 lines
drivers/net/tap.c +1 -2
 	}
 
 	/* tun/tap driver inverts the usage for TSO offloads, where
@@ -894,8 +894,7 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
 	 * When user space turns off TSO, we turn off GSO/LRO so that
 	 * user-space will not receive TSO frames.
 	 */
-	if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6) ||
-	    (feature_mask & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
+	if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_UDP_L4))
 		features |= RX_OFFLOADS;
 	else
 		features &= ~RX_OFFLOADS;
#2 lore raw
Quoted 15 lines · Willem de Bruijn
Quoted 14 lines · Rongguang Wei

From: Rongguang Wei <[email protected]>

The USO features in set_offload() incorrectly uses feature_mask and features argument.

The USO feature was written to the local features variable instead of feature_mask. All other offload bits (TSO, TSO_ECN) are stored in feature_mask which becomes tap->tap_features and is used by tap_handle_frame() for GSO segmentation. Without NETIF_F_GSO_UDP_L4 in tap->tap_features, making USO on tap effectively non-functional.

Keeping the USO handling inside the TUN_F_CSUM block avoids enabling GRO/LRO when userspace requests USO without CSUM.

Quoted 8 lines
Quoted 3 lines
Fixes 399e0827642f ("driver/net/tun: Added features for USO.")

Substantially changed patch, please don't keep Reviewed-by tags across non-trivial changes. That said, I do agree, so adding it again.

I am sorry for that and thanks for the reminder.

Quoted 15 lines
Quoted 15 lines

---
v2: Fix more incorrect variable in USO check.

    https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/
---
 drivers/net/tap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/tap.c +0 -0
index 5d2d34d24ce8..d4ca2fee538b 100644
@@ -883,7 +883,7 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
 
Quoted 8 lines

drivers/net/tap.c static int set_offload(struct tap_queue *q, unsigned long arg) · line 886

Quoted 4 lines
drivers/net/tap.c +1 -1
 		/* TODO: for now USO4 and USO6 should work simultaneously */
 		if ((arg & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
-			features |= NETIF_F_GSO_UDP_L4;
+			feature_mask |= NETIF_F_GSO_UDP_L4;

Drivers/net/tun seems to have this same issue.

Do you want to take a look or shall I?

Sure, I'd be glad to do with that. Should the tun modifications be combined with this patch?

Quoted 15 lines
Quoted 15 lines
drivers/net/tap.c +1 -2
 	}
 
 	/* tun/tap driver inverts the usage for TSO offloads, where
@@ -894,8 +894,7 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
 	 * When user space turns off TSO, we turn off GSO/LRO so that
 	 * user-space will not receive TSO frames.
 	 */
-	if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6) ||
-	    (feature_mask & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
+	if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_UDP_L4))
 		features |= RX_OFFLOADS;
 	else
 		features &= ~RX_OFFLOADS;
#3 lore raw
In reply to Willem de Bruijn
Quoted 38 lines · Willem de Bruijn
Quoted 11 lines · Rongguang Wei

From: Rongguang Wei <[email protected]>

The USO features in set_offload() incorrectly uses feature_mask and features argument.

The USO feature was written to the local features variable instead of feature_mask. All other offload bits (TSO, TSO_ECN) are stored in feature_mask which becomes tap->tap_features and is used by tap_handle_frame() for GSO segmentation. Without NETIF_F_GSO_UDP_L4 in tap->tap_features, making USO on tap effectively non-functional.

Quoted 6 lines

Keeping the USO handling inside the TUN_F_CSUM block avoids enabling GRO/LRO when userspace requests USO without CSUM.

Fixes 399e0827642f ("driver/net/tun: Added features for USO.")

Substantially changed patch, please don't keep Reviewed-by tags across non-trivial changes. That said, I do agree, so adding it again.

Quoted 14 lines

---
v2: Fix more incorrect variable in USO check.

    https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/
---
 drivers/net/tap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/tap.c +0 -0
index 5d2d34d24ce8..d4ca2fee538b 100644
@@ -883,7 +883,7 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
 
Quoted 9 lines

drivers/net/tap.c static int set_offload(struct tap_queue *q, unsigned long arg) · line 886

Quoted 4 lines
drivers/net/tap.c +1 -1
 		/* TODO: for now USO4 and USO6 should work simultaneously */
 		if ((arg & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
-			features |= NETIF_F_GSO_UDP_L4;
+			feature_mask |= NETIF_F_GSO_UDP_L4;

Drivers/net/tun seems to have this same issue.

Do you want to take a look or shall I?

Hi,
I have check the code in drivers/net/tun.c.
In tun.c, the tun's all offload bits go into features argument and I think tun.c does not have this issue.

Quoted 14 lines
Quoted 14 lines
drivers/net/tap.c +1 -2
 	}
 
 	/* tun/tap driver inverts the usage for TSO offloads, where
@@ -894,8 +894,7 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
 	 * When user space turns off TSO, we turn off GSO/LRO so that
 	 * user-space will not receive TSO frames.
 	 */
-	if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6) ||
-	    (feature_mask & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
+	if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_UDP_L4))
 		features |= RX_OFFLOADS;
 	else
 		features &= ~RX_OFFLOADS;
maintainer
#4 lore raw
Quoted 46 lines · Rongguang Wei
Quoted 45 lines · Willem de Bruijn
Quoted 11 lines · Rongguang Wei

From: Rongguang Wei <[email protected]>

The USO features in set_offload() incorrectly uses feature_mask and features argument.

The USO feature was written to the local features variable instead of feature_mask. All other offload bits (TSO, TSO_ECN) are stored in feature_mask which becomes tap->tap_features and is used by tap_handle_frame() for GSO segmentation. Without NETIF_F_GSO_UDP_L4 in tap->tap_features, making USO on tap effectively non-functional.

Quoted 6 lines

Keeping the USO handling inside the TUN_F_CSUM block avoids enabling GRO/LRO when userspace requests USO without CSUM.

Fixes 399e0827642f ("driver/net/tun: Added features for USO.")

Substantially changed patch, please don't keep Reviewed-by tags across non-trivial changes. That said, I do agree, so adding it again.

Quoted 13 lines

---
v2: Fix more incorrect variable in USO check.

    https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/
---
 drivers/net/tap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/tap.c +0 -0
index 5d2d34d24ce8..d4ca2fee538b 100644

drivers/net/tap.c static int set_offload(struct tap_queue *q, unsigned long arg) · line 886

Quoted 5 lines
drivers/net/tap.c +1 -1
@@ -883,7 +883,7 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
 
 		/* TODO: for now USO4 and USO6 should work simultaneously */
 		if ((arg & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
-			features |= NETIF_F_GSO_UDP_L4;
+			feature_mask |= NETIF_F_GSO_UDP_L4;

Drivers/net/tun seems to have this same issue.

Quoted 6 lines
Quoted 2 lines

Do you want to take a look or shall I?

Hi,
I have check the code in drivers/net/tun.c.
In tun.c, the tun's all offload bits go into features argument and I think tun.c does not have this issue.

Oh indeed. Thanks for checking.

To repeat, this patch LGTM.

#5 lore raw
In reply to Rongguang Wei
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 5 lines · On Fri, 7 Aug 2026 15:09:14 +0800 you wrote:

From: Rongguang Wei <[email protected]>

The USO features in set_offload() incorrectly uses feature_mask and features argument.

Quoted 7 lines

The USO feature was written to the local features variable instead of feature_mask. All other offload bits (TSO, TSO_ECN) are stored in feature_mask which becomes tap->tap_features and is used by tap_handle_frame() for GSO segmentation. Without NETIF_F_GSO_UDP_L4 in tap->tap_features, making USO on tap effectively non-functional.

[...]

Here is the summary with links:
- [net,v2] tap: fix incorrect variable used for USO check in set_offload()

    https://git.kernel.org/netdev/net-next/c/fac7973f004d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html