Skip to contentSkip to conversation

udp: Fix UDP length on last GSO_PARTIAL segment

PATCH In review Gal Pressman 2 participants 9 messages May 13 – May 17

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

PATCH 1/1 udp: Fix UDP length on last GSO_PARTIAL segment

Following the cited commit, __udp_gso_segment() writes single MSS length in the UDP header.
The cited patch doesn't account for the fact that the last segment could be a GSO skb by itself. This could happen when the size of the packet is a multiple of MSS, hence the first segment is also the last one (there is no need for a remainder skb).

When the post-loop segment is a GSO skb, assign the single MSS length in the UDP header.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL")
---
 net/ipv4/udp_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp_offload.c +1 -1
index a0813d425b71..71df45f9488a 100644
@@ -604,7 +604,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		       seg->data_len);
 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
 
-	uh->len = newlen;
+	uh->len = skb_is_gso(seg) ? msslen : newlen;
 	uh->check = check;
 
 	if (seg->ip_summed == CHECKSUM_PARTIAL)
Signature · 1 line
2.52.0
#1 lore raw
Quoted 27 lines · Gal Pressman

Following the cited commit, __udp_gso_segment() writes single MSS length in the UDP header.
The cited patch doesn't account for the fact that the last segment could be a GSO skb by itself. This could happen when the size of the packet is a multiple of MSS, hence the first segment is also the last one (there is no need for a remainder skb).

When the post-loop segment is a GSO skb, assign the single MSS length in the UDP header.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for

GSO_PARTIAL")

Closes:
https://lore.kernel.org/all/[email protected]/

---
 net/ipv4/udp_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp_offload.c +0 -0
index a0813d425b71..71df45f9488a 100644

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 608

Quoted 6 lines
net/ipv4/udp_offload.c +1 -1
@@ -604,7 +604,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		       seg->data_len);
 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
 
-	uh->len = newlen;
+	uh->len = skb_is_gso(seg) ? msslen : newlen;
 	uh->check = check;

This is going to have the same checksum bug as your first commit, which I'm fixing in [1]. You should use the right value of either msslen or newlen when modifying check a couple of lines above.

That said, maybe you can base your patch on top of my checksum fix? For the last packet, it will then be:

if (!skb_is_gso(seg))

        newlen = /* the new value */;

/* keep newlen as is otherwise: my newlen is your msslen */ check = csum16_add(csum16_sub(uh->check, uh->len), newlen); uh->len = newlen;
uh->check = check;

[1]: https://lore.kernel.org/netdev/[email protected]/

Quoted 4 lines
net/ipv4/udp_offload.c +0 -0
 	if (seg->ip_summed == CHECKSUM_PARTIAL)
Signature · 1 line
2.52.0
#2 lore raw
Quoted 31 lines · Alice Mikityanska
Quoted 30 lines · Gal Pressman

Following the cited commit, __udp_gso_segment() writes single MSS length in the UDP header.
The cited patch doesn't account for the fact that the last segment could be a GSO skb by itself. This could happen when the size of the packet is a multiple of MSS, hence the first segment is also the last one (there is no need for a remainder skb).

When the post-loop segment is a GSO skb, assign the single MSS length in the UDP header.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for

GSO_PARTIAL")

Closes:
https://lore.kernel.org/all/[email protected]/

---
 net/ipv4/udp_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp_offload.c +0 -0
index a0813d425b71..71df45f9488a 100644
@@ -604,7 +604,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		       seg->data_len);
 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
 
Quoted 7 lines

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 608

Quoted 3 lines
net/ipv4/udp_offload.c +1 -1
-	uh->len = newlen;
+	uh->len = skb_is_gso(seg) ? msslen : newlen;
 	uh->check = check;

This is going to have the same checksum bug as your first commit, which I'm fixing in [1]. You should use the right value of either msslen or newlen when modifying check a couple of lines above.

I tend to agree that the checksum seems to have the wrong value, the reason I chose not to change it is because my work only moved the UDP length assignment from the drivers to the stack.

The "wrong" checksum value was used regardless of my change, and I prefer not to change it as part of this work.

Quoted 4 lines

That said, maybe you can base your patch on top of my checksum fix? For the last packet, it will then be:

