Skip to content

Commit ff43ae4

Browse files
committed
Merge tag 'rxrpc-fixes-20191220' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
David Howells says: ==================== rxrpc: Fixes Here are a couple of bugfixes plus a patch that makes one of the bugfixes easier: (1) Move the ping and mutex unlock on a new call from rxrpc_input_packet() into rxrpc_new_incoming_call(), which it calls. This means the lock-unlock section is entirely within the latter function. This simplifies patch (2). (2) Don't take the call->user_mutex at all in the softirq path. Mutexes aren't allowed to be taken or released there and a patch was merged that caused a warning to be emitted every time this happened. Looking at the code again, it looks like that taking the mutex isn't actually necessary, as the value of call->state will block access to the call. (3) Fix the incoming call path to check incoming calls earlier to reject calls to RPC services for which we don't have a security key of the appropriate class. This avoids an assertion failure if YFS tries making a secure call to the kafs cache manager RPC service. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 7c3125f + 063c60d commit ff43ae4

7 files changed

Lines changed: 85 additions & 98 deletions

File tree

‎net/rxrpc/ar-internal.h‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ struct rxrpc_skb_priv {
209209
struct rxrpc_security {
210210
const char *name; /* name of this service */
211211
u8 security_index; /* security type provided */
212+
u32 no_key_abort; /* Abort code indicating no key */
212213

213214
/* Initialise a security service */
214215
int (*init)(void);
@@ -977,8 +978,9 @@ static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
977978
struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
978979
struct sk_buff *);
979980
struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
980-
void rxrpc_new_incoming_connection(struct rxrpc_sock *,
981-
struct rxrpc_connection *, struct sk_buff *);
981+
void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *,
982+
const struct rxrpc_security *, struct key *,
983+
struct sk_buff *);
982984
void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
983985

984986
/*
@@ -1103,7 +1105,9 @@ extern const struct rxrpc_security rxkad;
11031105
int __init rxrpc_init_security(void);
11041106
void rxrpc_exit_security(void);
11051107
int rxrpc_init_client_conn_security(struct rxrpc_connection *);
1106-
int rxrpc_init_server_conn_security(struct rxrpc_connection *);
1108+
bool rxrpc_look_up_server_security(struct rxrpc_local *, struct rxrpc_sock *,
1109+
const struct rxrpc_security **, struct key **,
1110+
struct sk_buff *);
11071111

11081112
/*
11091113
* sendmsg.c

‎net/rxrpc/call_accept.c‎

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,22 @@ void rxrpc_discard_prealloc(struct rxrpc_sock *rx)
239239
kfree(b);
240240
}
241241

242+
/*
243+
* Ping the other end to fill our RTT cache and to retrieve the rwind
244+
* and MTU parameters.
245+
*/
246+
static void rxrpc_send_ping(struct rxrpc_call *call, struct sk_buff *skb)
247+
{
248+
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
249+
ktime_t now = skb->tstamp;
250+
251+
if (call->peer->rtt_usage < 3 ||
252+
ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), now))
253+
rxrpc_propose_ACK(call, RXRPC_ACK_PING, sp->hdr.serial,
254+
true, true,
255+
rxrpc_propose_ack_ping_for_params);
256+
}
257+
242258
/*
243259
* Allocate a new incoming call from the prealloc pool, along with a connection
244260
* and a peer as necessary.
@@ -247,6 +263,8 @@ static struct rxrpc_call *rxrpc_alloc_incoming_call(struct rxrpc_sock *rx,
247263
struct rxrpc_local *local,
248264
struct rxrpc_peer *peer,
249265
struct rxrpc_connection *conn,
266+
const struct rxrpc_security *sec,
267+
struct key *key,
250268
struct sk_buff *skb)
251269
{
252270
struct rxrpc_backlog *b = rx->backlog;
@@ -294,7 +312,7 @@ static struct rxrpc_call *rxrpc_alloc_incoming_call(struct rxrpc_sock *rx,
294312
conn->params.local = rxrpc_get_local(local);
295313
conn->params.peer = peer;
296314
rxrpc_see_connection(conn);
297-
rxrpc_new_incoming_connection(rx, conn, skb);
315+
rxrpc_new_incoming_connection(rx, conn, sec, key, skb);
298316
} else {
299317
rxrpc_get_connection(conn);
300318
}
@@ -333,9 +351,11 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
333351
struct sk_buff *skb)
334352
{
335353
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
354+
const struct rxrpc_security *sec = NULL;
336355
struct rxrpc_connection *conn;
337356
struct rxrpc_peer *peer = NULL;
338-
struct rxrpc_call *call;
357+
struct rxrpc_call *call = NULL;
358+
struct key *key = NULL;
339359

340360
_enter("");
341361

@@ -346,9 +366,7 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
346366
sp->hdr.seq, RX_INVALID_OPERATION, ESHUTDOWN);
347367
skb->mark = RXRPC_SKB_MARK_REJECT_ABORT;
348368
skb->priority = RX_INVALID_OPERATION;
349-
_leave(" = NULL [close]");
350-
call = NULL;
351-
goto out;
369+
goto no_call;
352370
}
353371

354372
/* The peer, connection and call may all have sprung into existence due
@@ -358,29 +376,19 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
358376
*/
359377
conn = rxrpc_find_connection_rcu(local, skb, &peer);
360378

