Skip to contentSkip to conversation

rxrpc: Also unshare DATA/RESPONSE packets when paged frags are present

PATCH In review Hyunwoo Kim 6 participants 11 messages May 8 – May 11

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

PATCH v3 1/1 rxrpc: Also unshare DATA/RESPONSE packets when paged frags are present

The DATA-packet handler in rxrpc_input_call_event() and the RESPONSE handler in rxrpc_verify_response() copy the skb to a linear one before calling into the security ops only when skb_cloned() is true. An skb that is not cloned but still carries externally-owned paged fragments (e.g. SKBFL_SHARED_FRAG set by splice() into a UDP socket via __ip_append_data, or a chained skb_has_frag_list()) falls through to the in-place decryption path, which binds the frag pages directly into the AEAD/skcipher SGL via skb_to_sgvec().

Extend the gate to also unshare when skb_has_frag_list() or skb_has_shared_frag() is true. This catches the splice-loopback vector and other externally-shared frag sources while preserving the zero-copy fast path for skbs whose frags are kernel-private (e.g. NIC page_pool RX, GRO). The OOM/trace handling already in place is reused.

Fixes d0d5c0cd1e71 ("rxrpc: Use skb_unshare() rather than skb_cow_data()")

---
Changes in v3:
- Use skb_has_frag_list() || skb_has_shared_frag() instead of skb_is_nonlinear()
- v2: https://lore.kernel.org/all/af2F1FU5d4Q_Gn1W@v4bel/
Changes in v2:
- Use skb_is_nonlinear() instead of skb->data_len
- v1: https://lore.kernel.org/all/afKV2zGR6rrelPC7@v4bel/

---
 net/rxrpc/call_event.c | 4 +++-
 net/rxrpc/conn_event.c | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)
net/rxrpc/call_event.c +3 -1
index fdd683261226..2b19b252225e 100644
@@ -334,7 +334,9 @@ bool rxrpc_input_call_event(struct rxrpc_call *call)
 
 			if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA &&
 			    sp->hdr.securityIndex != 0 &&
