All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v4 0/2] ipv4/ipv6: account for fraggap on paged allocation paths
@ 2026-06-16 13:33 Wongi Lee
  2026-06-16 13:38 ` [PATCH net v4 1/2] ipv4: account for fraggap on the paged allocation path Wongi Lee
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Wongi Lee @ 2026-06-16 13:33 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, asml.silence, dhowells,
	willemb, Jungwoo Lee

Fix fraggap accounting in the paged-allocation paths of IPv4 and IPv6.

The IPv6 patch is the v4 update of the previously posted patch. The IPv4
patch handles the same code pattern (by Ido).

v3->v4
- Remove the MSG_SPLICE_PAGES exception from the IPv6 negative copy check.
- Clarify where the fraggap bytes are copied in the commit messages.
- Add Reviewed-by tags.

v2->v3
- Add the IPv4 counterpart.
- Mention that the IPv6 corruption became triggerable after ce650a166335.
- Remove the stale comments about copy becoming -fraggap when pagedlen > 0.
- Add missing Cc entries.

v1->v2:
- Fix mail format.

v3: https://lore.kernel.org/netdev/aiq3f7UZGFp0F3MV@DESKTOP-19IMU7U.localdomain/
v2: https://lore.kernel.org/netdev/aigx83czv+UJZA0d@DESKTOP-19IMU7U.localdomain/
v1: https://lore.kernel.org/netdev/aibiIYMAwUErTw5U@DESKTOP-19IMU7U.localdomain/

Wongi Lee (2):
  ipv4: account for fraggap on the paged allocation path
  ipv6: account for fraggap on the paged allocation path

 net/ipv4/ip_output.c  | 7 ++-----
 net/ipv6/ip6_output.c | 9 +++------
 2 files changed, 5 insertions(+), 11 deletions(-)

-- 
2.34.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net v4 1/2] ipv4: account for fraggap on the paged allocation path
  2026-06-16 13:33 [PATCH net v4 0/2] ipv4/ipv6: account for fraggap on paged allocation paths Wongi Lee
@ 2026-06-16 13:38 ` Wongi Lee
  2026-06-16 13:46 ` [PATCH net v4 2/2] ipv6: " Wongi Lee
  2026-06-21 22:30 ` [PATCH net v4 0/2] ipv4/ipv6: account for fraggap on paged allocation paths patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Wongi Lee @ 2026-06-16 13:38 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, asml.silence, dhowells,
	willemb, Jungwoo Lee

In __ip_append_data(), when the paged-allocation branch is taken,
alloclen and pagedlen are computed as

	alloclen = fragheaderlen + transhdrlen;
	pagedlen = datalen - transhdrlen;

datalen already includes fraggap, but the fraggap bytes carried over
from the previous skb are copied into the new skb's linear area at
offset transhdrlen by the subsequent skb_copy_and_csum_bits(). The
linear area is therefore undersized by fraggap bytes while pagedlen is
overstated by the same amount.

The non-paged branch sets alloclen to fraglen, which already accounts
for fraggap because datalen does. Bring the paged branch in line by
adding fraggap to alloclen and subtracting it from pagedlen.

After this adjustment, copy no longer collapses to -fraggap on the
paged path, so remove the stale comment describing that old arithmetic.

Fixes: 8eb77cc73977 ("ipv4: avoid partial copy for zc")
Signed-off-by: Jungwoo Lee <jwlee2217@gmail.com>
Signed-off-by: Wongi Lee <qw3rtyp0@gmail.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 net/ipv4/ip_output.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 5bcd73cbdb41..ec790bad1679 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -1117,8 +1117,8 @@ static int __ip_append_data(struct sock *sk,
 				  !(rt->dst.dev->features & NETIF_F_SG)))
 				alloclen = fraglen;
 			else {
-				alloclen = fragheaderlen + transhdrlen;
-				pagedlen = datalen - transhdrlen;
+				alloclen = fragheaderlen + transhdrlen + fraggap;
+				pagedlen = datalen - transhdrlen - fraggap;
 			}
 
 			alloclen += alloc_extra;
@@ -1165,9 +1165,6 @@ static int __ip_append_data(struct sock *sk,
 			}
 
 			copy = datalen - transhdrlen - fraggap - pagedlen;