361-
call = rxrpc_alloc_incoming_call(rx, local, peer, conn, skb);
379+
if (!conn && !rxrpc_look_up_server_security(local, rx, &sec, &key, skb))
380+
goto no_call;
381+
382+
call = rxrpc_alloc_incoming_call(rx, local, peer, conn, sec, key, skb);
383+
key_put(key);
362384
if (!call) {
363385
skb->mark = RXRPC_SKB_MARK_REJECT_BUSY;
364-
_leave(" = NULL [busy]");
365-
call = NULL;
366-
goto out;
386+
goto no_call;
367387
}
368388

369389
trace_rxrpc_receive(call, rxrpc_receive_incoming,
370390
sp->hdr.serial, sp->hdr.seq);
371391

372-
/* Lock the call to prevent rxrpc_kernel_send/recv_data() and
373-
* sendmsg()/recvmsg() inconveniently stealing the mutex once the
374-
* notification is generated.
375-
*
376-
* The BUG should never happen because the kernel should be well
377-
* behaved enough not to access the call before the first notification
378-
* event and userspace is prevented from doing so until the state is
379-
* appropriate.
380-
*/
381-
if (!mutex_trylock(&call->user_mutex))
382-
BUG();
383-
384392
/* Make the call live. */
385393
rxrpc_incoming_call(rx, call, skb);
386394
conn = call->conn;
@@ -421,6 +429,9 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
421429
BUG();
422430
}
423431
spin_unlock(&conn->state_lock);
432+
spin_unlock(&rx->incoming_lock);
433+
434+
rxrpc_send_ping(call, skb);
424435

425436
if (call->state == RXRPC_CALL_SERVER_ACCEPTING)
426437
rxrpc_notify_socket(call);
@@ -433,9 +444,12 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
433444
rxrpc_put_call(call, rxrpc_call_put);
434445

435446
_leave(" = %p{%d}", call, call->debug_id);
436-
out:
437-
spin_unlock(&rx->incoming_lock);
438447
return call;
448+
449+
no_call:
450+
spin_unlock(&rx->incoming_lock);
451+
_leave(" = NULL [%u]", skb->mark);
452+
return NULL;
439453
}
440454

441455
/*

‎net/rxrpc/conn_event.c‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -376,21 +376,7 @@ static void rxrpc_secure_connection(struct rxrpc_connection *conn)
376376
_enter("{%d}", conn->debug_id);
377377

378378
ASSERT(conn->security_ix != 0);
379-
380-
if (!conn->params.key) {
381-
_debug("set up security");
382-
ret = rxrpc_init_server_conn_security(conn);
383-
switch (ret) {
384-
case 0:
385-
break;
386-
case -ENOENT:
387-
abort_code = RX_CALL_DEAD;
388-
goto abort;
389-
default:
390-
abort_code = RXKADNOAUTH;
391-
goto abort;
392-
}
393-
}
379+
ASSERT(conn->server_key);
394380

395381
if (conn->security->issue_challenge(conn) < 0) {
396382
abort_code = RX_CALL_DEAD;

‎net/rxrpc/conn_service.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *rxn
148148
*/
149149
void rxrpc_new_incoming_connection(struct rxrpc_sock *rx,
150150
struct rxrpc_connection *conn,
151+
const struct rxrpc_security *sec,
152+
struct key *key,
151153
struct sk_buff *skb)
152154
{
153155
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
@@ -160,6 +162,8 @@ void rxrpc_new_incoming_connection(struct rxrpc_sock *rx,
160162
conn->service_id = sp->hdr.serviceId;
161163
conn->security_ix = sp->hdr.securityIndex;
162164
conn->out_clientflag = 0;
165+
conn->security = sec;
166+
conn->server_key = key_get(key);
163167
if (conn->security_ix)
164168
conn->state = RXRPC_CONN_SERVICE_UNSECURED;
165169
else

‎net/rxrpc/input.c‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,6 @@ static void rxrpc_congestion_management(struct rxrpc_call *call,
192192
goto out_no_clear_ca;
193193
}
194194

195-
/*
196-
* Ping the other end to fill our RTT cache and to retrieve the rwind
197-
* and MTU parameters.
198-
*/
199-
static void rxrpc_send_ping(struct rxrpc_call *call, struct sk_buff *skb)
200-
{
201-
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
202-
ktime_t now = skb->tstamp;
203-
204-
if (call->peer->rtt_usage < 3 ||
205-
ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), now))
206-
rxrpc_propose_ACK(call, RXRPC_ACK_PING, sp->hdr.serial,
207-
true, true,
208-
rxrpc_propose_ack_ping_for_params);
209-
}
210-
211195
/*
212196
* Apply a hard ACK by advancing the Tx window.
213197
*/
@@ -1396,8 +1380,6 @@ int rxrpc_input_packet(struct sock *udp_sk, struct sk_buff *skb)
13961380
call = rxrpc_new_incoming_call(local, rx, skb);
13971381
if (!call)
13981382
goto reject_packet;
1399-
rxrpc_send_ping(call, skb);
1400-
mutex_unlock(&call->user_mutex);
14011383
}
14021384

