Skip to content

Commit 64863f4

Browse files
dhowellskuba-moo
authored andcommitted
rxrpc: Fix unhandled errors in rxgk_verify_packet_integrity()
rxgk_verify_packet_integrity() may get more errors than just -EPROTO from rxgk_verify_mic_skb(). Pretty much anything other than -ENOMEM constitutes an unrecoverable error. In the case of -ENOMEM, we can just drop the packet and wait for a retransmission. Similar happens with rxgk_decrypt_skb() and its callers. Fix rxgk_decrypt_skb() or rxgk_verify_mic_skb() to return a greater variety of abort codes and fix their callers to abort the connection on any error apart from -ENOMEM. Also preclear the variables used to hold the abort code returned from rxgk_decrypt_skb() or rxgk_verify_mic_skb() to eliminate uninitialised variable warnings. Fixes: 9d1d2b5 ("rxrpc: rxgk: Implement the yfs-rxgk security class (GSSAPI)") Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lists.infradead.org/pipermail/linux-afs/2025-April/009739.html Closes: https://lists.infradead.org/pipermail/linux-afs/2025-April/009740.html Signed-off-by: David Howells <dhowells@redhat.com> cc: Marc Dionne <marc.dionne@auristor.com> cc: linux-afs@lists.infradead.org Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/2038804.1757631496@warthog.procyon.org.uk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 70d9962 commit 64863f4

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

net/rxrpc/rxgk.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ static int rxgk_verify_packet_integrity(struct rxrpc_call *call,
475475
struct krb5_buffer metadata;
476476
unsigned int offset = sp->offset, len = sp->len;
477477
size_t data_offset = 0, data_len = len;
478-
u32 ac;
478+
u32 ac = 0;
479479
int ret = -ENOMEM;
480480

481481
_enter("");
@@ -499,9 +499,10 @@ static int rxgk_verify_packet_integrity(struct rxrpc_call *call,
499499
ret = rxgk_verify_mic_skb(gk->krb5, gk->rx_Kc, &metadata,
500500
skb, &offset, &len, &ac);
501501
kfree(hdr);
502-
if (ret == -EPROTO) {
503-
rxrpc_abort_eproto(call, skb, ac,
504-
rxgk_abort_1_verify_mic_eproto);
502+
if (ret < 0) {
503+
if (ret != -ENOMEM)
504+
rxrpc_abort_eproto(call, skb, ac,
505+
rxgk_abort_1_verify_mic_eproto);
505506
} else {
506507
sp->offset = offset;
507508
sp->len = len;
@@ -524,15 +525,16 @@ static int rxgk_verify_packet_encrypted(struct rxrpc_call *call,
524525
struct rxgk_header hdr;
525526
unsigned int offset = sp->offset, len = sp->len;
526527
int ret;
527-
u32 ac;
528+
u32 ac = 0;
528529

529530
_enter("");
530531

531532
ret = rxgk_decrypt_skb(gk->krb5, gk->rx_enc, skb, &offset, &len, &ac);
532-
if (ret == -EPROTO)
533-
rxrpc_abort_eproto(call, skb, ac, rxgk_abort_2_decrypt_eproto);
534-
if (ret < 0)
533+
if (ret < 0) {
534+
if (ret != -ENOMEM)
535+
rxrpc_abort_eproto(call, skb, ac, rxgk_abort_2_decrypt_eproto);
535536
goto error;
537+
}
536538

537539
if (len < sizeof(hdr)) {
538540
ret = rxrpc_abort_eproto(call, skb, RXGK_PACKETSHORT,

net/rxrpc/rxgk_app.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int rxgk_extract_token(struct rxrpc_connection *conn, struct sk_buff *skb,
187187
struct key *server_key;
188188
unsigned int ticket_offset, ticket_len;
189189
u32 kvno, enctype;
190-
int ret, ec;
190+
int ret, ec = 0;
191191

192192
struct {
193193
__be32 kvno;
@@ -236,9 +236,11 @@ int rxgk_extract_token(struct rxrpc_connection *conn, struct sk_buff *skb,
236236
&ticket_offset, &ticket_len, &ec);
237237
crypto_free_aead(token_enc);
238238
token_enc = NULL;
239-
if (ret < 0)
240-
return rxrpc_abort_conn(conn, skb, ec, ret,
241-
rxgk_abort_resp_tok_dec);
239+
if (ret < 0) {
240+
if (ret != -ENOMEM)
241+
return rxrpc_abort_conn(conn, skb, ec, ret,
242+
rxgk_abort_resp_tok_dec);
243+
}
242244

243245
ret = conn->security->default_decode_ticket(conn, skb, ticket_offset,
244246
ticket_len, _key);

net/rxrpc/rxgk_common.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,16 @@ int rxgk_decrypt_skb(const struct krb5_enctype *krb5,
8888
*_offset += offset;
8989
*_len = len;
9090
break;
91+
case -EBADMSG: /* Checksum mismatch. */
9192
case -EPROTO:
92-
case -EBADMSG:
9393
*_error_code = RXGK_SEALEDINCON;
9494
break;
95+
case -EMSGSIZE:
96+
*_error_code = RXGK_PACKETSHORT;
97+
break;
98+
case -ENOPKG: /* Would prefer RXGK_BADETYPE, but not available for YFS. */
9599
default:
100+
*_error_code = RXGK_INCONSISTENCY;
96101
break;
97102
}
98103

@@ -127,11 +132,16 @@ int rxgk_verify_mic_skb(const struct krb5_enctype *krb5,
127132
*_offset += offset;
128133
*_len = len;
129134
break;
135+
case -EBADMSG: /* Checksum mismatch */
130136
case -EPROTO:
131-
case -EBADMSG:
132137
*_error_code = RXGK_SEALEDINCON;
133138
break;
139+
case -EMSGSIZE:
140+
*_error_code = RXGK_PACKETSHORT;
141+
break;
142+
case -ENOPKG: /* Would prefer RXGK_BADETYPE, but not available for YFS. */
134143
default:
144+
*_error_code = RXGK_INCONSISTENCY;
135145
break;
136146
}
137147

0 commit comments

Comments
 (0)