-			/* [!] NOTE: copy will be negative if pagedlen>0
-			 * because then the equation reduces to -fraggap.
-			 */
 			if (copy > 0 &&
 			    INDIRECT_CALL_1(getfrag, ip_generic_getfrag,
 					    from, data + transhdrlen, offset,
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net v4 2/2] ipv6: account for fraggap on the paged allocation path
  2026-06-16 13:33 [PATCH net v4 0/2] ipv4/ipv6: account for fraggap on paged allocation paths Wongi Lee
  2026-06-16 13:38 ` [PATCH net v4 1/2] ipv4: account for fraggap on the paged allocation path Wongi Lee
@ 2026-06-16 13:46 ` Wongi Lee
  2026-06-21 22:30 ` [PATCH net v4 0/2] ipv4/ipv6: account for fraggap on paged allocation paths patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Wongi Lee @ 2026-06-16 13:46 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, asml.silence, dhowells,
	willemb, Jungwoo Lee

In __ip6_append_data(), when the paged-allocation branch is taken
(MSG_MORE / NETIF_F_SG / large fraglen), alloclen and pagedlen are
computed as

	alloclen = fragheaderlen + transhdrlen;
	pagedlen = datalen - transhdrlen;

datalen already includes fraggap (datalen = length + fraggap). When
fraggap is non-zero, this is not the first skb and transhdrlen is zero.
The fraggap bytes carried over from the previous skb are copied just past
the fragment headers in the new skb's linear area. The linear area is
therefore undersized by fraggap bytes while pagedlen is overstated by the
same amount, and the copy writes past skb->end into the trailing
skb_shared_info.

An unprivileged user can trigger this via a UDPv6 socket using
MSG_MORE together with MSG_SPLICE_PAGES.

The bad accounting was introduced by commit 773ba4fe9104 ("ipv6:
avoid partial copy for zc"). Before commit ce650a166335 ("udp6: Fix
__ip6_append_data()'s handling of MSG_SPLICE_PAGES"), the negative
copy value caused -EINVAL to be returned. That later commit allowed
MSG_SPLICE_PAGES to proceed in this case, making the corruption
triggerable.

The non-paged branch sets alloclen to fraglen, which already accounts
for fraggap because datalen does. Bring the paged branch in line by
adding fraggap to alloclen and subtracting it from pagedlen.

After this adjustment, copy no longer collapses to -fraggap on the
paged path, so remove the stale comment describing that old arithmetic.
Since a negative copy is no longer expected for a valid MSG_SPLICE_PAGES
case, remove the MSG_SPLICE_PAGES exception from the negative copy check.

Fixes: 773ba4fe9104 ("ipv6: avoid partial copy for zc")
Signed-off-by: Jungwoo Lee <jwlee2217@gmail.com>
Signed-off-by: Wongi Lee <qw3rtyp0@gmail.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 net/ipv6/ip6_output.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index c14adcdd4396..13463c95c7a7 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1668,8 +1668,8 @@ static int __ip6_append_data(struct sock *sk,
 				  !(rt->dst.dev->features & NETIF_F_SG)))
 				alloclen = fraglen;
 			else {
-				alloclen = fragheaderlen + transhdrlen;
-				pagedlen = datalen - transhdrlen;
+				alloclen = fragheaderlen + transhdrlen + fraggap;
+				pagedlen = datalen - transhdrlen - fraggap;
 			}
 			alloclen += alloc_extra;
 
@@ -1684,10 +1684,7 @@ static int __ip6_append_data(struct sock *sk,
 			fraglen = datalen + fragheaderlen;
 
 			copy = datalen - transhdrlen - fraggap - pagedlen;
-			/* [!] NOTE: copy may be negative if pagedlen>0
-			 * because then the equation may reduces to -fraggap.
-			 */
-			if (copy < 0 && !(flags & MSG_SPLICE_PAGES)) {
+			if (copy < 0) {
 				err = -EINVAL;
 				goto error;
 			}
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net v4 0/2] ipv4/ipv6: account for fraggap on paged allocation paths
  2026-06-16 13:33 [PATCH net v4 0/2] ipv4/ipv6: account for fraggap on paged allocation paths Wongi Lee
  2026-06-16 13:38 ` [PATCH net v4 1/2] ipv4: account for fraggap on the paged allocation path Wongi Lee
  2026-06-16 13:46 ` [PATCH net v4 2/2] ipv6: " Wongi Lee
@ 2026-06-21 22:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-06-21 22:30 UTC (permalink / raw)
  To: Wongi Lee
  Cc: netdev, dsahern, idosch, davem, edumazet, kuba, pabeni, horms,
	asml.silence, dhowells, willemb, jwlee2217

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 16 Jun 2026 22:33:19 +0900 you wrote:
> Fix fraggap accounting in the paged-allocation paths of IPv4 and IPv6.
> 
> The IPv6 patch is the v4 update of the previously posted patch. The IPv4
> patch handles the same code pattern (by Ido).
> 
> v3->v4
> - Remove the MSG_SPLICE_PAGES exception from the IPv6 negative copy check.
> - Clarify where the fraggap bytes are copied in the commit messages.
> - Add Reviewed-by tags.
> 
> [...]

Here is the summary with links:
  - [net,v4,1/2] ipv4: account for fraggap on the paged allocation path
    https://git.kernel.org/netdev/net/c/eca856950f7c
  - [net,v4,2/2] ipv6: account for fraggap on the paged allocation path
    https://git.kernel.org/netdev/net/c/736b380e28d0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-21 22:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-16 13:33 [PATCH net v4 0/2] ipv4/ipv6: account for fraggap on paged allocation paths Wongi Lee
2026-06-16 13:38 ` [PATCH net v4 1/2] ipv4: account for fraggap on the paged allocation path Wongi Lee
2026-06-16 13:46 ` [PATCH net v4 2/2] ipv6: " Wongi Lee
2026-06-21 22:30 ` [PATCH net v4 0/2] ipv4/ipv6: account for fraggap on paged allocation paths patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.