14031385
/* Process a call packet; this either discards or passes on the ref

‎net/rxrpc/rxkad.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,9 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
648648
u32 serial;
649649
int ret;
650650

651-
_enter("{%d,%x}", conn->debug_id, key_serial(conn->params.key));
651+
_enter("{%d,%x}", conn->debug_id, key_serial(conn->server_key));
652652

653-
ret = key_validate(conn->params.key);
653+
ret = key_validate(conn->server_key);
654654
if (ret < 0)
655655
return ret;
656656

@@ -1293,6 +1293,7 @@ static void rxkad_exit(void)
12931293
const struct rxrpc_security rxkad = {
12941294
.name = "rxkad",
12951295
.security_index = RXRPC_SECURITY_RXKAD,
1296+
.no_key_abort = RXKADUNKNOWNKEY,
12961297
.init = rxkad_init,
12971298
.exit = rxkad_exit,
12981299
.init_connection_security = rxkad_init_connection_security,

‎net/rxrpc/security.c‎

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -101,62 +101,58 @@ int rxrpc_init_client_conn_security(struct rxrpc_connection *conn)
101101
}
102102

103103
/*
104-
* initialise the security on a server connection
104+
* Find the security key for a server connection.
105105
*/
106-
int rxrpc_init_server_conn_security(struct rxrpc_connection *conn)
106+
bool rxrpc_look_up_server_security(struct rxrpc_local *local, struct rxrpc_sock *rx,
107+
const struct rxrpc_security **_sec,
108+
struct key **_key,
109+
struct sk_buff *skb)
107110
{
108111
const struct rxrpc_security *sec;
109-
struct rxrpc_local *local = conn->params.local;
110-
struct rxrpc_sock *rx;
111-
struct key *key;
112-
key_ref_t kref;
112+
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
113+
key_ref_t kref = NULL;
113114
char kdesc[5 + 1 + 3 + 1];
114115

115116
_enter("");
116117

117-
sprintf(kdesc, "%u:%u", conn->service_id, conn->security_ix);
118+
sprintf(kdesc, "%u:%u", sp->hdr.serviceId, sp->hdr.securityIndex);
118119

119-
sec = rxrpc_security_lookup(conn->security_ix);
120+
sec = rxrpc_security_lookup(sp->hdr.securityIndex);
120121
if (!sec) {
121-
_leave(" = -ENOKEY [lookup]");
122-
return -ENOKEY;
122+
trace_rxrpc_abort(0, "SVS",
123+
sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
124+
RX_INVALID_OPERATION, EKEYREJECTED);
125+
skb->mark = RXRPC_SKB_MARK_REJECT_ABORT;
126+
skb->priority = RX_INVALID_OPERATION;
127+
return false;
123128
}
124129

125-
/* find the service */
126-
read_lock(&local->services_lock);
127-
rx = rcu_dereference_protected(local->service,
128-
lockdep_is_held(&local->services_lock));
129-
if (rx && (rx->srx.srx_service == conn->service_id ||
130-
rx->second_service == conn->service_id))
131-
goto found_service;
130+
if (sp->hdr.securityIndex == RXRPC_SECURITY_NONE)
131+
goto out;
132132

133-
/* the service appears to have died */
134-
read_unlock(&local->services_lock);
135-
_leave(" = -ENOENT");
136-
return -ENOENT;
137-
138-
found_service:
139133
if (!rx->securities) {
140-
read_unlock(&local->services_lock);
141-
_leave(" = -ENOKEY");
142-
return -ENOKEY;
134+
trace_rxrpc_abort(0, "SVR",
135+
sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
136+
RX_INVALID_OPERATION, EKEYREJECTED);
137+
skb->mark = RXRPC_SKB_MARK_REJECT_ABORT;
138+
skb->priority = RX_INVALID_OPERATION;
139+
return false;
143140
}
144141

145142
/* look through the service's keyring */
146143
kref = keyring_search(make_key_ref(rx->securities, 1UL),
147144
&key_type_rxrpc_s, kdesc, true);
148145
if (IS_ERR(kref)) {
149-
read_unlock(&local->services_lock);
150-
_leave(" = %ld [search]", PTR_ERR(kref));
151-
return PTR_ERR(kref);
146+
trace_rxrpc_abort(0, "SVK",
147+
sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
148+
sec->no_key_abort, EKEYREJECTED);
149+
skb->mark = RXRPC_SKB_MARK_REJECT_ABORT;
150+
skb->priority = sec->no_key_abort;
151+
return false;
152152
}
153153

154-
key = key_ref_to_ptr(kref);
155-
read_unlock(&local->services_lock);
156-
157-
conn->server_key = key;
158-
conn->security = sec;
159-
160-
_leave(" = 0");
161-
return 0;
154+
out:
155+
*_sec = sec;
156+
*_key = key_ref_to_ptr(kref);
157+
return true;
162158
}

0 commit comments

Comments
 (0)