Skip to contentSkip to conversation

rxrpc: Miscellaneous fixes

PATCH Superseded David Howells 4 participants 23 messages Mar 26 – Mar 31

Subsystems (8)

v3 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

David Howells

author maintainer
#0 lore raw

v3 cover rxrpc: Miscellaneous fixes

Here are some fixes for rxrpc:

(1) Fix key quota calculation.

(2) Fix a memory leak.

(3) Fix rxrpc_new_client_call_for_sendmsg() to substitute NULL for an empty key.

Might want to remove this substitution entirely or handle it in rxrpc_init_client_call_security() instead.

(4) Not strictly a fix, but move on_list_rcu() from apparmor to list.h so that (5) can use it as list_empty() is not sufficient. Also add an on_list() function.

(5) Fix deletion of call->link to be RCU safe.

(6) Fix missing bounds checks when parsing RxGK tickets.

(7) Fix use of wrong skbuff to get challenge serial number. Also actually substitute the newer response skbuff and release the older one.

(8) Fix unexpected RACK timer warning to report old mode.

(9) Fix server keyring refcount leak.

(10) Fix call key refcount leak.

(11) Fix the interaction of jumbograms with Tx window space, setting the request-ack flag when the window space is getting low, typically because each jumbogram take a big bite out of the window and fewer UDP packets get traded.

David

The patches can be found here also:

http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=rxrpc-fixes

Changes
=======
ver #3)
- Rename the dwc2's on_list() to dwc2_on_list() to free up the name.
- Added a patch to fix the interaction of jumbograms with window space.

ver #2)
- AI review[1]:
- Added a patch to fix key quota calculation.
- Added a patch to fix a memory leak.
- Added a patch to use NULL instead of an empty key in rxrpc_sengmsg().
- Added a patch to use RCU-safe deletion on call->link.
- Modified the response packet selection patch to select the newer response when there's an older response - and to release the older response skbuff.
- Move on_list_rcu() and add on_list().

Alok Tiwari (2):
rxrpc: Fix use of wrong skb when comparing queued RESP challenge
serial
rxrpc: Fix rack timer warning to report unexpected mode

Anderson Nascimento (2):
rxrpc: Fix keyring reference count leak in rxrpc_setsockopt()
rxrpc: Fix key reference count leak from call->key

David Howells (5):
rxrpc: Fix key quota calculation for multitoken keys
rxrpc: Fix key parsing memleak
rxrpc: Fix anonymous key handling
list: Move on_list_rcu() to list.h and add on_list() also
rxrpc: Fix call removal to use RCU safe deletion

Marc Dionne (1):
rxrpc: Fix to request an ack if window is limited

Oleh Konko (1):
rxrpc: Fix RxGK token loading to check bounds

 drivers/usb/dwc2/gadget.c          |  6 ++---
 include/linux/list.h               | 26 ++++++++++++++++++++
 include/trace/events/rxrpc.h       |  2 ++
 net/rxrpc/af_rxrpc.c               |  2 +-
 net/rxrpc/ar-internal.h            |  2 +-
 net/rxrpc/call_object.c            |  7 +++---
 net/rxrpc/conn_event.c             |  5 ++--
 net/rxrpc/input_rack.c             |  2 +-
 net/rxrpc/key.c                    | 38 +++++++++++++++++-------------
 net/rxrpc/output.c                 |  2 ++
 net/rxrpc/proc.c                   |  5 ++--
 net/rxrpc/sendmsg.c                |  2 +-
 security/apparmor/include/policy.h |  2 --
 13 files changed, 69 insertions(+), 32 deletions(-)
author maintainer
#1 lore raw

PATCH v3 1/11 rxrpc: Fix key quota calculation for multitoken keys

In the rxrpc key preparsing, every token extracted sets the proposed quota value, but for multitoken keys, this will overwrite the previous proposed quota, losing it.

Fix this by adding to the proposed quota instead.