Quoted 8 lines

if (!skb_is_gso(seg))

        newlen = /* the new value */;

/* keep newlen as is otherwise: my newlen is your msslen */ check = csum16_add(csum16_sub(uh->check, uh->len), newlen); uh->len = newlen;
uh->check = check;

[1]: https://lore.kernel.org/netdev/[email protected]/

As I mentioned in the other thread, this fix goes to net, I can't take your patch.

#3 lore raw
Quoted 40 lines · Gal Pressman
Quoted 31 lines · Alice Mikityanska
Quoted 30 lines · Gal Pressman

Following the cited commit, __udp_gso_segment() writes single MSS length in the UDP header.
The cited patch doesn't account for the fact that the last segment could be a GSO skb by itself. This could happen when the size of the packet is a multiple of MSS, hence the first segment is also the last one (there is no need for a remainder skb).

When the post-loop segment is a GSO skb, assign the single MSS length in the UDP header.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for

GSO_PARTIAL")

Closes:
https://lore.kernel.org/all/[email protected]/

---
 net/ipv4/udp_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp_offload.c +0 -0
index a0813d425b71..71df45f9488a 100644
@@ -604,7 +604,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		       seg->data_len);
 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
 
Quoted 7 lines

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 608

Quoted 3 lines
net/ipv4/udp_offload.c +1 -1
-	uh->len = newlen;
+	uh->len = skb_is_gso(seg) ? msslen : newlen;
 	uh->check = check;

This is going to have the same checksum bug as your first commit, which I'm fixing in [1]. You should use the right value of either msslen or newlen when modifying check a couple of lines above.

Quoted 5 lines

I tend to agree that the checksum seems to have the wrong value, the reason I chose not to change it is because my work only moved the UDP length assignment from the drivers to the stack.

The "wrong" checksum value was used regardless of my change,

The wrong checksum was visible only inside the driver, and since the hardware didn't care (due to the offload), it worked well. It was the driver business to make sure the corresponding hardware likes the packet. After commit b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL"), however, the wrong checksum moved one abstraction layer higher - to the networking stack, which attempts to keep the checksum correct for a more generic case. It's not the same, and while I'm trying to fix one occurrence, I'd prefer not to introduce more.

Quoted 14 lines

and I
prefer not to change it as part of this work.

Quoted 11 lines

That said, maybe you can base your patch on top of my checksum fix? For the last packet, it will then be:

if (!skb_is_gso(seg))

        newlen = /* the new value */;

/* keep newlen as is otherwise: my newlen is your msslen */ check = csum16_add(csum16_sub(uh->check, uh->len), newlen); uh->len = newlen;
uh->check = check;

Quoted 4 lines
Quoted 1 line

[1]: https://lore.kernel.org/netdev/[email protected]/

As I mentioned in the other thread, this fix goes to net, I can't take your patch.

Ah, that's right. Still, I guess you can take mine to net for the checksum fix.

#4 lore raw
Quoted 71 lines · Alice Mikityanska
Quoted 40 lines · Gal Pressman
Quoted 31 lines · Alice Mikityanska
Quoted 30 lines · Gal Pressman

Following the cited commit, __udp_gso_segment() writes single MSS length in the UDP header.
The cited patch doesn't account for the fact that the last segment could be a GSO skb by itself. This could happen when the size of the packet is a multiple of MSS, hence the first segment is also the last one (there is no need for a remainder skb).

When the post-loop segment is a GSO skb, assign the single MSS length in the UDP header.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for

GSO_PARTIAL")

Closes:
https://lore.kernel.org/all/[email protected]/

---
 net/ipv4/udp_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp_offload.c +0 -0
index a0813d425b71..71df45f9488a 100644
@@ -604,7 +604,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		       seg->data_len);
 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
 
Quoted 7 lines

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 608

Quoted 3 lines
net/ipv4/udp_offload.c +1 -1
-	uh->len = newlen;
+	uh->len = skb_is_gso(seg) ? msslen : newlen;
 	uh->check = check;

This is going to have the same checksum bug as your first commit, which I'm fixing in [1]. You should use the right value of either msslen or newlen when modifying check a couple of lines above.

