rxrpc: rxgk: round up appdata and authx lengths in rxgk_construct_response()
Subsystems (4)
PATCH v2 1/1 rxrpc: rxgk: round up appdata and authx lengths in rxgk_construct_response()
In rxgk_construct_response(), auth_len is computed using appdata->len instead of xdr_round_up(appdata->len), while rxgk_construct_authenticator() pads appdata to xdr_round_up(appdata->len) bytes and returnssizeof(a) + xdr_round_up(appdata->len) + sizeof(b).
Userspace can supply an unaligned RXRPC_RESP_RXGK_APPDATA control message via sendmsg() -> rxgk_sendmsg_respond_to_challenge(), which copies cmsg->cmsg_len - sizeof(struct cmsghdr) into appdata.len without checking 4-byte alignment. When appdata->len is not a multiple of 4, the allocated scatterlist length (sg_len) is up to 3 bytes too short, causing the profile encryption routine (krb5_aead_encrypt() or rfc8009_encrypt()) to hit WARN_ON(cksum_offset + krb5->cksum_len > sg_len) and return -EFAULT, preventing the RESPONSE packet from being sent (and panicking systems with panic_on_warn).
As defensive hardening, also wrap authx_len in xdr_round_up() when computing the total len to match the subsequent rxgk_pad_out() call, even though all currently supported enctypes already produce a 4-byte aligned authx_len.
Found by manual code inspection (not reproduced at runtime; verified via call-chain analysis from sendmsg() -> rxgk_sendmsg_respond_to_challenge() -> rxgk_construct_response() -> crypto_krb5_encrypt()).
---
Changes in v2:
- Add Fixes: tag and Cc: [email protected].
- Clarify the exact WARN_ON() site (krb5_aead_encrypt() / rfc8009_encrypt()), describe the xdr_round_up(authx_len) hunk as defensive hardening, and note how the issue was discovered.
---
net/rxrpc/rxgk.c +3 -2
@@ -936,11 +936,12 @@ static int rxgk_construct_response(struct rxrpc_connection *conn,if (IS_ERR (gk))return PTR_ERR (gk); - auth_len =20 + (4 + appdata->len) +12 + (1 +4 ) *4 ; + auth_len =20 + (4 +xdr_round_up (appdata->len)) +12 + (1 +4 ) *4 ; authx_len =crypto_krb5_how_much_buffer (gk->krb5,KRB5_ENCRYPT_MODE , auth_len, &auth_offset); len =sizeof (struct rxrpc_wire_header ) + -8 + (4 +xdr_round_up (gk->key->ticket.len)) + (4 + authx_len); +8 + (4 +xdr_round_up (gk->key->ticket.len)) + + (4 +xdr_round_up (authx_len)); response =alloc_skb_with_frags (0 , len,0 , &ret,GFP_NOFS );if (!response)