Skip to content

Commit db099c6

Browse files
dhowellsdavem330
authored andcommitted
rxrpc: Fix timeout of a call that hasn't yet been granted a channel
afs_make_call() calls rxrpc_kernel_begin_call() to begin a call (which may get stalled in the background waiting for a connection to become available); it then calls rxrpc_kernel_set_max_life() to set the timeouts - but that starts the call timer so the call timer might then expire before we get a connection assigned - leading to the following oops if the call stalled: BUG: kernel NULL pointer dereference, address: 0000000000000000 ... CPU: 1 PID: 5111 Comm: krxrpcio/0 Not tainted 6.3.0-rc7-build3+ #701 RIP: 0010:rxrpc_alloc_txbuf+0xc0/0x157 ... Call Trace: <TASK> rxrpc_send_ACK+0x50/0x13b rxrpc_input_call_event+0x16a/0x67d rxrpc_io_thread+0x1b6/0x45f ? _raw_spin_unlock_irqrestore+0x1f/0x35 ? rxrpc_input_packet+0x519/0x519 kthread+0xe7/0xef ? kthread_complete_and_exit+0x1b/0x1b ret_from_fork+0x22/0x30 Fix this by noting the timeouts in struct rxrpc_call when the call is created. The timer will be started when the first packet is transmitted. It shouldn't be possible to trigger this directly from userspace through AF_RXRPC as sendmsg() will return EBUSY if the call is in the waiting-for-conn state if it dropped out of the wait due to a signal. Fixes: 9d35d88 ("rxrpc: Move client call connection to the I/O thread") Reported-by: Marc Dionne <[email protected]> Signed-off-by: David Howells <[email protected]> cc: "David S. Miller" <[email protected]> cc: Eric Dumazet <[email protected]> cc: Jakub Kicinski <[email protected]> cc: Paolo Abeni <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected] Signed-off-by: David S. Miller <[email protected]>
1 parent 0eb362d commit db099c6

File tree

8 files changed

+30
-19
lines changed

8 files changed

+30
-19
lines changed

fs/afs/afs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#define AFSPATHMAX 1024 /* Maximum length of a pathname plus NUL */
2020
#define AFSOPAQUEMAX 1024 /* Maximum length of an opaque field */
2121

22-
#define AFS_VL_MAX_LIFESPAN (120 * HZ)
23-
#define AFS_PROBE_MAX_LIFESPAN (30 * HZ)
22+
#define AFS_VL_MAX_LIFESPAN 120
23+
#define AFS_PROBE_MAX_LIFESPAN 30
2424

2525
typedef u64 afs_volid_t;
2626
typedef u64 afs_vnodeid_t;

fs/afs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct afs_call {
128128
spinlock_t state_lock;
129129
int error; /* error code */
130130
u32 abort_code; /* Remote abort ID or 0 */
131-
unsigned int max_lifespan; /* Maximum lifespan to set if not 0 */
131+
unsigned int max_lifespan; /* Maximum lifespan in secs to set if not 0 */
132132
unsigned request_size; /* size of request data */
133133
unsigned reply_max; /* maximum size of reply */
134134
unsigned count2; /* count used in unmarshalling */

fs/afs/rxrpc.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
335335
/* create a call */
336336
rxcall = rxrpc_kernel_begin_call(call->net->socket, srx, call->key,
337337
(unsigned long)call,
338-
tx_total_len, gfp,
338+
tx_total_len,
339+
call->max_lifespan,
340+
gfp,
339341
(call->async ?
340342
afs_wake_up_async_call :
341343
afs_wake_up_call_waiter),
@@ -350,10 +352,6 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
350352
}
351353

352354
call->rxcall = rxcall;
353-
354-
if (call->max_lifespan)
355-
rxrpc_kernel_set_max_life(call->net->socket, rxcall,
356-
call->max_lifespan);
357355
call->issue_time = ktime_get_real();
358356

359357
/* send the request */

include/net/af_rxrpc.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ typedef void (*rxrpc_user_attach_call_t)(struct rxrpc_call *, unsigned long);
4040
void rxrpc_kernel_new_call_notification(struct socket *,
4141
rxrpc_notify_new_call_t,
4242
rxrpc_discard_new_call_t);
43-
struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *,
44-
struct sockaddr_rxrpc *,
45-
struct key *,
46-
unsigned long,
47-
s64,
48-
gfp_t,
49-
rxrpc_notify_rx_t,
50-
bool,
51-
enum rxrpc_interruptibility,
52-
unsigned int);
43+
struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
44+
struct sockaddr_rxrpc *srx,
45+
struct key *key,
46+
unsigned long user_call_ID,
47+
s64 tx_total_len,
48+
u32 hard_timeout,
49+
gfp_t gfp,
50+
rxrpc_notify_rx_t notify_rx,
51+
bool upgrade,
52+
enum rxrpc_interruptibility interruptibility,
53+
unsigned int debug_id);
5354
int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *,
5455
struct msghdr *, size_t,
5556
rxrpc_notify_end_tx_t);