Quoted 5 lines

I tend to agree that the checksum seems to have the wrong value, the reason I chose not to change it is because my work only moved the UDP length assignment from the drivers to the stack.

The "wrong" checksum value was used regardless of my change,

The wrong checksum was visible only inside the driver, and since the hardware didn't care (due to the offload), it worked well. It was the driver business to make sure the corresponding hardware likes the packet. After commit b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL"), however, the wrong checksum moved one abstraction layer higher - to the networking stack, which attempts to keep the checksum correct for a more generic case. It's not the same, and while I'm trying to fix one occurrence, I'd prefer not to introduce more.

Quoted 14 lines

and I
prefer not to change it as part of this work.

Quoted 11 lines

That said, maybe you can base your patch on top of my checksum fix? For the last packet, it will then be:

if (!skb_is_gso(seg))

        newlen = /* the new value */;

/* keep newlen as is otherwise: my newlen is your msslen */ check = csum16_add(csum16_sub(uh->check, uh->len), newlen); uh->len = newlen;
uh->check = check;

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

[1]: https://lore.kernel.org/netdev/[email protected]/

As I mentioned in the other thread, this fix goes to net, I can't take your patch.

Ah, that's right. Still, I guess you can take mine to net for the checksum fix.

Do you think it is suitable for net? Would you like to rephrase the commit message accordingly?

If you can send me an updated version I will take it and submit both (or you can submit mine if you prefer).

#5 lore raw
Quoted 74 lines · Gal Pressman
Quoted 73 lines · Alice Mikityanska
Quoted 40 lines · Gal Pressman
Quoted 31 lines · Alice Mikityanska
Quoted 30 lines · Gal Pressman

Following the cited commit, __udp_gso_segment() writes single MSS length in the UDP header.
The cited patch doesn't account for the fact that the last segment could be a GSO skb by itself. This could happen when the size of the packet is a multiple of MSS, hence the first segment is also the last one (there is no need for a remainder skb).

When the post-loop segment is a GSO skb, assign the single MSS length in the UDP header.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for

GSO_PARTIAL")

Closes:
https://lore.kernel.org/all/[email protected]/

---
 net/ipv4/udp_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp_offload.c +0 -0
index a0813d425b71..71df45f9488a 100644
@@ -604,7 +604,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		       seg->data_len);
 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
 
Quoted 7 lines

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 608

Quoted 3 lines
net/ipv4/udp_offload.c +1 -1
-	uh->len = newlen;
+	uh->len = skb_is_gso(seg) ? msslen : newlen;
 	uh->check = check;

This is going to have the same checksum bug as your first commit, which I'm fixing in [1]. You should use the right value of either msslen or newlen when modifying check a couple of lines above.

Quoted 5 lines

I tend to agree that the checksum seems to have the wrong value, the reason I chose not to change it is because my work only moved the UDP length assignment from the drivers to the stack.

The "wrong" checksum value was used regardless of my change,

The wrong checksum was visible only inside the driver, and since the hardware didn't care (due to the offload), it worked well. It was the driver business to make sure the corresponding hardware likes the packet. After commit b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL"), however, the wrong checksum moved one abstraction layer higher - to the networking stack, which attempts to keep the checksum correct for a more generic case. It's not the same, and while I'm trying to fix one occurrence, I'd prefer not to introduce more.

Quoted 16 lines

and I
prefer not to change it as part of this work.

Quoted 12 lines

That said, maybe you can base your patch on top of my checksum fix? For the last packet, it will then be:

if (!skb_is_gso(seg))

        newlen = /* the new value */;

/* keep newlen as is otherwise: my newlen is your msslen */ check = csum16_add(csum16_sub(uh->check, uh->len), newlen); uh->len = newlen;
uh->check = check;

[1]: https://lore.kernel.org/netdev/[email protected]/

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

As I mentioned in the other thread, this fix goes to net, I can't take your patch.

Ah, that's right. Still, I guess you can take mine to net for the checksum fix.

Do you think it is suitable for net?

