All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2 0/3] net: don't strip zerocopy frag markers from a forwarded skb
@ 2026-08-16  6:48 Norbert Szetei
  2026-08-16  6:51 ` [PATCH net v2 1/3] openvswitch: only skb_tx_error() a packet we are about to drop Norbert Szetei
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Norbert Szetei @ 2026-08-16  6:48 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Aaron Conole, Eelco Chaudron, Ilya Maximets,
	linux-kernel, dev

queue_userspace_packet() calls skb_tx_error() on the packet skb in its
error path, but it only borrows that skb: on the OVS_ACTION_ATTR_USERSPACE
action path do_execute_actions() ignores output_userspace()'s return value
and keeps forwarding the same skb through the flow's remaining actions.
skb_tx_error() completes the zerocopy uarg and clears SKBFL_ALL_ZEROCOPY,
and with it SKBFL_SHARED_FRAG.

For a MSG_ZEROCOPY skb carrying page-cache frags, SKBFL_SHARED_FRAG is
what makes esp_input() skb_cow_data() instead of taking the in-place AEAD
path. Once it is stripped, a later local ESP delivery decrypts in place
over pages the sender still shares with the page cache.

Patch 1 moves the skb_tx_error() into the one path that does drop the
packet, the "default" arm of ovs_dp_process_packet()'s switch(error).

Patch 2 removes a second such strip, in skb_zerocopy(), which calls
skb_tx_error() on its source when skb_orphan_frags() fails. A copy helper
should not perform a destructive action on its source, and both callers
already report the error on their own drop path. MSG_ZEROCOPY skbs cannot
reach that one -- SKBFL_DONT_ORPHAN makes skb_orphan_frags() return early
-- but producers that do not set that flag, such as af_packet's TX_RING
path, can.

Patch 3 is new in v2. It stops skb_tx_error() from touching skb_shinfo()
state that is shared with clones, so patch 1's new call site cannot reach
a live skb either. For a non-last OVS_ACTION_ATTR_RECIRC action
clone_execute() sends a skb_clone() into ovs_dp_process_packet() while
do_execute_actions() keeps forwarding the original, and skb_clone() does
not privatise the frags for these skbs -- skb_orphan_frags() returns early
on SKBFL_DONT_ORPHAN -- so a flow miss on the clone strips
SKBFL_SHARED_FRAG from the packet still in flight.

As Ilya noted, that makes patch 3 the general fix -- an skb can enter any
skb_tx_error() caller already cloned elsewhere in the stack -- while
patches 1 and 2 keep the callers from acting on an skb they do not own.
Removing skb_tx_error() altogether looks like the right long-term cleanup
and is planned as a net-next follow-up.

v2:
  - new patch 3: skip the shared skb_shinfo() work in skb_tx_error() when
    the skb is cloned, which also covers the OVS_ACTION_ATTR_RECIRC path
    that patch 1 alone leaves open (suggested by Ilya Maximets)
  - patches 1 and 2 unchanged, Reviewed-by from Ilya Maximets picked up
  - v1: https://lore.kernel.org/netdev/8063260C-05C9-4997-B9B6-2135063C4858@doyensec.com/

Norbert Szetei (3):
  openvswitch: only skb_tx_error() a packet we are about to drop
  net: skbuff: don't skb_tx_error() the source skb in skb_zerocopy()
  net: skbuff: don't touch shared zerocopy state in skb_tx_error()

 net/core/skbuff.c          | 10 ++++++----
 net/openvswitch/datapath.c |  3 +--
 2 files changed, 7 insertions(+), 6 deletions(-)

-- 
2.55.0


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

* [PATCH net v2 1/3] openvswitch: only skb_tx_error() a packet we are about to drop
  2026-08-16  6:48 [PATCH net v2 0/3] net: don't strip zerocopy frag markers from a forwarded skb Norbert Szetei
@ 2026-08-16  6:51 ` Norbert Szetei
  2026-08-17 18:30   ` Jongmin Jang
  2026-08-16  6:55 ` [PATCH net v2 2/3] net: skbuff: don't skb_tx_error() the source skb in skb_zerocopy() Norbert Szetei
  2026-08-16  6:57 ` [PATCH net v2 3/3] net: skbuff: don't touch shared zerocopy state in skb_tx_error() Norbert Szetei
  2 siblings, 1 reply; 7+ messages in thread
From: Norbert Szetei @ 2026-08-16  6:51 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Aaron Conole, Eelco Chaudron, Ilya Maximets,
	linux-kernel, dev

queue_userspace_packet() borrows the packet skb -- it only copies it into
a private netlink message (user_skb) and does not own it; on return
do_execute_actions() keeps forwarding it through the flow's remaining
actions. Its error path nevertheless calls skb_tx_error(skb), which via
skb_zcopy_clear() does skb_shinfo(skb)->flags &= ~SKBFL_ALL_ZEROCOPY,
stripping SKBFL_SHARED_FRAG from that live skb (skb_tx_error()'s kerneldoc
says "skb must be freed afterwards").

For a MSG_ZEROCOPY skb carrying page-cache frags, SKBFL_SHARED_FRAG is
what makes esp_input() skb_cow_data() before in-place AEAD; once it is
stripped a later local ESP-in-UDP delivery decrypts in place over pages
the sender does not own -- an unprivileged page-cache write (the
"Fragnesia" primitive).
do_execute_actions() ignores output_userspace()'s return value, so any
action after a failed USERSPACE upcall inherits the stripped skb.

Move the skb_tx_error() to the flow-miss drop path - the "default"
branch of ovs_dp_process_packet()'s switch(error), before kfree_skb().

The call has been here since commit 36d5fe6a0007 ("core, nfqueue,
openvswitch: Orphan frags in skb_zerocopy and handle errors") but was
harmless until esp_input() began relying on SKBFL_SHARED_FRAG to gate
in-place decrypt; only then did stripping it on a still-forwarded skb
become a page-cache write primitive.

Fixes: 36d5fe6a0007 ("core, nfqueue, openvswitch: Orphan frags in skb_zerocopy and handle errors")
Fixes: f4c50a4034e6 ("xfrm: esp: avoid in-place decrypt on shared skb frags")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Norbert Szetei <norbert@doyensec.com>
Reviewed-by: Ilya Maximets <i.maximets@ovn.org>
---
 net/openvswitch/datapath.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index ae69b2cabab9..fff75c3eed11 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -285,6 +285,7 @@ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key)
 			consume_skb(skb);
 			break;
 		default:
+			skb_tx_error(skb);
 			kfree_skb(skb);
 			break;
 		}
@@ -601,8 +602,6 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
 	err = genlmsg_unicast(ovs_dp_get_net(dp), user_skb, upcall_info->portid);
 	user_skb = NULL;
 out:
-	if (err)
-		skb_tx_error(skb);
 	consume_skb(user_skb);
 	consume_skb(nskb);
 
-- 
2.55.0


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

* [PATCH net v2 2/3] net: skbuff: don't skb_tx_error() the source skb in skb_zerocopy()
  2026-08-16  6:48 [PATCH net v2 0/3] net: don't strip zerocopy frag markers from a forwarded skb Norbert Szetei
  2026-08-16  6:51 ` [PATCH net v2 1/3] openvswitch: only skb_tx_error() a packet we are about to drop Norbert Szetei