net/rxrpc/af_rxrpc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ static int rxrpc_listen(struct socket *sock, int backlog)
265265
* @key: The security context to use (defaults to socket setting)
266266
* @user_call_ID: The ID to use
267267
* @tx_total_len: Total length of data to transmit during the call (or -1)
268+
* @hard_timeout: The maximum lifespan of the call in sec
268269
* @gfp: The allocation constraints
269270
* @notify_rx: Where to send notifications instead of socket queue
270271
* @upgrade: Request service upgrade for call
@@ -283,6 +284,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
283284
struct key *key,
284285
unsigned long user_call_ID,
285286
s64 tx_total_len,
287+
u32 hard_timeout,
286288
gfp_t gfp,
287289
rxrpc_notify_rx_t notify_rx,
288290
bool upgrade,
@@ -313,6 +315,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
313315
p.tx_total_len = tx_total_len;
314316
p.interruptibility = interruptibility;
315317
p.kernel = true;
318+
p.timeouts.hard = hard_timeout;
316319

317320
memset(&cp, 0, sizeof(cp));
318321
cp.local = rx->local;

net/rxrpc/ar-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ struct rxrpc_call {
616616
unsigned long expect_term_by; /* When we expect call termination by */
617617
u32 next_rx_timo; /* Timeout for next Rx packet (jif) */
618618
u32 next_req_timo; /* Timeout for next Rx request packet (jif) */
619+
u32 hard_timo; /* Maximum lifetime or 0 (jif) */
619620
struct timer_list timer; /* Combined event timer */
620621
struct work_struct destroyer; /* In-process-context destroyer */
621622
rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */

net/rxrpc/call_object.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ static struct rxrpc_call *rxrpc_alloc_client_call(struct rxrpc_sock *rx,
226226
if (cp->exclusive)
227227
__set_bit(RXRPC_CALL_EXCLUSIVE, &call->flags);
228228

229+
if (p->timeouts.normal)
230+
call->next_rx_timo = min(msecs_to_jiffies(p->timeouts.normal), 1UL);
231+
if (p->timeouts.idle)
232+
call->next_req_timo = min(msecs_to_jiffies(p->timeouts.idle), 1UL);
233+
if (p->timeouts.hard)
234+
call->hard_timo = p->timeouts.hard * HZ;
235+
229236
ret = rxrpc_init_client_call_security(call);
230237
if (ret < 0) {
231238
rxrpc_prefail_call(call, RXRPC_CALL_LOCAL_ERROR, ret);
@@ -257,7 +264,7 @@ void rxrpc_start_call_timer(struct rxrpc_call *call)
257264
call->keepalive_at = j;
258265
call->expect_rx_by = j;
259266
call->expect_req_by = j;
260-
call->expect_term_by = j;
267+
call->expect_term_by = j + call->hard_timo;
261268
call->timer.expires = now;
262269
}
263270

net/rxrpc/sendmsg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
651651
if (IS_ERR(call))
652652
return PTR_ERR(call);
653653
/* ... and we have the call lock. */
654+
p.call.nr_timeouts = 0;
654655
ret = 0;
655656
if (rxrpc_call_is_complete(call))
656657
goto out_put_unlock;

0 commit comments

Comments
 (0)