This is always a mystery to me... I've had different experiences:
sometimes I am asked to resubmit less important fixes to -next, sometimes a fix is a fix and must go to net. This one is a refactoring useful for my further patches + the checksum fix, which we get for free and which I considered not important enough to submit to net (hardware offload fixes the checksum in most cases anyway). Following the "a fix is a fix" logic, we may try sending it to net. What do you think?

Quoted 5 lines

Would you like to rephrase the
commit message accordingly?

If you can send me an updated version I will take it and submit both (or you can submit mine if you prefer).

#6 lore raw
Quoted 83 lines · Alice Mikityanska
Quoted 74 lines · Gal Pressman
Quoted 73 lines · Alice Mikityanska
Quoted 40 lines · Gal Pressman
Quoted 31 lines · Alice Mikityanska
Quoted 30 lines · Gal Pressman

Following the cited commit, __udp_gso_segment() writes single MSS length in the UDP header.
The cited patch doesn't account for the fact that the last segment could be a GSO skb by itself. This could happen when the size of the packet is a multiple of MSS, hence the first segment is also the last one (there is no need for a remainder skb).

When the post-loop segment is a GSO skb, assign the single MSS length in the UDP header.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for

GSO_PARTIAL")

Closes:
https://lore.kernel.org/all/[email protected]/

---
 net/ipv4/udp_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp_offload.c +0 -0
index a0813d425b71..71df45f9488a 100644
@@ -604,7 +604,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		       seg->data_len);
 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
 
Quoted 7 lines

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 608

Quoted 3 lines
net/ipv4/udp_offload.c +1 -1
-	uh->len = newlen;
+	uh->len = skb_is_gso(seg) ? msslen : newlen;
 	uh->check = check;

This is going to have the same checksum bug as your first commit, which I'm fixing in [1]. You should use the right value of either msslen or newlen when modifying check a couple of lines above.

Quoted 5 lines

I tend to agree that the checksum seems to have the wrong value, the reason I chose not to change it is because my work only moved the UDP length assignment from the drivers to the stack.

The "wrong" checksum value was used regardless of my change,

The wrong checksum was visible only inside the driver, and since the hardware didn't care (due to the offload), it worked well. It was the driver business to make sure the corresponding hardware likes the packet. After commit b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL"), however, the wrong checksum moved one abstraction layer higher - to the networking stack, which attempts to keep the checksum correct for a more generic case. It's not the same, and while I'm trying to fix one occurrence, I'd prefer not to introduce more.

Quoted 16 lines

and I
prefer not to change it as part of this work.

Quoted 12 lines

That said, maybe you can base your patch on top of my checksum fix? For the last packet, it will then be:

if (!skb_is_gso(seg))

        newlen = /* the new value */;

/* keep newlen as is otherwise: my newlen is your msslen */ check = csum16_add(csum16_sub(uh->check, uh->len), newlen); uh->len = newlen;
uh->check = check;

[1]: https://lore.kernel.org/netdev/[email protected]/

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

As I mentioned in the other thread, this fix goes to net, I can't take your patch.

Ah, that's right. Still, I guess you can take mine to net for the checksum fix.

Do you think it is suitable for net?

Quoted 7 lines

This is always a mystery to me... I've had different experiences:
sometimes I am asked to resubmit less important fixes to -next, sometimes a fix is a fix and must go to net. This one is a refactoring useful for my further patches + the checksum fix, which we get for free and which I considered not important enough to submit to net (hardware offload fixes the checksum in most cases anyway). Following the "a fix is a fix" logic, we may try sending it to net. What do you think?

IMHO, the motivation you provided in your previous message for the checksum fix is convincing, but as I said, I think the commit message should be phrased to explain the bug rather than the refactoring (and add a Fixes tag).

Reviewed-by Willem de Bruijn
#7 lore raw
Quoted 92 lines · Gal Pressman
Quoted 83 lines · Alice Mikityanska
Quoted 74 lines · Gal Pressman
Quoted 73 lines · Alice Mikityanska
Quoted 40 lines · Gal Pressman
Quoted 31 lines · Alice Mikityanska
Quoted 30 lines · Gal Pressman

Following the cited commit, __udp_gso_segment() writes single MSS length in the UDP header.
The cited patch doesn't account for the fact that the last segment could be a GSO skb by itself. This could happen when the size of the packet is a multiple of MSS, hence the first segment is also the last one (there is no need for a remainder skb).

