Skip to content

Commit 1363af6

Browse files
dhowellsNipaLocal
authored andcommitted
rxrpc: Fix untrusted unsigned subtract
Fix the following Smatch Smatch static checker warning: net/rxrpc/rxgk_app.c:65 rxgk_yfs_decode_ticket() warn: untrusted unsigned subtract. 'ticket_len - 10 * 4' by prechecking the length of what we're trying to extract in two places in the token and decoding for a response packet. Also use sizeof() on the struct we're extracting rather specifying the size numerically to be consistent with the other related statements. 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-September/010135.html Signed-off-by: David Howells <dhowells@redhat.com> cc: Marc Dionne <marc.dionne@auristor.com> cc: Jakub Kicinski <kuba@kernel.org> cc: "David S. Miller" <davem@davemloft.net> cc: Eric Dumazet <edumazet@google.com> cc: Paolo Abeni <pabeni@redhat.com> cc: Simon Horman <horms@kernel.org> cc: linux-afs@lists.infradead.org cc: netdev@vger.kernel.org Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: NipaLocal <nipa@local>
1 parent 3d275ff commit 1363af6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

net/rxrpc/rxgk_app.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ int rxgk_yfs_decode_ticket(struct rxrpc_connection *conn, struct sk_buff *skb,
5454

5555
_enter("");
5656

57+
if (ticket_len < 10 * sizeof(__be32))
58+
return rxrpc_abort_conn(conn, skb, RXGK_INCONSISTENCY, -EPROTO,
59+
rxgk_abort_resp_short_yfs_tkt);
60+
5761
/* Get the session key length */
5862
ret = skb_copy_bits(skb, ticket_offset, tmp, sizeof(tmp));
5963
if (ret < 0)
@@ -195,22 +199,23 @@ int rxgk_extract_token(struct rxrpc_connection *conn, struct sk_buff *skb,
195199
__be32 token_len;
196200
} container;
197201

202+
if (token_len < sizeof(container))
203+
goto short_packet;
204+
198205
/* Decode the RXGK_TokenContainer object. This tells us which server
199206
* key we should be using. We can then fetch the key, get the secret
200207
* and set up the crypto to extract the token.
201208
*/
202209
if (skb_copy_bits(skb, token_offset, &container, sizeof(container)) < 0)
203-
return rxrpc_abort_conn(conn, skb, RXGK_PACKETSHORT, -EPROTO,
204-
rxgk_abort_resp_tok_short);
210+
goto short_packet;
205211

206212
kvno = ntohl(container.kvno);
207213
enctype = ntohl(container.enctype);
208214
ticket_len = ntohl(container.token_len);
209215
ticket_offset = token_offset + sizeof(container);
210216

211-
if (xdr_round_up(ticket_len) > token_len - 3 * 4)
212-
return rxrpc_abort_conn(conn, skb, RXGK_PACKETSHORT, -EPROTO,
213-
rxgk_abort_resp_tok_short);
217+
if (xdr_round_up(ticket_len) > token_len - sizeof(container))
218+
goto short_packet;
214219

215220
_debug("KVNO %u", kvno);
216221
_debug("ENC %u", enctype);
@@ -285,4 +290,8 @@ int rxgk_extract_token(struct rxrpc_connection *conn, struct sk_buff *skb,
285290
* also come out this way if the ticket decryption fails.
286291
*/
287292
return ret;
293+
294+
short_packet:
295+
return rxrpc_abort_conn(conn, skb, RXGK_PACKETSHORT, -EPROTO,
296+
rxgk_abort_resp_tok_short);
288297
}

0 commit comments

Comments
 (0)