Fixes 8a7a3eb4ddbe ("KEYS: RxRPC: Use key preparsing")
cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/key.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/rxrpc/key.c +4 -3
index 85078114b2dd..af403f0ccab5 100644
@@ -72,7 +72,7 @@ static int rxrpc_preparse_xdr_rxkad(struct key_preparsed_payload *prep,
 		return -EKEYREJECTED;
 
 	plen = sizeof(*token) + sizeof(*token->kad) + tktlen;
-	prep->quotalen = datalen + plen;
+	prep->quotalen += datalen + plen;
 
 	plen -= sizeof(*token);
 	token = kzalloc_obj(*token);
@@ -199,7 +199,7 @@ static int rxrpc_preparse_xdr_yfs_rxgk(struct key_preparsed_payload *prep,
 	}
 
 	plen = sizeof(*token) + sizeof(*token->rxgk) + tktlen + keylen;
-	prep->quotalen = datalen + plen;
+	prep->quotalen += datalen + plen;
 
 	plen -= sizeof(*token);
 	token = kzalloc_obj(*token);
@@ -460,6 +460,7 @@ static int rxrpc_preparse(struct key_preparsed_payload *prep)
 	memcpy(&kver, prep->data, sizeof(kver));
 	prep->data += sizeof(kver);
 	prep->datalen -= sizeof(kver);
+	prep->quotalen = 0;
 
 	_debug("KEY I/F VERSION: %u", kver);
 
@@ -497,7 +498,7 @@ static int rxrpc_preparse(struct key_preparsed_payload *prep)
 		goto error;
 
 	plen = sizeof(*token->kad) + v1->ticket_length;
-	prep->quotalen = plen + sizeof(*token);
+	prep->quotalen += plen + sizeof(*token);
 
 	ret = -ENOMEM;
 	token = kzalloc_obj(*token);
author maintainer
#2 lore raw

PATCH v3 2/11 rxrpc: Fix key parsing memleak

In reply to David Howells

In rxrpc_preparse_xdr_yfs_rxgk(), the memory attached to token->rxgk can be leaked in a few error paths after it's allocated.

Fix this by freeing it in the "reject_token:" case.

Fixes 0ca100ff4df6 ("rxrpc: Add YFS RxGK (GSSAPI) security class")
cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/key.c | 1 +
 1 file changed, 1 insertion(+)
net/rxrpc/key.c +1 -0
index af403f0ccab5..26d4336a4a02 100644
@@ -274,6 +274,7 @@ static int rxrpc_preparse_xdr_yfs_rxgk(struct key_preparsed_payload *prep,
 nomem:
 	return -ENOMEM;
 reject_token:
+	kfree(token->rxgk);
 	kfree(token);
 reject:
 	return -EKEYREJECTED;
author maintainer
#3 lore raw

PATCH v3 3/11 rxrpc: Fix anonymous key handling

In reply to David Howells

In rxrpc_new_client_call_for_sendmsg(), a key with no payload is meant to be substituted for a NULL key pointer, but the variable this is done with is subsequently not used.

Fix this by using "key" rather than "rx->key" when filling in the connection parameters.

Note that this only affects direct use of AF_RXRPC; the kAFS filesystem doesn't use sendmsg() directly and so bypasses the issue. Further, AF_RXRPC passes a NULL key in if no key is set, so using an anonymous key in that manner works. Since this hasn't been noticed to this point, it might be better just to remove the "key" variable and the code that sets it
- and, arguably, rxrpc_init_client_call_security() would be a better place to handle it.

Fixes 19ffa01c9c45 ("rxrpc: Use structs to hold connection params and protocol info")
cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/sendmsg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/sendmsg.c +1 -1
index 04f9c5f2dc24..c35de4fd75e3 100644
@@ -637,7 +637,7 @@ rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg,
 	memset(&cp, 0, sizeof(cp));
 	cp.local		= rx->local;
 	cp.peer			= peer;
-	cp.key			= rx->key;
+	cp.key			= key;
 	cp.security_level	= rx->min_sec_level;
 	cp.exclusive		= rx->exclusive | p->exclusive;
 	cp.upgrade		= p->upgrade;
author maintainer
#4 lore raw

PATCH v3 4/11 list: Move on_list_rcu() to list.h and add on_list() also

In reply to David Howells

Unfortunately, list_empty() is not usable with an entry that has been removed from a list with list_del_rcu() as ->next must be left pointing at the following entry so as not to break traversal under RCU.

Solve this by moving on_list_rcu() from AppArmor to linux/list.h, and turning it into an inline function.

Also add an on_list() counterpart (functionally, this is just an antonym for list_empty()), but the name looks less awkward when applied to a non-head element. We probably don't want to use on_list_rcu() generally because it requires an extra check as ->prev is set differently in the two cases.

Further, rename the on_list() function in the Designware usb2 drd ip driver to dwc2_on_list() to free up the original name.

cc Mathieu Desnoyers <[email protected]>
cc John Johansen <[email protected]>
cc Minas Harutyunyan <[email protected]>
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 drivers/usb/dwc2/gadget.c          |  6 +++---
 include/linux/list.h               | 26 ++++++++++++++++++++++++++
 security/apparmor/include/policy.h |  2 --
 3 files changed, 29 insertions(+), 5 deletions(-)
drivers/usb/dwc2/gadget.c +3 -3
index d216e26c787b..04b6aef8ac13 100644
@@ -4306,11 +4306,11 @@ static int dwc2_hsotg_ep_disable_lock(struct usb_ep *ep)
 }
 
 /**
- * on_list - check request is on the given endpoint
+ * dwc2_on_list - check request is on the given endpoint
  * @ep: The endpoint to check.
  * @test: The request to test if it is on the endpoint.
  */
-static bool on_list(struct dwc2_hsotg_ep *ep, struct dwc2_hsotg_req *test)
+static bool dwc2_on_list(struct dwc2_hsotg_ep *ep, struct dwc2_hsotg_req *test)
 {
 	struct dwc2_hsotg_req *req, *treq;
 
@@ -4338,7 +4338,7 @@ static int dwc2_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
 
 	spin_lock_irqsave(&hs->lock, flags);
 
-	if (!on_list(hs_ep, hs_req)) {
+	if (!dwc2_on_list(hs_ep, hs_req)) {
 		spin_unlock_irqrestore(&hs->lock, flags);
 		return -EINVAL;
 	}
include/linux/list.h +26 -0
index 00ea8e5fb88b..d224e7210d1b 100644
@@ -381,6 +381,32 @@ static inline int list_empty(const struct list_head *head)
 	return READ_ONCE(head->next) == head;
 }
 
+/**
+ * on_list - Test whether an entry is on a list.
+ * @entry: The entry to check
+ *
+ * Test whether an entry is on a list.  Safe to use on an entry initialised
+ * with INIT_LIST_HEAD() or LIST_HEAD() or removed with things like
+ * list_del_init().  Not safe for use with list_del() or list_del_rcu().
+ */
+static inline bool on_list(const struct list_head *entry)
+{
+	return !list_empty(entry);
+}
+
+/**
+ * on_list_rcu - Test whether an entry is on a list (RCU-del safe).
+ * @entry: The entry to check
+ *
+ * Test whether an entry is on a list.  Safe to use on an entry initialised
+ * with INIT_LIST_HEAD() or LIST_HEAD() or removed with things like
+ * list_del_init().  Also safe for use with list_del() or list_del_rcu().
+ */
+static inline bool on_list_rcu(const struct list_head *entry)
+{
+	return !list_empty(entry) && entry->prev != LIST_POISON2;
+}
+
 /**
  * list_del_init_careful - deletes entry from list and reinitialize it.
  * @entry: the element to delete from the list.
security/apparmor/include/policy.h +0 -2
index 3895f8774a3f..c3697c23bbed 100644
@@ -57,8 +57,6 @@ extern const char *const aa_profile_mode_names[];
 
 #define profile_is_stale(_profile) (label_is_stale(&(_profile)->label))
 
-#define on_list_rcu(X) (!list_empty(X) && (X)->prev != LIST_POISON2)
-
 /* flags in the dfa accept2 table */
 enum dfa_accept_flags {
 	ACCEPT_FLAG_OWNER = 1,
maintainer
#5 lore raw

Re: [PATCH net v3 04/11] list: Move on_list_rcu() to list.h and add on_list() also

Quoted 23 lines · On Thu, 26 Mar 2026 13:18:29 +0000 David Howells wrote:
include/linux/list.h +15 -0
index 00ea8e5fb88b..d224e7210d1b 100644
@@ -381,6 +381,32 @@ static inline int list_empty(const struct list_head *head)
 	return READ_ONCE(head->next) == head;
 }
 
+/**
+ * on_list - Test whether an entry is on a list.
+ * @entry: The entry to check
+ *
+ * Test whether an entry is on a list.  Safe to use on an entry initialised
+ * with INIT_LIST_HEAD() or LIST_HEAD() or removed with things like
+ * list_del_init().  Not safe for use with list_del() or list_del_rcu().
+ */
+static inline bool on_list(const struct list_head *entry)
+{
+	return !list_empty(entry);
+}
+
+/**
+ * on_list_rcu - Test whether an entry is on a list (RCU-del safe).

include/linux/list.h static inline int list_empty(const struct list_head *head) · line 408

Quoted 10 lines
include/linux/list.h +10 -0
+ * @entry: The entry to check
+ *
+ * Test whether an entry is on a list.  Safe to use on an entry initialised
+ * with INIT_LIST_HEAD() or LIST_HEAD() or removed with things like
+ * list_del_init().  Also safe for use with list_del() or list_del_rcu().
+ */
+static inline bool on_list_rcu(const struct list_head *entry)
+{
+	return !list_empty(entry) && entry->prev != LIST_POISON2;
+}

Could someone with sufficient weight to their name ack this?

The non-RCU version of on_list() does not sit well with me. It provides no additional semantics above list_empty() and the uninit / poison-related gotchas more obvious when typing !list_empty(&entry->list).

I can believe the RCU version is more useful. It could probably be used on both RCU and non-RCU entries?

Last minor nit - the list API consistently uses list_ as a prefix. I have no better name to suggest but it's sad that on_list_rcu() breaks that.

I think you're missing a READ_ONCE(), BTW.

#6 lore raw

Re: [PATCH net v3 04/11] list: Move on_list_rcu() to list.h and add on_list() also

Quoted 2 lines · Jakub Kicinski

Could someone with sufficient weight to their name ack this?

I don't particularly like it. I think the name is too generic, and it's all wrong anyway. Whether something is on a list or not ends up being much too specific to the use-case, and I do *not* see a huge advantage to a helper function that just wraps "list_empty()" with another name that is actually *less* descriptive.

So no. NAK.

As you mention, the RCU version at least does something else, but honestly, it looks pretty damn questionable too. And no, it does not work for non-RCU lists in any kind of generic sense, since iut's perfectly valid to remove list entries without poisoning them.,

For example, some places that want a simple "am I on a list" will use __list_del_clearprev(), which does *not* poison the prev pointer, but just clears it instead. And then the "am I on a list" is just checking prev for NULL or not.

In other words: all of this is wrong. Whether you are on a list or not is simply not a generic operation. It depends on the user.

The name is also *MUCH* too generic anyway.

Linus

author maintainer
#7 lore raw

Re: [PATCH net v3 04/11] list: Move on_list_rcu() to list.h and add on_list() also

Quoted 2 lines · Linus Torvalds

... and I do *not* see a huge advantage to a helper function that just wraps "list_empty()" with another name that is actually *less* descriptive.

I don't like list_empty() as the name of the function used to find out whether an entry is on a list. Yes, technically, all it's doing is seeing if the list_head is 'empty', but, linguistically, it looks wrong: the question you're asking is not if the list is empty (you're not looking at the list head), but if the entry is on a list.

So if I see in the code:

	if (list_empty(p))

what is the test actually asking?

Note that various other list types in the kernel have separate "is the list empty" and "is the entry on a list" primitives, though, granted, usually because they require separate functions programmatically.

Anyway, I'll find a different way to do this, not involving checking the prev pointer. What I don't want to do is hard code "prev == LIST_POISON2" into my stuff. Anything like that really needs to be in list.h.

David

#8 lore raw

Re: [PATCH net v3 04/11] list: Move on_list_rcu() to list.h and add on_list() also

Quoted 4 lines · David Howells

Anyway, I'll find a different way to do this, not involving checking the prev pointer. What I don't want to do is hard code "prev == LIST_POISON2" into my stuff. Anything like that really needs to be in list.h.

So i think the proper model is:

(a) normal and good list users should never *use* this kind of "is this entry on a list or not".

Dammit, you should *KNOW* that already from core logic. Not with a flag, not with a function to ask, but from how things work. The whole "am I on a list or not" should not be a list issue, it should be obvious.

(b) if the code in question really doesn't know what the ^%&%^ it did, and has lost sight of what it has done to a list entry, and really wants some kind of "did I remove this entry already" logic, I would encourage such uses to either re-consider, or just use the "__list_del_clearprev()" function when removing entries.

Because I really don't want the core list handling to cater to code that doesn't know what the hell it has done.

Linus

author maintainer
#9 lore raw

Re: [PATCH net v3 04/11] list: Move on_list_rcu() to list.h and add on_list() also

Quoted 4 lines · Linus Torvalds

Dammit, you should *KNOW* that already from core logic. Not with a flag, not with a function to ask, but from how things work. The whole "am I on a list or not" should not be a list issue, it should be obvious.

The circumstance in question is this: There's a list of outstanding calls attached to the rxrpc network namespace. Calls may hang around on it beyond the life of the socket that created them for a little bit to deal with network protocol cleanup, timer cleanup, work func cleanup. Under normal operation, calls are removed as the last ref is put.

However, should the namespace be deleted, rxrpc_destroy_all_calls() trawls the list to report any calls that haven't been cleaned up and the calls are deleted from the list as it reports them so that the spinlock doesn't have to be kept held. It used to do other work here too, IIRC, but that's no longer the case, so perhaps this loop is not needed now, and a warning will suffice if the list is not empty (or I could just report, say, the first 10 calls and not worry about calling cond_resched()). The wait at the bottom of the function should be sufficient to hold up namespace deallocation.

If I don't delete entries in rxrpc_destroy_all_calls(), then rxrpc_put_call() only needs list_empty() to guard against the call not having being queued yet. I could have a flag for that, but it would be superfluous.

Note that the reason for the RCU walking is because /proc/net/rxrpc/calls walks over the same list, so I still need the next patch which switches to list_del_rcu().

David

#10 lore raw

Re: [PATCH net v3 04/11] list: Move on_list_rcu() to list.h and add on_list() also

Quoted 4 lines · David Howells

If I don't delete entries in rxrpc_destroy_all_calls(), then rxrpc_put_call() only needs list_empty() to guard against the call not having being queued yet. I could have a flag for that, but it would be superfluous.

So make *that* code use a creaful "delete with flag".

As far as I know, __list_del_clearprev() works fine for RCU walking too, and that "prev is NULL" works as a "this is not on a list".

Admittedly I didn't think about it a lot.

So my point is more that this should not be some "generic list" behavior, and I do *not* want people to think that they can just do "is_on_list()" kind of crap in general.

This should be a "this user needs that particular behavior, and has used this particular function to get it".

And yes, this pattern started out as a single performance-critical networking user, and maybe we could rename and codify this pattern better since we now have a couple of users (bpf and xdp) and another apparently appearing. But I think that "rename and codify" should be a separate thing (and done after ths particular issue is fixed).

Linus

maintainer
#11 lore raw

Re: [PATCH net v3 04/11] list: Move on_list_rcu() to list.h and add on_list() also

In reply to Linus Torvalds
Quoted 8 lines · On Mon, 30 Mar 2026 15:14:07 -0700 Linus Torvalds wrote:
Quoted 4 lines · David Howells

Anyway, I'll find a different way to do this, not involving checking the prev pointer. What I don't want to do is hard code "prev == LIST_POISON2" into my stuff. Anything like that really needs to be in list.h.

So i think the proper model is:

Quoted 7 lines

(a) normal and good list users should never *use* this kind of "is this entry on a list or not".

Dammit, you should *KNOW* that already from core logic. Not with a flag, not with a function to ask, but from how things work. The whole "am I on a list or not" should not be a list issue, it should be obvious.

+1 FWIW, the use of the on_list_rcu() in patch 5 looks kinda shady:

@@ -654,9 +654,9 @@ void rxrpc_put_call(struct rxrpc_call *call, enum rxrpc_call_trace why)
if (dead) {
ASSERTCMP(__rxrpc_call_state(call), ==, RXRPC_CALL_COMPLETE);

- if (!list_empty(&call->link)) {
+ if (on_list_rcu(&call->link)) {
spin_lock(&rxnet->call_lock);
- list_del_init(&call->link);
+ list_del_rcu(&call->link);
spin_unlock(&rxnet->call_lock);
}

I haven't dug around to see if there's some higher level lock protecting the whole op, so I didn't mention it. But I was worried that on_list() would lead to questionable code, and the first use didn't deliver the reassurance I was hoping for.

Quoted 8 lines

(b) if the code in question really doesn't know what the ^%&%^ it did, and has lost sight of what it has done to a list entry, and really wants some kind of "did I remove this entry already" logic, I would encourage such uses to either re-consider, or just use the "__list_del_clearprev()" function when removing entries.

Because I really don't want the core list handling to cater to code that doesn't know what the hell it has done.

maintainer
#12 lore raw

Re: [PATCH net v3 04/11] list: Move on_list_rcu() to list.h and add on_list() also

In reply to David Howells
Quoted 3 lines · On Thu, 26 Mar 2026 13:18:29 +0000 David Howells wrote:

Unfortunately, list_empty() is not usable with an entry that has been removed from a list with list_del_rcu() as ->next must be left pointing at the following entry so as not to break traversal under RCU.

This seems to break build for jffs.
Someone already marked this as rejected in PW.
Whoever it was PLEASE STOP.

Quoting documentation:

Updating patch status
~~~~~~~~~~~~~~~~~~~~~

Contributors and reviewers do not have the permissions to update patch state directly in patchwork. Patchwork doesn't expose much information about the history of the state of patches, therefore having multiple people update the state leads to confusion.

Instead of delegating patchwork permissions netdev uses a simple mail bot which looks for special commands/lines within the emails sent to the mailing list. For example to mark a series as Changes Requested one needs to send the following line anywhere in the email thread::

pw-bot: changes-requested

As a result the bot will set the entire series to Changes Requested. This may be useful when author discovers a bug in their own series and wants to prevent it from getting applied.

The use of the bot is entirely optional, if in doubt ignore its existence completely. Maintainers will classify and update the state of the patches themselves. No email should ever be sent to the list with the main purpose of communicating with the bot, the bot commands should be seen as metadata.
The use of the bot is restricted to authors of the patches (the ``From:`` header on patch submission and command must match!), maintainers of the modified code according to the MAINTAINERS file (again, ``From:`` must match the MAINTAINERS entry) and a handful of senior reviewers.
Bot records its activity here:

https://netdev.bots.linux.dev/pw-bot.html

See:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#updating-patch-status

author maintainer
#13 lore raw

PATCH v3 5/11 rxrpc: Fix call removal to use RCU safe deletion

In reply to David Howells

Fix rxrpc call removal from the rxnet->calls list to use list_del_rcu() rather than list_del_init() to prevent stuffing up reading /proc/net/rxrpc/calls from potentially getting into an infinite loop.

---
 net/rxrpc/call_object.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/rxrpc/call_object.c +3 -3
index 918f41d97a2f..0e47751d5937 100644
@@ -654,9 +654,9 @@ void rxrpc_put_call(struct rxrpc_call *call, enum rxrpc_call_trace why)
 	if (dead) {
 		ASSERTCMP(__rxrpc_call_state(call), ==, RXRPC_CALL_COMPLETE);
 
-		if (!list_empty(&call->link)) {
+		if (on_list_rcu(&call->link)) {
 			spin_lock(&rxnet->call_lock);
-			list_del_init(&call->link);
+			list_del_rcu(&call->link);
 			spin_unlock(&rxnet->call_lock);
 		}
 
@@ -738,7 +738,7 @@ void rxrpc_destroy_all_calls(struct rxrpc_net *rxnet)
 			_debug("Zapping call %p", call);
 
 			rxrpc_see_call(call, rxrpc_call_see_zap);
-			list_del_init(&call->link);
+			list_del_rcu(&call->link);
 
 			pr_err("Call %p still in use (%d,%s,%lx,%lx)!\n",
 			       call, refcount_read(&call->ref),
author maintainer
#14 lore raw

PATCH v3 6/11 rxrpc: Fix RxGK token loading to check bounds

In reply to David Howells

From: Oleh Konko <[email protected]>

rxrpc_preparse_xdr_yfs_rxgk() reads the raw key length and ticket length from the XDR token as u32 values and passes each through round_up(x, 4) before using the rounded value for validation and allocation. When the raw length is >= 0xfffffffd, round_up() wraps to 0, so the bounds check and kzalloc both use 0 while the subsequent memcpy still copies the original ~4 GiB value, producing a heap buffer overflow reachable from an unprivileged add_key() call.

Fix this by:

(1) Rejecting raw key lengths above AFSTOKEN_GK_KEY_MAX and raw ticket lengths above AFSTOKEN_GK_TOKEN_MAX before rounding, consistent with the caps that the RxKAD path already enforces via AFSTOKEN_RK_TIX_MAX.

(2) Sizing the flexible-array allocation from the validated raw key length via struct_size_t() instead of the rounded value.

(3) Caching the raw lengths so that the later field assignments and memcpy calls do not re-read from the token, eliminating a class of TOCTOU re-parse.

The control path (valid token with lengths within bounds) is unaffected.

Fixes 0ca100ff4df6 ("rxrpc: Add YFS RxGK (GSSAPI) security class")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/key.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)
net/rxrpc/key.c +17 -13
index 26d4336a4a02..77237a82be3b 100644
@@ -13,6 +13,7 @@
 #include <crypto/skcipher.h>
 #include <linux/module.h>
 #include <linux/net.h>
+#include <linux/overflow.h>
 #include <linux/skbuff.h>
 #include <linux/key-type.h>
 #include <linux/ctype.h>
@@ -171,7 +172,7 @@ static int rxrpc_preparse_xdr_yfs_rxgk(struct key_preparsed_payload *prep,
 	size_t plen;
 	const __be32 *ticket, *key;
 	s64 tmp;
-	u32 tktlen, keylen;
+	size_t raw_keylen, raw_tktlen, keylen, tktlen;
 
 	_enter(",{%x,%x,%x,%x},%x",
 	       ntohl(xdr[0]), ntohl(xdr[1]), ntohl(xdr[2]), ntohl(xdr[3]),
@@ -181,18 +182,22 @@ static int rxrpc_preparse_xdr_yfs_rxgk(struct key_preparsed_payload *prep,
 		goto reject;
 
 	key = xdr + (6 * 2 + 1);
-	keylen = ntohl(key[-1]);
-	_debug("keylen: %x", keylen);
-	keylen = round_up(keylen, 4);
+	raw_keylen = ntohl(key[-1]);
+	_debug("keylen: %zx", raw_keylen);
+	if (raw_keylen > AFSTOKEN_GK_KEY_MAX)
+		goto reject;
+	keylen = round_up(raw_keylen, 4);
 	if ((6 * 2 + 2) * 4 + keylen > toklen)
 		goto reject;
 
 	ticket = xdr + (6 * 2 + 1 + (keylen / 4) + 1);
-	tktlen = ntohl(ticket[-1]);
-	_debug("tktlen: %x", tktlen);
-	tktlen = round_up(tktlen, 4);
+	raw_tktlen = ntohl(ticket[-1]);
+	_debug("tktlen: %zx", raw_tktlen);
+	if (raw_tktlen > AFSTOKEN_GK_TOKEN_MAX)
+		goto reject;
+	tktlen = round_up(raw_tktlen, 4);
 	if ((6 * 2 + 2) * 4 + keylen + tktlen != toklen) {
-		kleave(" = -EKEYREJECTED [%x!=%x, %x,%x]",
+		kleave(" = -EKEYREJECTED [%zx!=%x, %zx,%zx]",
 		       (6 * 2 + 2) * 4 + keylen + tktlen, toklen,
 		       keylen, tktlen);
 		goto reject;
@@ -206,7 +211,7 @@ static int rxrpc_preparse_xdr_yfs_rxgk(struct key_preparsed_payload *prep,
 	if (!token)
 		goto nomem;
 
-	token->rxgk = kzalloc(sizeof(*token->rxgk) + keylen, GFP_KERNEL);
+	token->rxgk = kzalloc(struct_size_t(struct rxgk_key, _key, raw_keylen), GFP_KERNEL);
 	if (!token->rxgk)
 		goto nomem_token;
 
@@ -221,9 +226,9 @@ static int rxrpc_preparse_xdr_yfs_rxgk(struct key_preparsed_payload *prep,
 	token->rxgk->enctype	= tmp = xdr_dec64(xdr + 5 * 2);
 	if (tmp < 0 || tmp > UINT_MAX)
 		goto reject_token;
-	token->rxgk->key.len	= ntohl(key[-1]);
+	token->rxgk->key.len	= raw_keylen;
 	token->rxgk->key.data	= token->rxgk->_key;
-	token->rxgk->ticket.len = ntohl(ticket[-1]);
+	token->rxgk->ticket.len = raw_tktlen;
 
 	if (token->rxgk->endtime != 0) {
 		expiry = rxrpc_s64_to_time64(token->rxgk->endtime);
@@ -236,8 +241,7 @@ static int rxrpc_preparse_xdr_yfs_rxgk(struct key_preparsed_payload *prep,
 	memcpy(token->rxgk->key.data, key, token->rxgk->key.len);
 
 	/* Pad the ticket so that we can use it directly in XDR */
-	token->rxgk->ticket.data = kzalloc(round_up(token->rxgk->ticket.len, 4),
-					   GFP_KERNEL);
+	token->rxgk->ticket.data = kzalloc(tktlen, GFP_KERNEL);
 	if (!token->rxgk->ticket.data)
 		goto nomem_yrxgk;
 	memcpy(token->rxgk->ticket.data, ticket, token->rxgk->ticket.len);
author maintainer
#15 lore raw

PATCH v3 7/11 rxrpc: Fix use of wrong skb when comparing queued RESP challenge serial

In reply to David Howells

From: Alok Tiwari <[email protected]>

In rxrpc_post_response(), the code should be comparing the challenge serial number from the cached response before deciding to switch to a newer response, but looks at the newer packet private data instead, rendering the comparison always false.

Fix this by switching to look at the older packet.

Fix further[1] to substitute the new packet in place of the old one if newer and also to release whichever we don't use.

Fixes 5800b1cf3fd8 ("rxrpc: Allow CHALLENGEs to the passed to the app for a RESPONSE")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 include/trace/events/rxrpc.h | 1 +
 net/rxrpc/conn_event.c       | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
include/trace/events/rxrpc.h +1 -0
index 869f97c9bf73..5edad6a624ad 100644
@@ -185,6 +185,7 @@
 	EM(rxrpc_skb_put_input,			"PUT input    ") \
 	EM(rxrpc_skb_put_jumbo_subpacket,	"PUT jumbo-sub") \
 	EM(rxrpc_skb_put_oob,			"PUT oob      ") \
+	EM(rxrpc_skb_put_old_response,		"PUT old-resp ") \
 	EM(rxrpc_skb_put_purge,			"PUT purge    ") \
 	EM(rxrpc_skb_put_purge_oob,		"PUT purge-oob") \
 	EM(rxrpc_skb_put_response,		"PUT response ") \
net/rxrpc/conn_event.c +3 -2
index 98ad9b51ca2c..c50cbfc5a313 100644
@@ -557,11 +557,11 @@ void rxrpc_post_response(struct rxrpc_connection *conn, struct sk_buff *skb)
 	spin_lock_irq(&local->lock);
 	old = conn->tx_response;
 	if (old) {
-		struct rxrpc_skb_priv *osp = rxrpc_skb(skb);
+		struct rxrpc_skb_priv *osp = rxrpc_skb(old);
 
 		/* Always go with the response to the most recent challenge. */
 		if (after(sp->resp.challenge_serial, osp->resp.challenge_serial))
-			conn->tx_response = old;
+			conn->tx_response = skb;
 		else
 			old = skb;
 	} else {
@@ -569,4 +569,5 @@ void rxrpc_post_response(struct rxrpc_connection *conn, struct sk_buff *skb)
 	}
 	spin_unlock_irq(&local->lock);
 	rxrpc_poke_conn(conn, rxrpc_conn_get_poke_response);
+	rxrpc_free_skb(old, rxrpc_skb_put_old_response);
 }
author maintainer
#16 lore raw

PATCH v3 8/11 rxrpc: Fix rack timer warning to report unexpected mode

In reply to David Howells

From: Alok Tiwari <[email protected]>

rxrpc_rack_timer_expired() clears call->rack_timer_mode to OFF before the switch. The default case warning therefore always prints OFF and doesn't identify the unexpected timer mode.

Log the saved mode value instead so the warning reports the actual unexpected rack timer mode.

Fixes 7c482665931b ("rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985]")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
---
 net/rxrpc/input_rack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/input_rack.c +1 -1
index 13c371261e0a..9eb109ffba56 100644
@@ -413,6 +413,6 @@ void rxrpc_rack_timer_expired(struct rxrpc_call *call, ktime_t overran_by)
 		break;
 	//case RXRPC_CALL_RACKTIMER_ZEROWIN:
 	default:
-		pr_warn("Unexpected rack timer %u", call->rack_timer_mode);
+		pr_warn("Unexpected rack timer %u", mode);
 	}
 }
author maintainer
#17 lore raw

PATCH v3 9/11 rxrpc: Fix keyring reference count leak in rxrpc_setsockopt()

In reply to David Howells

From: Anderson Nascimento <[email protected]>

In rxrpc_setsockopt(), the code checks 'rx->key' when handling the RXRPC_SECURITY_KEYRING option. However, this appears to be a logic error. The code should be checking 'rx->securities' to determine if a keyring has already been defined for the socket.

Currently, if a user calls setsockopt(RXRPC_SECURITY_KEYRING) multiple times on the same socket, the check 'if (rx->key)' fails to block subsequent calls because 'rx->key' has not been defined by the function. This results in a reference count leak on the keyring.

This patch changes the check to 'rx->securities' to correctly identify if the socket security keyring has already been configured, returning -EINVAL on subsequent attempts.

Before the patch:

It shows the keyring reference counter elevated.

$ cat /proc/keys | grep AFSkeys1
27aca8ae I--Q--- 24469721 perm 3f010000  1000  1000 keyring   AFSkeys1: empty
$

After the patch:

The keyring reference counter remains stable and subsequent calls return an error:

$ ./poc
setsockopt: Invalid argument
$
Fixes 17926a79320a ("[AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/af_rxrpc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/af_rxrpc.c +1 -1
index 0f90272ac254..0b7ed99a3025 100644
@@ -665,7 +665,7 @@ static int rxrpc_setsockopt(struct socket *sock, int level, int optname,
 
 		case RXRPC_SECURITY_KEYRING:
 			ret = -EINVAL;
-			if (rx->key)
+			if (rx->securities)
 				goto error;
 			ret = -EISCONN;
 			if (rx->sk.sk_state != RXRPC_UNBOUND)
#18 lore raw

Re: [PATCH net v3 09/11] rxrpc: Fix keyring reference count leak in rxrpc_setsockopt()

Quoted 57 lines · David Howells

From: Anderson Nascimento <[email protected]>

In rxrpc_setsockopt(), the code checks 'rx->key' when handling the RXRPC_SECURITY_KEYRING option. However, this appears to be a logic error. The code should be checking 'rx->securities' to determine if a keyring has already been defined for the socket.

Currently, if a user calls setsockopt(RXRPC_SECURITY_KEYRING) multiple times on the same socket, the check 'if (rx->key)' fails to block subsequent calls because 'rx->key' has not been defined by the function. This results in a reference count leak on the keyring.

This patch changes the check to 'rx->securities' to correctly identify if the socket security keyring has already been configured, returning -EINVAL on subsequent attempts.

Before the patch:

It shows the keyring reference counter elevated.

$ cat /proc/keys | grep AFSkeys1
27aca8ae I--Q--- 24469721 perm 3f010000  1000  1000 keyring   AFSkeys1: empty
$

After the patch:

The keyring reference counter remains stable and subsequent calls return an error:

$ ./poc
setsockopt: Invalid argument
$
Fixes 17926a79320a ("[AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/af_rxrpc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/af_rxrpc.c +0 -0
index 0f90272ac254..0b7ed99a3025 100644

net/rxrpc/af_rxrpc.c static int rxrpc_setsockopt(struct socket *sock, int level, int optname, · line 671

Quoted 8 lines
net/rxrpc/af_rxrpc.c +1 -1
@@ -665,7 +665,7 @@ static int rxrpc_setsockopt(struct socket *sock, int level, int optname,
 
                case RXRPC_SECURITY_KEYRING:
                        ret = -EINVAL;
-                       if (rx->key)
+                       if (rx->securities)
                                goto error;
                        ret = -EISCONN;
                        if (rx->sk.sk_state != RXRPC_UNBOUND)

I am following this patchset along with sashiko's comments. This time, it flagged this patch for an API order dependency. The setsockopt RXRPC_SECURITY_KEY option checks for rx->securities before proceeding, but after this change, the RXRPC_SECURITY_KEYRING option doesn't check for rx->key. Consequently, it's possible to set both keys on a socket depending on the setsockopt call order.

I noticed this and wondered about it before sending the patch, but I decided to keep the patch as concise as possible rather than assuming too much and potentially breaking code. To make the logic more coherent, what if we check if (rx->key || rx->securities) in both options and remove the rx->securities check from rxrpc_request_key()?

Based on my check, rxrpc_request_key() and rxrpc_server_keyring() are only called by their setsockopt options. We could also add a comment to rxrpc_request_key() and rxrpc_server_keyring() noting that key validation should be handled by the caller. Is the -EINVAL error appropriate for this case?

Signature · 3 lines
Anderson Nascimento
Allele Security Intelligence
https://www.allelesecurity.com
author maintainer
#19 lore raw

Re: [PATCH net v3 09/11] rxrpc: Fix keyring reference count leak in rxrpc_setsockopt()

Quoted 3 lines · Anderson Nascimento

To make the logic more coherent, what if we check if (rx->key || rx->securities) in both options and remove the rx->securities check from rxrpc_request_key()?

You're allowed to have both a keyring (server) and a key (client). You can issue client calls on a server socket. The in-kernel kafs filesystem does this, for example - though it normally sets the outgoing key on individual calls.

To parallel the kernel example, it might be worth my while adding a CMSG tag to take a key ID or key description so the rxrpc_sendmsg() can do a request_key() when setting up a call (the AF_RXRPC socket allows a different key with each call dispatched), though the AFS command line tools tend only to talk to a single cell at a time (you only need one key for comms with an entire cell).

Davod

#20 lore raw

Re: [PATCH net v3 09/11] rxrpc: Fix keyring reference count leak in rxrpc_setsockopt()

Quoted 12 lines · David Howells
Quoted 3 lines · Anderson Nascimento

To make the logic more coherent, what if we check if (rx->key || rx->securities) in both options and remove the rx->securities check from rxrpc_request_key()?

You're allowed to have both a keyring (server) and a key (client). You can issue client calls on a server socket. The in-kernel kafs filesystem does this, for example - though it normally sets the outgoing key on individual calls.

Understood, thanks.

Quoted 9 lines

To parallel the kernel example, it might be worth my while adding a CMSG tag to take a key ID or key description so the rxrpc_sendmsg() can do a request_key() when setting up a call (the AF_RXRPC socket allows a different key with each call dispatched), though the AFS command line tools tend only to talk to a single cell at a time (you only need one key for comms with an entire cell).

Davod

Signature · 3 lines
Anderson Nascimento
Allele Security Intelligence
https://www.allelesecurity.com
author maintainer
#21 lore raw

PATCH v3 10/11 rxrpc: Fix key reference count leak from call->key

In reply to David Howells

From: Anderson Nascimento <[email protected]>

When creating a client call in rxrpc_alloc_client_call(), the code obtains a reference to the key. This is never cleaned up and gets leaked when the call is destroyed.

Fix this by freeing call->key in rxrpc_destroy_call().

Before the patch, it shows the key reference counter elevated:

$ cat /proc/keys | grep afs@54321
1bffe9cd I--Q--i 8053480 4169w 3b010000  1000  1000 rxrpc     afs@54321: ka
$

After the patch, the invalidated key is removed when the code exits:

$ cat /proc/keys | grep afs@54321
$
Fixes f3441d4125fc ("rxrpc: Copy client call parameters into rxrpc_call earlier")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/call_object.c | 1 +
 1 file changed, 1 insertion(+)
net/rxrpc/call_object.c +1 -0
index 0e47751d5937..57c15aa1e9b5 100644
@@ -694,6 +694,7 @@ static void rxrpc_destroy_call(struct work_struct *work)
 	rxrpc_put_bundle(call->bundle, rxrpc_bundle_put_call);
 	rxrpc_put_peer(call->peer, rxrpc_peer_put_call);
 	rxrpc_put_local(call->local, rxrpc_local_put_call);
+	key_put(call->key);
 	call_rcu(&call->rcu, rxrpc_rcu_free_call);
 }
 
author maintainer
#22 lore raw

PATCH v3 11/11 rxrpc: Fix to request an ack if window is limited

In reply to David Howells

From: Marc Dionne <[email protected]>

Peers may only send immediate acks for every 2 UDP packets received. When sending a jumbogram, it is important to check that there is sufficient window space to send another same sized jumbogram following the current one, and request an ack if there isn't. Failure to do so may cause the call to stall waiting for an ack until the resend timer fires.

Where jumbograms are in use this causes a very significant drop in performance.

Fixes fe24a5494390 ("rxrpc: Send jumbo DATA packets")
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 include/trace/events/rxrpc.h | 1 +
 net/rxrpc/ar-internal.h      | 2 +-
 net/rxrpc/output.c           | 2 ++
 net/rxrpc/proc.c             | 5 +++--
 4 files changed, 7 insertions(+), 3 deletions(-)
include/trace/events/rxrpc.h +1 -0
index 5edad6a624ad..792d0f944fc2 100644
@@ -521,6 +521,7 @@
 #define rxrpc_req_ack_traces \
 	EM(rxrpc_reqack_ack_lost,		"ACK-LOST  ")	\
 	EM(rxrpc_reqack_app_stall,		"APP-STALL ")	\
+	EM(rxrpc_reqack_jumbo_win,		"JUMBO-WIN ")	\
 	EM(rxrpc_reqack_more_rtt,		"MORE-RTT  ")	\
 	EM(rxrpc_reqack_no_srv_last,		"NO-SRVLAST")	\
 	EM(rxrpc_reqack_old_rtt,		"OLD-RTT   ")	\
net/rxrpc/ar-internal.h +1 -1
index 36d6ca0d1089..96ecb83c9071 100644
@@ -117,7 +117,7 @@ struct rxrpc_net {
 	atomic_t		stat_tx_jumbo[10];
 	atomic_t		stat_rx_jumbo[10];
 
-	atomic_t		stat_why_req_ack[8];
+	atomic_t		stat_why_req_ack[9];
 
 	atomic_t		stat_io_loop;
 };
net/rxrpc/output.c +2 -0
index d70db367e358..870e59bf06af 100644
@@ -479,6 +479,8 @@ static size_t rxrpc_prepare_data_subpacket(struct rxrpc_call *call,
 		why = rxrpc_reqack_old_rtt;
 	else if (!last && !after(READ_ONCE(call->send_top), txb->seq))
 		why = rxrpc_reqack_app_stall;
+	else if (call->tx_winsize <= (2 * req->n) || call->cong_cwnd <= (2 * req->n))
+		why = rxrpc_reqack_jumbo_win;
 	else
 		goto dont_set_request_ack;
 
net/rxrpc/proc.c +3 -2
index 59292f7f9205..7755fca5beb8 100644
@@ -518,11 +518,12 @@ int rxrpc_stats_show(struct seq_file *seq, void *v)
 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_IDLE]),
 		   atomic_read(&rxnet->stat_rx_acks[0]));
 	seq_printf(seq,
-		   "Why-Req-A: acklost=%u mrtt=%u ortt=%u stall=%u\n",
+		   "Why-Req-A: acklost=%u mrtt=%u ortt=%u stall=%u jwin=%u\n",
 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_ack_lost]),
 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_more_rtt]),
 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_old_rtt]),
-		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_app_stall]));
+		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_app_stall]),
+		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_jumbo_win]));
 	seq_printf(seq,
 		   "Why-Req-A: nolast=%u retx=%u slows=%u smtxw=%u\n",
 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_no_srv_last]),