When the post-loop segment is a GSO skb, assign the single MSS length in the UDP header.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for

GSO_PARTIAL")

Closes:
https://lore.kernel.org/all/[email protected]/

---
 net/ipv4/udp_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp_offload.c +0 -0
index a0813d425b71..71df45f9488a 100644
@@ -604,7 +604,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		       seg->data_len);
 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
 
Quoted 7 lines

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 608

Quoted 3 lines
net/ipv4/udp_offload.c +1 -1
-	uh->len = newlen;
+	uh->len = skb_is_gso(seg) ? msslen : newlen;
 	uh->check = check;

This is going to have the same checksum bug as your first commit, which I'm fixing in [1]. You should use the right value of either msslen or newlen when modifying check a couple of lines above.

Quoted 5 lines

I tend to agree that the checksum seems to have the wrong value, the reason I chose not to change it is because my work only moved the UDP length assignment from the drivers to the stack.

The "wrong" checksum value was used regardless of my change,

The wrong checksum was visible only inside the driver, and since the hardware didn't care (due to the offload), it worked well. It was the driver business to make sure the corresponding hardware likes the packet. After commit b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL"), however, the wrong checksum moved one abstraction layer higher - to the networking stack, which attempts to keep the checksum correct for a more generic case. It's not the same, and while I'm trying to fix one occurrence, I'd prefer not to introduce more.

Quoted 16 lines

and I
prefer not to change it as part of this work.

Quoted 12 lines

That said, maybe you can base your patch on top of my checksum fix? For the last packet, it will then be:

if (!skb_is_gso(seg))

        newlen = /* the new value */;

/* keep newlen as is otherwise: my newlen is your msslen */ check = csum16_add(csum16_sub(uh->check, uh->len), newlen); uh->len = newlen;
uh->check = check;

[1]: https://lore.kernel.org/netdev/[email protected]/

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

As I mentioned in the other thread, this fix goes to net, I can't take your patch.

Ah, that's right. Still, I guess you can take mine to net for the checksum fix.

Do you think it is suitable for net?

Quoted 7 lines

This is always a mystery to me... I've had different experiences:
sometimes I am asked to resubmit less important fixes to -next, sometimes a fix is a fix and must go to net. This one is a refactoring useful for my further patches + the checksum fix, which we get for free and which I considered not important enough to submit to net (hardware offload fixes the checksum in most cases anyway). Following the "a fix is a fix" logic, we may try sending it to net. What do you think?

Quoted 4 lines

IMHO, the motivation you provided in your previous message for the checksum fix is convincing, but as I said, I think the commit message should be phrased to explain the bug rather than the refactoring (and add a Fixes tag).

I can put it like this:

udp: gso: Fix handling checksum in __udp_gso_segment

The cited commit started using msslen for uh->len, but still uses newlen to adjust uh->check. Although the checksum is ignored in most cases due to the hardware offload, __udp_gso_segment attempts to maintain the correct one. Fix uh->check and adjust it by the right value.

Additionally, after the fix, newlen becomes assigned and unused before the loop. The code can be simplified a bit if mss adjustment is dropped, so that newlen becomes equal to msslen before the loop, and msslen can be also dropped, saving a few lines of code.

This brings us back to one variable, drops an unneeded arithmetic for mss, and fixes the UDP checksum.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL")
#8 lore raw
Quoted 14 lines · Alice Mikityanska

I can put it like this:

udp: gso: Fix handling checksum in __udp_gso_segment

The cited commit started using msslen for uh->len, but still uses newlen to adjust uh->check. Although the checksum is ignored in most cases due to the hardware offload, __udp_gso_segment attempts to maintain the correct one. Fix uh->check and adjust it by the right value.

Additionally, after the fix, newlen becomes assigned and unused before the loop. The code can be simplified a bit if mss adjustment is dropped, so that newlen becomes equal to msslen before the loop, and msslen can be also dropped, saving a few lines of code.

Quoted 6 lines

This brings us back to one variable, drops an unneeded arithmetic for mss, and fixes the UDP checksum.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL")

Thanks Alice!

I will take this and submit both fixes.