@ 2026-08-16  6:55 ` Norbert Szetei
  2026-08-16  6:57 ` [PATCH net v2 3/3] net: skbuff: don't touch shared zerocopy state in skb_tx_error() Norbert Szetei
  2 siblings, 0 replies; 7+ messages in thread
From: Norbert Szetei @ 2026-08-16  6:55 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Aaron Conole, Eelco Chaudron, Ilya Maximets,
	linux-kernel, dev

skb_zerocopy() copies frags from @from into @to. On an
skb_orphan_frags() failure it calls skb_tx_error(@from), a destructive
operation on the source skb the copy helper does not own. That completes
@from's zerocopy uarg and clears SKBFL_ALL_ZEROCOPY, including the
SKBFL_SHARED_FRAG page-ownership marker.

Both callers already report the failure on their own drop path.
nfnetlink_queue does it at nla_put_failure, and Open vSwitch does it in
the flow-miss drop arm of ovs_dp_process_packet(), so nothing is lost by
dropping it here.

On Open vSwitch's OVS_ACTION_ATTR_USERSPACE path the skb is not freed on
this error: do_execute_actions() ignores output_userspace()'s return
value and, unless the upcall was the last action, keeps forwarding the
same skb through the flow's remaining actions. The uarg is completed
while that skb is still in flight, telling the producer its buffers are
free, and SKBFL_SHARED_FRAG is cleared on an skb the rest of the stack
still handles. That flag is what makes esp_input() call skb_cow_data()
instead of decrypting in place, so a later local ESP delivery can
decrypt over frags the skb does not own privately.