-			    skb_cloned(skb)) {
+			    (skb_cloned(skb) ||
+			     skb_has_frag_list(skb) ||
+			     skb_has_shared_frag(skb))) {
 				/* Unshare the packet so that it can be
 				 * modified by in-place decryption.
 				 */
net/rxrpc/conn_event.c +2 -1
index a2130d25aaa9..442414d90ba1 100644
@@ -245,7 +245,8 @@ static int rxrpc_verify_response(struct rxrpc_connection *conn,
 {
 	int ret;
 
-	if (skb_cloned(skb)) {
+	if (skb_cloned(skb) || skb_has_frag_list(skb) ||
+	    skb_has_shared_frag(skb)) {
 		/* Copy the packet if shared so that we can do in-place
 		 * decryption.
 		 */
Signature · 1 line
2.43.0
maintainer Acked-by on v3 1/1
#1 lore raw
Quoted 15 lines · Hyunwoo Kim

The DATA-packet handler in rxrpc_input_call_event() and the RESPONSE handler in rxrpc_verify_response() copy the skb to a linear one before calling into the security ops only when skb_cloned() is true. An skb that is not cloned but still carries externally-owned paged fragments (e.g. SKBFL_SHARED_FRAG set by splice() into a UDP socket via __ip_append_data, or a chained skb_has_frag_list()) falls through to the in-place decryption path, which binds the frag pages directly into the AEAD/skcipher SGL via skb_to_sgvec().

Extend the gate to also unshare when skb_has_frag_list() or skb_has_shared_frag() is true. This catches the splice-loopback vector and other externally-shared frag sources while preserving the zero-copy fast path for skbs whose frags are kernel-private (e.g. NIC page_pool RX, GRO). The OOM/trace handling already in place is reused.

Quoted 3 lines
Fixes d0d5c0cd1e71 ("rxrpc: Use skb_unshare() rather than skb_cow_data()")
Reviewed-by on v3 1/1
#2 lore raw
In reply to Hyunwoo Kim
Quoted 9 lines · Hyunwoo Kim

The DATA-packet handler in rxrpc_input_call_event() and the RESPONSE handler in rxrpc_verify_response() copy the skb to a linear one before calling into the security ops only when skb_cloned() is true. An skb that is not cloned but still carries externally-owned paged fragments (e.g. SKBFL_SHARED_FRAG set by splice() into a UDP socket via __ip_append_data, or a chained skb_has_frag_list()) falls through to the in-place decryption path, which binds the frag pages directly into the AEAD/skcipher SGL via skb_to_sgvec().

Quoted 5 lines

Extend the gate to also unshare when skb_has_frag_list() or skb_has_shared_frag() is true. This catches the splice-loopback vector and other externally-shared frag sources while preserving the zero-copy fast path for skbs whose frags are kernel-private (e.g. NIC page_pool RX, GRO). The OOM/trace handling already in place is reused.

To be clear, frag_list is not empty for SKB_GSO_FRAGLIST and the skb will go through the copy path.

It's just tradeoff.

Quoted 8 lines
Fixes d0d5c0cd1e71 ("rxrpc: Use skb_unshare() rather than skb_cow_data()")

---
Changes in v3:
- Use skb_has_frag_list() || skb_has_shared_frag() instead of skb_is_nonlinear()
- v2: https://lore.kernel.org/all/af2F1FU5d4Q_Gn1W@v4bel/

Others lgtm, it makes sense to keep this as the ESP fix, since both patches address your Dirty Frag vulnerability.

#3 lore raw
In reply to Hyunwoo Kim
Quoted 35 lines · Hyunwoo Kim

The DATA-packet handler in rxrpc_input_call_event() and the RESPONSE handler in rxrpc_verify_response() copy the skb to a linear one before calling into the security ops only when skb_cloned() is true. An skb that is not cloned but still carries externally-owned paged fragments (e.g. SKBFL_SHARED_FRAG set by splice() into a UDP socket via __ip_append_data, or a chained skb_has_frag_list()) falls through to the in-place decryption path, which binds the frag pages directly into the AEAD/skcipher SGL via skb_to_sgvec().

Extend the gate to also unshare when skb_has_frag_list() or skb_has_shared_frag() is true. This catches the splice-loopback vector and other externally-shared frag sources while preserving the zero-copy fast path for skbs whose frags are kernel-private (e.g. NIC page_pool RX, GRO). The OOM/trace handling already in place is reused.

Fixes d0d5c0cd1e71 ("rxrpc: Use skb_unshare() rather than skb_cow_data()")

---
Changes in v3:
- Use skb_has_frag_list() || skb_has_shared_frag() instead of skb_is_nonlinear()
- v2: https://lore.kernel.org/all/af2F1FU5d4Q_Gn1W@v4bel/
Changes in v2:
- Use skb_is_nonlinear() instead of skb->data_len
- v1: https://lore.kernel.org/all/afKV2zGR6rrelPC7@v4bel/

---
  net/rxrpc/call_event.c | 4 +++-
  net/rxrpc/conn_event.c | 3 ++-
  2 files changed, 5 insertions(+), 2 deletions(-)
net/rxrpc/call_event.c +0 -0
index fdd683261226..2b19b252225e 100644

net/rxrpc/call_event.c bool rxrpc_input_call_event(struct rxrpc_call *call) · line 342

Quoted 10 lines
net/rxrpc/call_event.c +3 -1
@@ -334,7 +334,9 @@ bool rxrpc_input_call_event(struct rxrpc_call *call)
 
  			if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA &&
  			    sp->hdr.securityIndex != 0 &&
-			    skb_cloned(skb)) {
+			    (skb_cloned(skb) ||
+			     skb_has_frag_list(skb) ||
+			     skb_has_shared_frag(skb))) {
  				/* Unshare the packet so that it can be
  				 * modified by in-place decryption.
  				 */

As pointed out by Jiayuan Chen, "frag_list is not empty for SKB_GSO_FRAGLIST and the skb will go through the copy path."   The copy path calls skb_copy() which returns NULL when SKB_GSO_FRAGLIST is set:

    if (WARN_ON_ONCE(skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST)) return NULL;

which will cause rxrpc_input_call_event() to drop the packet:

     /* OOM - Drop the packet. */ rxrpc_see_skb(skb, rxrpc_skb_see_unshare_nomem);

Is it safe to permit an skb with SKB_GSO_FRAGLIST set to go through the non-copy path or does there needs to be some alternative logic to process the packet.

Quoted 5 lines
net/rxrpc/conn_event.c +0 -0
index a2130d25aaa9..442414d90ba1 100644

net/rxrpc/conn_event.c static int rxrpc_verify_response(struct rxrpc_connection *conn, · line 252

Quoted 9 lines
net/rxrpc/conn_event.c +2 -1
@@ -245,7 +245,8 @@ static int rxrpc_verify_response(struct rxrpc_connection *conn,
  {
  	int ret;
 
-	if (skb_cloned(skb)) {
+	if (skb_cloned(skb) || skb_has_frag_list(skb) ||
+	    skb_has_shared_frag(skb)) {
  		/* Copy the packet if shared so that we can do in-place
  		 * decryption.
  		 */

The copy path in rxrpc_verify_response() also calls sk_copy().

Thank you.

Jeffrey Altman

maintainer
#4 lore raw
In reply to Hyunwoo Kim

net/rxrpc/call_event.c bool rxrpc_input_call_event(struct rxrpc_call *call) · line 339

Quoted 5 lines · On Fri, 8 May 2026 17:53:09 +0900 Hyunwoo Kim wrote:
net/rxrpc/call_event.c +3 -1
 			    sp->hdr.securityIndex != 0 &&
-			    skb_cloned(skb)) {
+			    (skb_cloned(skb) ||
+			     skb_has_frag_list(skb) ||
+			     skb_has_shared_frag(skb))) {

We seem to be getting a lot of fixes for this issue, and this one is incorrect :| Writing to _any_ frags is incorrect. You have to copy if skb is not linear. skb_ensure_writable()

#5 lore raw
Quoted 10 lines · Jakub Kicinski

net/rxrpc/call_event.c bool rxrpc_input_call_event(struct rxrpc_call *call) · line 339

Quoted 5 lines · On Fri, 8 May 2026 17:53:09 +0900 Hyunwoo Kim wrote:
net/rxrpc/call_event.c +3 -1
 			    sp->hdr.securityIndex != 0 &&
-			    skb_cloned(skb)) {
+			    (skb_cloned(skb) ||
+			     skb_has_frag_list(skb) ||
+			     skb_has_shared_frag(skb))) {

We seem to be getting a lot of fixes for this issue, and this one is incorrect :| Writing to _any_ frags is incorrect. You have to copy if skb is not linear. skb_ensure_writable()

I was testing a patch based on skb_ensure_writable() but it seems v3 has just been merged to mainline...

What would be the best way to proceed?

Best regards,
Hyunwoo Kim

maintainer
#6 lore raw
Quoted 12 lines · On Mon, 11 May 2026 01:48:39 +0900 Hyunwoo Kim wrote:
Quoted 10 lines · Jakub Kicinski

net/rxrpc/call_event.c bool rxrpc_input_call_event(struct rxrpc_call *call) · line 339

Quoted 5 lines · On Fri, 8 May 2026 17:53:09 +0900 Hyunwoo Kim wrote:
net/rxrpc/call_event.c +3 -1
 			    sp->hdr.securityIndex != 0 &&
-			    skb_cloned(skb)) {
+			    (skb_cloned(skb) ||
+			     skb_has_frag_list(skb) ||
+			     skb_has_shared_frag(skb))) {  

We seem to be getting a lot of fixes for this issue, and this one is incorrect :| Writing to _any_ frags is incorrect. You have to copy if skb is not linear. skb_ensure_writable()

Quoted 4 lines

I was testing a patch based on skb_ensure_writable() but it seems v3 has just been merged to mainline...

What would be the best way to proceed?

Depends on the tree. Where was it merged?

#7 lore raw
Quoted 13 lines · Jakub Kicinski
Quoted 12 lines · On Mon, 11 May 2026 01:48:39 +0900 Hyunwoo Kim wrote:
Quoted 10 lines · Jakub Kicinski

net/rxrpc/call_event.c bool rxrpc_input_call_event(struct rxrpc_call *call) · line 339

Quoted 5 lines · On Fri, 8 May 2026 17:53:09 +0900 Hyunwoo Kim wrote:

sp->hdr.securityIndex != 0 &&

net/rxrpc/call_event.c +3 -1
-			    skb_cloned(skb)) {
+			    (skb_cloned(skb) ||
+			     skb_has_frag_list(skb) ||
+			     skb_has_shared_frag(skb))) {

We seem to be getting a lot of fixes for this issue, and this one is incorrect :| Writing to _any_ frags is incorrect. You have to copy if skb is not linear. skb_ensure_writable()

Quoted 7 lines
Quoted 4 lines

I was testing a patch based on skb_ensure_writable() but it seems v3 has just been merged to mainline...

What would be the best way to proceed?

Depends on the tree. Where was it merged?

It is already on linus' tree.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=aa54b1d27fe0c2b78e664a34fd0fdf7cd1960d71

#8 lore raw
In reply to Jakub Kicinski
Quoted 13 lines · Jakub Kicinski
Quoted 12 lines · On Mon, 11 May 2026 01:48:39 +0900 Hyunwoo Kim wrote:
Quoted 10 lines · Jakub Kicinski

net/rxrpc/call_event.c bool rxrpc_input_call_event(struct rxrpc_call *call) · line 339

Quoted 5 lines · On Fri, 8 May 2026 17:53:09 +0900 Hyunwoo Kim wrote:
net/rxrpc/call_event.c +3 -1
 			    sp->hdr.securityIndex != 0 &&
-			    skb_cloned(skb)) {
+			    (skb_cloned(skb) ||
+			     skb_has_frag_list(skb) ||
+			     skb_has_shared_frag(skb))) {  

We seem to be getting a lot of fixes for this issue, and this one is incorrect :| Writing to _any_ frags is incorrect. You have to copy if skb is not linear. skb_ensure_writable()

Quoted 6 lines
Quoted 4 lines

I was testing a patch based on skb_ensure_writable() but it seems v3 has just been merged to mainline...

What would be the best way to proceed?

Depends on the tree. Where was it merged?

That's the torvalds tree:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=aa54b1d27fe0c2b78e664a34fd0fdf7cd1960d71

maintainer
#9 lore raw
Quoted 6 lines · On Mon, 11 May 2026 02:05:19 +0900 Hyunwoo Kim wrote:
Quoted 5 lines · Jakub Kicinski
Quoted 4 lines · On Mon, 11 May 2026 01:48:39 +0900 Hyunwoo Kim wrote:

On Sun, May 10, 2026 at 08:45:20AM -0700, Jakub Kicinski wrote:
I was testing a patch based on skb_ensure_writable() but it seems v3 has just been merged to mainline...

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

What would be the best way to proceed?

Depends on the tree. Where was it merged?

That's the torvalds tree:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=aa54b1d27fe0c2b78e664a34fd0fdf7cd1960d71

Send an incremental patch on top of that, pls

#10 lore raw
In reply to Jakub Kicinski
Quoted 9 lines · Jakub Kicinski

net/rxrpc/call_event.c bool rxrpc_input_call_event(struct rxrpc_call *call) · line 339

Quoted 5 lines · On Fri, 8 May 2026 17:53:09 +0900 Hyunwoo Kim wrote:

sp->hdr.securityIndex != 0 &&

net/rxrpc/call_event.c +3 -1
-			    skb_cloned(skb)) {
+			    (skb_cloned(skb) ||
+			     skb_has_frag_list(skb) ||
+			     skb_has_shared_frag(skb))) {

We seem to be getting a lot of fixes for this issue, and this one is incorrect :| Writing to _any_ frags is incorrect. You have to copy if skb is not linear. skb_ensure_writable()

There is a issue Simon pointed [1] that triggered BUG_ON(skb_shared(skb)) which was fixed by commit d0d5c0cd1e71 skb_cow_data -> __pskb_pull_tail -> pskb_expand_head -> BUG_ON(skb_shared(skb))

I think skb_ensure_writable will also trigger such code:
skb_ensure_writable -> pskb_may_pull -> __pskb_pull_tail -> pskb_expand_head -> BUG_ON(skb_shared(skb))

LPE will become panic.

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