rxrpc: Miscellaneous fixes
Subsystems (4)
David Howells
maintainerv4 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) Fix deletion of call->link to be RCU safe.
(5) Fix missing bounds checks when parsing RxGK tickets.
(6) Fix use of wrong skbuff to get challenge serial number. Also actually substitute the newer response skbuff and release the older one.
(7) Fix unexpected RACK timer warning to report old mode.
(8) Fix server keyring refcount leak.
(9) Fix call key refcount leak.
(10) 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.
(11) Don't call rxrpc_put_call() with a NULL pointer.
(12) Reject undecryptable rxkad response tickets by checking result of decryption.
(13) Fix buffer bounds calculation in the RESPONSE authenticator parser.
(14) Fix refcount leak on multiple setting of server keyring.
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 #4)
- Got rid of the on_list()/on_list_rcu() patch.
- Removed the list_del_init from rxrpc_destroy_all_calls().
- Made the list_del_rcu() in rxrpc_put_call() unconditional.
- Added four new patches.
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 (4):
rxrpc: Fix key quota calculation for multitoken keys
rxrpc: Fix key parsing memleak
rxrpc: Fix anonymous key handling
rxrpc: Fix call removal to use RCU safe deletion
Douya Le (1):
rxrpc: Only put the call ref if one was acquired
Keenan Dong (2):
rxrpc: fix RESPONSE authenticator parser OOB read
rxrpc: fix oversized RESPONSE authenticator length check
Luxiao Xu (1):
rxrpc: fix reference count leak in rxrpc_server_keyring()
Marc Dionne (1):
rxrpc: Fix to request an ack if window is limited
Oleh Konko (1):
rxrpc: Fix RxGK token loading to check bounds
Yuqi Xu (1):
rxrpc: reject undecryptable rxkad response tickets
include/trace/events/rxrpc.h | 4 +++- net/rxrpc/af_rxrpc.c | 2 +- net/rxrpc/ar-internal.h | 2 +- net/rxrpc/call_object.c | 25 ++++++++++-------------- net/rxrpc/conn_event.c | 5 +++-- net/rxrpc/input_rack.c | 2 +- net/rxrpc/io_thread.c | 3 ++- net/rxrpc/key.c | 38 +++++++++++++++++++++--------------- net/rxrpc/output.c | 2 ++ net/rxrpc/proc.c | 5 +++-- net/rxrpc/rxgk.c | 5 +++-- net/rxrpc/rxkad.c | 6 +++++- net/rxrpc/sendmsg.c | 2 +- net/rxrpc/server_key.c | 3 +++ 14 files changed, 60 insertions(+), 44 deletions(-)
David Howells
maintainerPATCH v4 1/15 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.
--- net/rxrpc/key.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/rxrpc/key.c +4 -3
@@ -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);
David Howells
maintainerPATCH v4 2/15 rxrpc: Fix key parsing memleak
In reply to David HowellsIn 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.
--- net/rxrpc/key.c | 1 + 1 file changed, 1 insertion(+)
net/rxrpc/key.c +1 -0
@@ -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 ;
David Howells
maintainerPATCH v4 3/15 rxrpc: Fix anonymous key handling
In reply to David HowellsIn 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.
--- net/rxrpc/sendmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/sendmsg.c +1 -1
@@ -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;
David Howells
maintainerPATCH v4 4/15 rxrpc: Fix call removal to use RCU safe deletion
In reply to David HowellsFix 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.
This, however, means that list_empty() no longer works on an entry that's been deleted from the list, making it harder to detect prior deletion. Fix this by:
Firstly, make rxrpc_destroy_all_calls() only dump the first ten calls that are unexpectedly still on the list. Limiting the number of steps means there's no need to call cond_resched() or to remove calls from the list here, thereby eliminating the need for rxrpc_put_call() to check for that.
rxrpc_put_call() can then be fixed to unconditionally delete the call from the list as it is the only place that the deletion occurs.
--- include/trace/events/rxrpc.h | 2 +- net/rxrpc/call_object.c | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-)
include/trace/events/rxrpc.h +1 -1
@@ -347,7 +347,7 @@ EM(rxrpc_call_see_release, "SEE release ") \ EM(rxrpc_call_see_userid_exists, "SEE u-exists") \ EM(rxrpc_call_see_waiting_call, "SEE q-conn ") \ - E_(rxrpc_call_see_zap, "SEE zap ") + E_(rxrpc_call_see_still_live, "SEE !still-l")#define rxrpc_txqueue_traces \ EM(rxrpc_txqueue_await_reply, "AWR") \
net/rxrpc/call_object.c +9 -15
@@ -654,11 +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)) { -spin_lock (&rxnet->call_lock); -list_del_init (&call->link); -spin_unlock (&rxnet->call_lock); - } +spin_lock (&rxnet->call_lock); +list_del_rcu (&call->link); +spin_unlock (&rxnet->call_lock);rxrpc_cleanup_call (call); }
@@ -730,24 +728,20 @@ void rxrpc_destroy_all_calls(struct rxrpc_net *rxnet)_enter ("" );if (!list_empty (&rxnet->calls)) { -spin_lock (&rxnet->call_lock); +int shown =0 ; -while (!list_empty (&rxnet->calls)) { - call =list_entry (rxnet->calls.next, - struct rxrpc_call, link); -_debug ("Zapping call %p" , call); +spin_lock (&rxnet->call_lock); -rxrpc_see_call (call, rxrpc_call_see_zap); -list_del_init (&call->link); +list_for_each_entry (call, &rxnet->calls, link) { +rxrpc_see_call (call, rxrpc_call_see_still_live);pr_err ("Call %p still in use (%d,%s,%lx,%lx)!\n" , call,refcount_read (&call->ref), rxrpc_call_states[__rxrpc_call_state (call)], call->flags, call->events); -spin_unlock (&rxnet->call_lock); -cond_resched (); -spin_lock (&rxnet->call_lock); +if (++shown >=10 ) +break ; }spin_unlock (&rxnet->call_lock);
David Howells
maintainerPATCH v4 5/15 rxrpc: Fix RxGK token loading to check bounds
In reply to David HowellsFrom: 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.
--- net/rxrpc/key.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
net/rxrpc/key.c +17 -13
@@ -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);
David Howells
maintainerPATCH v4 6/15 rxrpc: Fix use of wrong skb when comparing queued RESP challenge serial
In reply to David HowellsFrom: 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.
--- 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
@@ -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
@@ -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); }
David Howells
maintainerPATCH v4 7/15 rxrpc: Fix rack timer warning to report unexpected mode
In reply to David HowellsFrom: 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.
--- net/rxrpc/input_rack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/input_rack.c +1 -1
@@ -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); } }
David Howells
maintainerPATCH v4 8/15 rxrpc: Fix keyring reference count leak in rxrpc_setsockopt()
In reply to David HowellsFrom: 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 $
--- net/rxrpc/af_rxrpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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 )
David Howells
maintainerPATCH v4 9/15 rxrpc: Fix key reference count leak from call->key
In reply to David HowellsFrom: 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 $
--- net/rxrpc/call_object.c | 1 + 1 file changed, 1 insertion(+)
net/rxrpc/call_object.c +1 -0
@@ -692,6 +692,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); }
David Howells
maintainerPATCH v4 10/15 rxrpc: Fix to request an ack if window is limited
In reply to David HowellsFrom: 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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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]),
David Howells
maintainerPATCH v4 11/15 rxrpc: Only put the call ref if one was acquired
In reply to David HowellsFrom: Douya Le <[email protected]>
rxrpc_input_packet_on_conn() can process a to-client packet after the current client call on the channel has already been torn down. In that case chan->call is NULL, rxrpc_try_get_call() returns NULL and there is no reference to drop.
The client-side implicit-end error path does not account for that and unconditionally calls rxrpc_put_call(). This turns a protocol error path into a kernel crash instead of rejecting the packet.
Only drop the call reference if one was actually acquired. Keep the existing protocol error handling unchanged.
--- net/rxrpc/io_thread.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/rxrpc/io_thread.c +2 -1
@@ -419,7 +419,8 @@ static int rxrpc_input_packet_on_conn(struct rxrpc_connection *conn,if (sp->hdr.callNumber > chan->call_id) {if (rxrpc_to_client (sp)) { -rxrpc_put_call (call, rxrpc_call_put_input); +if (call) +rxrpc_put_call (call, rxrpc_call_put_input);return rxrpc_protocol_error (skb, rxrpc_eproto_unexpected_implicit_end); }
David Howells
maintainerPATCH v4 12/15 rxrpc: reject undecryptable rxkad response tickets
In reply to David HowellsFrom: Yuqi Xu <[email protected]>
rxkad_decrypt_ticket() decrypts the RXKAD response ticket and then parses the buffer as plaintext without checking whether crypto_skcipher_decrypt() succeeded.
A malformed RESPONSE can therefore use a non-block-aligned ticket length, make the decrypt operation fail, and still drive the ticket parser with attacker-controlled bytes.
Check the decrypt result and abort the connection with RXKADBADTICKET when ticket decryption fails.
--- net/rxrpc/rxkad.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/rxrpc/rxkad.c +5 -1
@@ -958,6 +958,7 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn,struct in_addr addr;unsigned int life;time64_t issue, now; +int ret;bool little_endian;u8 *p, *q, *name, *end;
@@ -977,8 +978,11 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn,sg_init_one (&sg[0 ], ticket, ticket_len);skcipher_request_set_callback (req,0 ,NULL ,NULL );skcipher_request_set_crypt (req, sg, sg, ticket_len, iv.x); -crypto_skcipher_decrypt (req); + ret =crypto_skcipher_decrypt (req);skcipher_request_free (req); +if (ret <0 ) +return rxrpc_abort_conn (conn, skb,RXKADBADTICKET , -EPROTO , + rxkad_abort_resp_tkt_short); p = ticket; end = p + ticket_len;
David Howells
maintainerPATCH v4 13/15 rxrpc: fix RESPONSE authenticator parser OOB read
In reply to David HowellsFrom: Keenan Dong <[email protected]>
rxgk_verify_authenticator() copies auth_len bytes into a temporary buffer and then passes p + auth_len as the parser limit to rxgk_do_verify_authenticator(). Since p is a __be32 *, that inflates the parser end pointer by a factor of four and lets malformed RESPONSE authenticators read past the kmalloc() buffer.
Decoded from the original latest-net reproduction logs with scripts/decode_stacktrace.sh:
BUG: KASAN: slab-out-of-bounds in rxgk_verify_response()
Call Trace:
dump_stack_lvl() [lib/dump_stack.c:123]
print_report() [mm/kasan/report.c:379 mm/kasan/report.c:482]
kasan_report() [mm/kasan/report.c:597]
rxgk_verify_response()
[net/rxrpc/rxgk.c:1103 net/rxrpc/rxgk.c:1167
net/rxrpc/rxgk.c:1274]
rxrpc_process_connection()
[net/rxrpc/conn_event.c:266 net/rxrpc/conn_event.c:364
net/rxrpc/conn_event.c:386]
process_one_work() [kernel/workqueue.c:3281]
worker_thread()
[kernel/workqueue.c:3353 kernel/workqueue.c:3440]
kthread() [kernel/kthread.c:436]
ret_from_fork() [arch/x86/kernel/process.c:164]
Allocated by task 54:
rxgk_verify_response()
[include/linux/slab.h:954 net/rxrpc/rxgk.c:1155
net/rxrpc/rxgk.c:1274]
rxrpc_process_connection()
[net/rxrpc/conn_event.c:266 net/rxrpc/conn_event.c:364
net/rxrpc/conn_event.c:386]Convert the byte count to __be32 units before constructing the parser limit.
--- net/rxrpc/rxgk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/rxrpc/rxgk.c +2 -1
@@ -1164,7 +1164,8 @@ static int rxgk_verify_authenticator(struct rxrpc_connection *conn, } p = auth; - ret =rxgk_do_verify_authenticator (conn, krb5, skb, p, p + auth_len); + ret =rxgk_do_verify_authenticator (conn, krb5, skb, p, + p + auth_len /sizeof (*p)); error:kfree (auth);return ret;
David Howells
maintainerPATCH v4 14/15 rxrpc: fix oversized RESPONSE authenticator length check
In reply to David HowellsFrom: Keenan Dong <[email protected]>
rxgk_verify_response() decodes auth_len from the packet and is supposed to verify that it fits in the remaining bytes. The existing check is inverted, so oversized RESPONSE authenticators are accepted and passed to rxgk_decrypt_skb(), which can later reach skb_to_sgvec() with an impossible length and hit BUG_ON(len).
Decoded from the original latest-net reproduction logs with scripts/decode_stacktrace.sh:
RIP: __skb_to_sgvec()
[net/core/skbuff.c:5285 (discriminator 1)]
Call Trace:
skb_to_sgvec() [net/core/skbuff.c:5305]
rxgk_decrypt_skb() [net/rxrpc/rxgk_common.h:81]
rxgk_verify_response() [net/rxrpc/rxgk.c:1268]
rxrpc_process_connection()
[net/rxrpc/conn_event.c:266 net/rxrpc/conn_event.c:364
net/rxrpc/conn_event.c:386]
process_one_work() [kernel/workqueue.c:3281]
worker_thread()
[kernel/workqueue.c:3353 kernel/workqueue.c:3440]
kthread() [kernel/kthread.c:436]
ret_from_fork() [arch/x86/kernel/process.c:164]Reject authenticator lengths that exceed the remaining packet payload.
--- net/rxrpc/rxgk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/rxgk.c +1 -1
@@ -1224,7 +1224,7 @@ static int rxgk_verify_response(struct rxrpc_connection *conn, auth_offset = offset; auth_len =ntohl (xauth_len); -if (auth_len < len) +if (auth_len > len) goto short_packet;if (auth_len &3 ) goto inconsistent;
David Howells
maintainerPATCH v4 15/15 rxrpc: fix reference count leak in rxrpc_server_keyring()
In reply to David HowellsFrom: Luxiao Xu <[email protected]>
This patch fixes a reference count leak in rxrpc_server_keyring() by checking if rx->securities is already set.
--- net/rxrpc/server_key.c | 3 +++ 1 file changed, 3 insertions(+)
net/rxrpc/server_key.c +3 -0
@@ -125,6 +125,9 @@ int rxrpc_server_keyring(struct rxrpc_sock *rx, sockptr_t optval, int optlen)_enter ("" ); +if (rx->securities) +return -EEXIST ; +if (optlen <=0 || optlen >PAGE_SIZE -1 )return -EINVAL ;
David Howells
maintainerRe: [PATCH net v4 04/15] rxrpc: Fix call removal to use RCU safe deletion
In reply to David HowellsRe: [PATCH net v4 15/15] rxrpc: fix reference count leak in rxrpc_server_keyring()
In reply to David HowellsQuoted 34 lines · David Howells
From: Luxiao Xu <[email protected]>
This patch fixes a reference count leak in
rxrpc_server_keyring()by checking ifrx->securitiesis already set.Fixes 17926a79320a ("[AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both")Reported-by Yifan Wu <[email protected]>Reported-by Juefei Pu <[email protected]>Co-developed-by Yuan Tan <[email protected]>Signed-off-by Yuan Tan <[email protected]>Suggested-by Xin Liu <[email protected]>Tested-by Ren Wei <[email protected]>Signed-off-by Luxiao Xu <[email protected]>Signed-off-by Ren Wei <[email protected]>Signed-off-by David Howells <[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]>--- net/rxrpc/server_key.c | 3 +++ 1 file changed, 3 insertions(+)net/rxrpc/server_key.c +0
-0
net/rxrpc/server_key.c int rxrpc_server_keyring(struct rxrpc_sock *rx, sockptr_t optval, int optlen) · line 133
Quoted 9 lines
net/rxrpc/server_key.c +3
-0@@ -125,6 +125,9 @@ int rxrpc_server_keyring(struct rxrpc_sock *rx, sockptr_t optval, int optlen)_enter ("" ); +if (rx->securities) +return -EEXIST ; +if (optlen <=0 || optlen >PAGE_SIZE -1 )return -EINVAL ;
Isn't this the same issue addressed by my patch "[PATCH net v4 08/15] rxrpc: Fix keyring reference count leak in rxrpc_setsockopt()"? Just asking to make sure this is intended.
--
Anderson Nascimento
Allele Security Intelligence
https://www.allelesecurity.com
David Howells
maintainerRe: [PATCH net v4 15/15] rxrpc: fix reference count leak in rxrpc_server_keyring()
Quoted 3 lines · Anderson Nascimento
Isn't this the same issue addressed by my patch "[PATCH net v4 08/15] rxrpc:
Fix keyring reference count leak inrxrpc_setsockopt()"? Just asking to make sure this is intended.
Actually, yes. This is a different way to fix the same bug, so I'm happy to drop it from the series in preference to yours.
David
Jakub Kicinski
maintainerRe: [PATCH net v4 15/15] rxrpc: fix reference count leak in rxrpc_server_keyring()
Quoted 8 lines · On Wed, 01 Apr 2026 20:32:36 +0100 David Howells wrote:
Quoted 3 lines · Anderson Nascimento
Isn't this the same issue addressed by my patch "[PATCH net v4 08/15] rxrpc:
Fix keyring reference count leak inrxrpc_setsockopt()"? Just asking to make sure this is intended.Actually, yes. This is a different way to fix the same bug, so I'm happy to drop it from the series in preference to yours.
Would you like me to drop the last patch when applying? And in return maybe you can scan the AI output and tell me if any of it is legit? ;)
David Howells
maintainerRe: [PATCH net v4 15/15] rxrpc: fix reference count leak in rxrpc_server_keyring()
Quoted 4 lines · Jakub Kicinski
And in return maybe you can scan the AI output and tell me if any of it is legit? ;)
PATCH 2
-------
The complaint it makes about overflows in relation to patch 2:
net/rxrpc/key.c:rxrpc_preparse_xdr_yfs_rxgk() {
...
keylen = ntohl(key[-1]);
_debug("keylen: %x", keylen);
keylen = round_up(keylen, 4);
...
tktlen = ntohl(ticket[-1]);
_debug("tktlen: %x", tktlen);
tktlen = round_up(tktlen, 4);
...
}is actually addressed by:
[PATCH net v4 05/15] rxrpc: Fix RxGK token loading to check bounds
I guess it doesn't look forward through the patches?
PATCH 8
-------
In regards to patch 8, it asks:
Does this change introduce an asymmetric behavior between configuring RXRPC_SECURITY_KEY and RXRPC_SECURITY_KEYRING?
Yes, but it's then correct. An AF_RXRPC server socket can also make client calls - and, indeed, the kernel AFS client requires this. The kernel AFS client makes filesystem access/manipulation client calls but also listens for, amongst other things, change notifications from the server.
With regards to its complaint about patch 12, I should really switch to using lib/crypto/ to avoid using any memory allocation, but, yes, it has a point and that crypto_skcipher_decrypt() (and encrypt) can fail too.
"sp->len < 8" is checked for at the beginning of the functions rxkad_verify_packet_2(), so it must be at least one block in size. rxkad uses pcbc to wrap fcrypt which should take care of the non-block alignment.
I'll add a patch to add error handling.
PATCH 13
--------
For patch 13, it says:
Are there integer overflows in rxgk_verify_response() when handling token_len?
Yeah - I do the round up before the check. I'll add a patch to check that the raw token_len <= len too (len must be < 65536 as the response must fit in a single UDP packet).
It also says:
Does rxgk_verify_response() leak the rxgk_context structure (gk)?
Yep. Another patch for that.
And:
Does rxgk_do_verify_authenticator() still perform an out-of-bounds read if the authenticator is smaller than 24 bytes?
Unfortunately, yes. Add one for that.
Further, it says:
Can modifying conn->channels[i].call_counter here cause a data race?
It shouldn't, since the value is only used to allocate the number for a call that is set in callNumber in the Rx header for that call (well, the number may also be copied inside the encrypted payload) but it's only *interpreted* by the peer.
The way Rx works is that there's a separate callNumber space on each channel on each connection. Only one call can be in progress on a given channel (the channel number is in the bottom two bits of the connection ID field), and calls on a channel are numbered consecutively. Seeing a new incoming call with the next higher callNumber implicitly completes and ACKs the previous call on that channel (potentially rendering explicit ACK packets unnecessary on a busy channel).
If, however, a connection becomes idle, the server can just discard its record of it. Should the client resume activity on that connection, the RESPONSE packet conveys the client's call counter for each channel, from which the server reinitialises the counters.
rxrpc_expose_client_call() cranks the counter for the client side; rxgk_do_verify_authenticator() sets the counter for the server side. This sets the expectation in a secure environment of what callNumbers should be next on a connection to help prevent replay attacks.
If the server sees the call ID revert more than 1 (to allow for duplicate packets from the previous call), it should abort the connection.
So I think nothing needs to be fixed here, as a secure connection isn't allowed to proceed until the RESPONSE packet is fully parsed and the transport security set up.
PATCH 14
--------
For patch 14, it says:
While this fixes the panic for auth_len, can a maliciously large token_len (e.g., 0xFFFFFFFF) cause an integer overflow in the same function that leads to the exact same BUG_ON() panic?
but this is the same as the first thing it says against patch 13. I've added a patch to check token_len.
Ditto for:
Does this function also unconditionally leak the rxgk_context allocated for the transport key?
It then says:
Are there memory leaks and data races if duplicate RESPONSE packets are processed concurrently?
That can't happen as there's a single work item, conn->processor, that processes all connection-level events, including CHALLENGE and RESPONSE issuing and parsing for that connection. Each connection has its own totally independent security context, so there shouldn't be interference between two connections.
And finally, it says:
If rxrpc_process_event() does not verify if the connection is already secured before invoking the verify_response() callback, duplicate packets would cause rxgk_verify_response() to unconditionally overwrite conn->key with the new key, leaking the previous key's reference.
Additionally, if rxgk_init_connection_security() unconditionally overwrites conn->rxgk.keys[] without putting the old key or holding conn->security_use_lock, could this cause another rxgk_context leak and race against concurrent read accesses in rxgk_get_key()?
These are both addressed by a patch I've been sent that I'll add.
PATCH 15
--------
Regarding patch 15, which provides an alternative fix to patch 8, I previously asked you to drop patch 15 - but I'm thinking now it's probably better to keep patch 15 and drop patch 8 (and change patch 15 to return -EINVAL).
David
David Howells
maintainerRe: [PATCH net v4 15/15] rxrpc: fix reference count leak in rxrpc_server_keyring()
In reply to Anderson NascimentoQuoted 3 lines · Anderson Nascimento
Isn't this the same issue addressed by my patch "[PATCH net v4 08/15] rxrpc:
Fix keyring reference count leak inrxrpc_setsockopt()"? Just asking to make sure this is intended.
Actually, I think it's probably better to use Luxiao Xu's patch rather than yours as it puts the check down into the function that actually makes the change.
David
David Howells
maintainerRe: [PATCH net v4 15/15] rxrpc: fix reference count leak in rxrpc_server_keyring()
Quoted 9 lines · David Howells
Quoted 3 lines · Anderson Nascimento
Isn't this the same issue addressed by my patch "[PATCH net v4 08/15]
rxrpc: Fix keyring reference count leak inrxrpc_setsockopt()"? Just asking to make sure this is intended.Actually, I think it's probably better to use Luxiao Xu's patch rather than yours as it puts the check down into the function that actually makes the change.
I also then need to remove the rx->key check.
David
Jakub Kicinski
maintainerRe: [PATCH net v4 15/15] rxrpc: fix reference count leak in rxrpc_server_keyring()
In reply to David HowellsQuoted 3 lines · On Wed, 08 Apr 2026 11:49:33 +0100 David Howells wrote:
Regarding patch 15, which provides an alternative fix to patch 8, I previously asked you to drop patch 15 - but I'm thinking now it's probably better to keep patch 15 and drop patch 8 (and change patch 15 to return
-EINVAL).
Should I apply the other 13 patches and let you include whatever is appropriate to replace patches 8 and 15 in the next series?