Leave error reporting to the callers.

Fixes: 36d5fe6a0007 ("core, nfqueue, openvswitch: Orphan frags in skb_zerocopy and handle errors")
Cc: stable@vger.kernel.org
Suggested-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: Norbert Szetei <norbert@doyensec.com>
Reviewed-by: Ilya Maximets <i.maximets@ovn.org>
---
 net/core/skbuff.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index ba3dbac80fb4..db62ed6e04b9 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3907,10 +3907,9 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)
 
 	skb_len_add(to, len + plen);
 
-	if (unlikely(skb_orphan_frags(from, GFP_ATOMIC))) {
-		skb_tx_error(from);
+	if (unlikely(skb_orphan_frags(from, GFP_ATOMIC)))
 		return -ENOMEM;
-	}
+
 	skb_zerocopy_clone(to, from, GFP_ATOMIC);
 
 	for (i = 0; i < skb_shinfo(from)->nr_frags; i++) {
-- 
2.55.0


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

* [PATCH net v2 3/3] net: skbuff: don't touch shared zerocopy state in skb_tx_error()
  2026-08-16  6:48 [PATCH net v2 0/3] net: don't strip zerocopy frag markers from a forwarded skb Norbert Szetei
  2026-08-16  6:51 ` [PATCH net v2 1/3] openvswitch: only skb_tx_error() a packet we are about to drop Norbert Szetei
  2026-08-16  6:55 ` [PATCH net v2 2/3] net: skbuff: don't skb_tx_error() the source skb in skb_zerocopy() Norbert Szetei
@ 2026-08-16  6:57 ` Norbert Szetei
  2026-08-17 16:47   ` Ilya Maximets
  2026-08-17 18:30   ` Jongmin Jang
  2 siblings, 2 replies; 7+ messages in thread
From: Norbert Szetei @ 2026-08-16  6:57 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Aaron Conole, Eelco Chaudron, Ilya Maximets,
	linux-kernel, dev

skb_tx_error() completes the zerocopy uarg and clears
SKBFL_ALL_ZEROCOPY, and skb_zcopy_downgrade_managed() clears
SKBFL_MANAGED_FRAG_REFS. Both live in skb_shinfo(), which every clone
shares, while the caller only owns the reference it is about to drop.
Through a clone it tells the producer its pages are free and drops
SKBFL_SHARED_FRAG for an skb that is still in flight.

Open vSwitch reaches this with a non-last OVS_ACTION_ATTR_RECIRC:
clone_execute() sends a skb_clone() into ovs_dp_process_packet() while
do_execute_actions() keeps forwarding the original, and skb_clone()
does not privatise the frags here -- skb_orphan_frags() returns early
on SKBFL_DONT_ORPHAN. A flow miss on the clone then strips the marker
from the packet still being forwarded, and a later local ESP delivery
decrypts in place over frags it does not own privately.

Skip it for a cloned skb. Nothing is lost: skb_release_data() clears
the zerocopy state once the last reference to the shared data goes.

Fixes: 36d5fe6a0007 ("core, nfqueue, openvswitch: Orphan frags in skb_zerocopy and handle errors")
Fixes: f4c50a4034e6 ("xfrm: esp: avoid in-place decrypt on shared skb frags")
Cc: stable@vger.kernel.org
Suggested-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: Norbert Szetei <norbert@doyensec.com>
---
 net/core/skbuff.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index db62ed6e04b9..04776a112334 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1417,10 +1417,13 @@ EXPORT_SYMBOL(skb_dump);
  *
  *	Report xmit error if a device callback is tracking this skb.
  *	skb must be freed afterwards.
+ *
+ *	Does nothing for a cloned skb: the zerocopy state lives in
+ *	skb_shinfo(), which the clones share.
  */
 void skb_tx_error(struct sk_buff *skb)
 {
-	if (skb) {
+	if (skb && !skb_cloned(skb)) {
 		skb_zcopy_downgrade_managed(skb);
 		skb_zcopy_clear(skb, true);
 	}
-- 
2.55.0


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

* Re: [PATCH net v2 3/3] net: skbuff: don't touch shared zerocopy state in skb_tx_error()
  2026-08-16  6:57 ` [PATCH net v2 3/3] net: skbuff: don't touch shared zerocopy state in skb_tx_error() Norbert Szetei
@ 2026-08-17 16:47   ` Ilya Maximets
  2026-08-17 18:30   ` Jongmin Jang
  1 sibling, 0 replies; 7+ messages in thread
From: Ilya Maximets @ 2026-08-17 16:47 UTC (permalink / raw)
  To: Norbert Szetei, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Aaron Conole, Eelco Chaudron, linux-kernel, dev,
	i.maximets

On 8/16/26 8:57 AM, Norbert Szetei wrote:
> skb_tx_error() completes the zerocopy uarg and clears
> SKBFL_ALL_ZEROCOPY, and skb_zcopy_downgrade_managed() clears
> SKBFL_MANAGED_FRAG_REFS. Both live in skb_shinfo(), which every clone
> shares, while the caller only owns the reference it is about to drop.
> Through a clone it tells the producer its pages are free and drops
> SKBFL_SHARED_FRAG for an skb that is still in flight.
> 
> Open vSwitch reaches this with a non-last OVS_ACTION_ATTR_RECIRC:
> clone_execute() sends a skb_clone() into ovs_dp_process_packet() while
> do_execute_actions() keeps forwarding the original, and skb_clone()
> does not privatise the frags here -- skb_orphan_frags() returns early
> on SKBFL_DONT_ORPHAN. A flow miss on the clone then strips the marker
> from the packet still being forwarded, and a later local ESP delivery
> decrypts in place over frags it does not own privately.
> 
> Skip it for a cloned skb. Nothing is lost: skb_release_data() clears
> the zerocopy state once the last reference to the shared data goes.
> 
> Fixes: 36d5fe6a0007 ("core, nfqueue, openvswitch: Orphan frags in skb_zerocopy and handle errors")

I think, this should be 25121173f7b1 ("skb: api to report errors for zero
copy skbs") instead.

Otherwise, LGTM.

Also, please, add all maintainers as per get_maintainers script into CC
while sending patches (may drop Zoltan though, since his email bounced,
as well as Pravin).

Note: there is a conflict between this set and the
  https://lore.kernel.org/r/20260814191336.187243-1-almasrymina@google.com
But I think, it's better if we apply the tx_error fixes first, as they
need to be backported further.

Best regards, Ilya Maximets.

> Fixes: f4c50a4034e6 ("xfrm: esp: avoid in-place decrypt on shared skb frags")
> Cc: stable@vger.kernel.org
> Suggested-by: Ilya Maximets <i.maximets@ovn.org>
> Signed-off-by: Norbert Szetei <norbert@doyensec.com>
> ---
>  net/core/skbuff.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index db62ed6e04b9..04776a112334 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -1417,10 +1417,13 @@ EXPORT_SYMBOL(skb_dump);
>   *
>   *	Report xmit error if a device callback is tracking this skb.
>   *	skb must be freed afterwards.
> + *
> + *	Does nothing for a cloned skb: the zerocopy state lives in
> + *	skb_shinfo(), which the clones share.
>   */
>  void skb_tx_error(struct sk_buff *skb)
>  {
> -	if (skb) {
> +	if (skb && !skb_cloned(skb)) {
>  		skb_zcopy_downgrade_managed(skb);
>  		skb_zcopy_clear(skb, true);
>  	}


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

* Re: [PATCH net v2 1/3] openvswitch: only skb_tx_error() a packet we are about to drop
  2026-08-16  6:51 ` [PATCH net v2 1/3] openvswitch: only skb_tx_error() a packet we are about to drop Norbert Szetei
@ 2026-08-17 18:30   ` Jongmin Jang
  0 siblings, 0 replies; 7+ messages in thread
From: Jongmin Jang @ 2026-08-17 18:30 UTC (permalink / raw)
  To: Norbert Szetei
  Cc: Jongmin Jang, netdev, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Aaron Conole,
	Eelco Chaudron, Ilya Maximets, linux-kernel, dev

Hi Norbert,

I independently tested this patch as part of the v2 series using a
separate, non-destructive page-cache canary reproducer.

The test exercised a failed nonterminal OVS USERSPACE action followed by
forwarding:

  userspace(pid=1),2

Before the fix, the root-owned read-only page-cache canary changed. With
v2 applied, the canary remained unchanged. No kernel warning, oops, or
panic was observed.

Tested-by: Jongmin Jang <payload.jang@gmail.com>

Best regards,
Jongmin Jang

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

* Re: [PATCH net v2 3/3] net: skbuff: don't touch shared zerocopy state in skb_tx_error()
  2026-08-16  6:57 ` [PATCH net v2 3/3] net: skbuff: don't touch shared zerocopy state in skb_tx_error() Norbert Szetei
  2026-08-17 16:47   ` Ilya Maximets
@ 2026-08-17 18:30   ` Jongmin Jang
  1 sibling, 0 replies; 7+ messages in thread
From: Jongmin Jang @ 2026-08-17 18:30 UTC (permalink / raw)
  To: Norbert Szetei
  Cc: Jongmin Jang, netdev, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Aaron Conole,
	Eelco Chaudron, Ilya Maximets, linux-kernel, dev

Hi Norbert,

I independently tested this patch as part of the v2 series using a
separate, non-destructive page-cache canary reproducer.

The test exercised the cloned OVS path while the original skb continued
through the remaining actions:

  clone(userspace(pid=1)),2

Before the fix, the root-owned read-only page-cache canary changed. With
v2 applied, the canary remained unchanged. No kernel warning, oops, or
panic was observed.

Tested-by: Jongmin Jang <payload.jang@gmail.com>

Best regards,
Jongmin Jang

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

end of thread, other threads:[~2026-08-17 18:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-16  6:48 [PATCH net v2 0/3] net: don't strip zerocopy frag markers from a forwarded skb Norbert Szetei
2026-08-16  6:51 ` [PATCH net v2 1/3] openvswitch: only skb_tx_error() a packet we are about to drop Norbert Szetei
2026-08-17 18:30   ` Jongmin Jang
2026-08-16  6:55 ` [PATCH net v2 2/3] net: skbuff: don't skb_tx_error() the source skb in skb_zerocopy() Norbert Szetei
2026-08-16  6:57 ` [PATCH net v2 3/3] net: skbuff: don't touch shared zerocopy state in skb_tx_error() Norbert Szetei
2026-08-17 16:47   ` Ilya Maximets
2026-08-17 18:30   ` Jongmin Jang

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.