Skip to contentSkip to conversation

rxrpc: rxgk: round up appdata and authx lengths in rxgk_construct_response()

PATCH Superseded Bilal Hashim 3 participants 3 messages Nov 27 – Nov 28

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rxrpc: rxgk: round up appdata and authx lengths in rxgk_construct_response()

In rxgk_construct_response(), the buffer length calculation forgets to round up both appdata->len and authx_len to 4-byte XDR boundaries:

1. 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 returns sizeof(a) + xdr_round_up(appdata->len) + sizeof(b). When userspace supplies a non-4-byte-aligned RXRPC_RESP_RXGK_APPDATA control message, the allocated authenticator buffer is up to 3 bytes too short, causing skb_store_bits() / crypto_krb5_encrypt() to fail or hit WARN_ON() in crypto_krb5_encrypt().
2. len uses (4 + authx_len) instead of (4 + xdr_round_up(authx_len)), even though rxgk_pad_out() subsequently writes up to 3 trailing XDR padding bytes after authx_offset + authx_len.

Wrap both appdata->len and authx_len in xdr_round_up().

---

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)
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
#2 lore raw
In reply to Bilal Hashim
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The commit message has no Fixes: tag and no Cc: stable, but the patch fixes a bug that userspace can trigger.
- [Low] The commit message gets three details of the failure wrong.

--

rxrpc: rxgk: round up appdata and authx lengths in rxgk_construct_response()

This patch fixes the RESPONSE buffer length calculation in rxgk_construct_response(). auth_len now uses xdr_round_up(appdata->len), which matches the size rxgk_construct_authenticator() writes. The authx part of len is now rounded up with xdr_round_up(authx_len).

Quoted 1 line

1. auth_len is computed using appdata->len instead of

[ ... ]

Quoted 6 lines

message, the allocated authenticator buffer is up to 3 bytes too short, causing skb_store_bits() / crypto_krb5_encrypt() to fail or hit WARN_ON() in crypto_krb5_encrypt().
2. len uses (4 + authx_len) instead of (4 + xdr_round_up(authx_len)), even though rxgk_pad_out() subsequently writes up to 3 trailing XDR padding bytes after authx_offset + authx_len.

[Severity: Low]
Is this description accurate? A few details don't seem to match the code.

Can skb_store_bits() actually fail here? rxgk_construct_authenticator() writes up to authx_offset + conf_len + 56 + xdr_round_up(appdata->len). Even before this patch, the skb extended to authx_offset + conf_len + 56 + appdata->len + cksum_len.

The padding is at most 3 bytes. cksum_len is at least 12 for every supported enctype (rfc3962: 12, rfc6803: 16, rfc8009: 16/24). So every store appears to fit.

The WARN_ON() that fires also isn't the one in crypto_krb5_encrypt(). It is the one in the profile encrypt routine, either krb5_aead_encrypt() in crypto/krb5/rfc3961_simplified.c or rfc8009_encrypt() in crypto/krb5/rfc8009_aes2.c:

	if (WARN_ON(cksum_offset + krb5->cksum_len > sg_len))
		return -EFAULT;

For item 2, can rxgk_pad_out() write any padding after authx_offset + authx_len? After encryption, authx_len is conf_len + auth_len + cksum_len:

- conf_len is 16.
- auth_len is sizeof(a) + xdr_round_up(appdata->len) + sizeof(b), which is always 4-aligned.
- Every cksum_len is a multiple of 4.

That means rxgk_pad_out(response, authx_len, ...) always pads 0 bytes, and xdr_round_up(authx_len) equals authx_len for every supported enctype.

Should the message describe the second hunk as hardening rather than a second bug fix?

Quoted 6 lines
net/rxrpc/rxgk.c +0 -0
index 77a67ace1d248..6dc4bfd2445a3 100644
@@ -936,11 +936,12 @@ static int rxgk_construct_response(struct rxrpc_connection *conn,
 	if (IS_ERR(gk))

net/rxrpc/rxgk.c static int rxgk_construct_response(struct rxrpc_connection *conn, · line 944

Quoted 10 lines
net/rxrpc/rxgk.c +3 -2
 		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));

[Severity: Medium]
Both of these calculations came from commit 9d1d2b59341f ("rxrpc: rxgk:
Implement the yfs-rxgk security class (GSSAPI)"). Should this patch carry a
Fixes: tag for that commit, and possibly a Cc: stable?

Userspace can reach this with sendmsg(). rxgk_sendmsg_respond_to_challenge() takes the appdata length from the cmsg without checking alignment:

	appdata.len = cmsg->cmsg_len - sizeof(struct cmsghdr);

The call chain is:

sendmsg()
rxgk_sendmsg_respond_to_challenge()

    rxgk_construct_response()
      rxgk_encrypt_authenticator()
        crypto_krb5_encrypt()
          krb5_aead_encrypt() / rfc8009_encrypt()

If appdata->len is not a multiple of 4, rxgk_construct_authenticator() returns 56 + xdr_round_up(appdata->len). Before this patch, sg_len was only conf_len + 56 + appdata->len + cksum_len. The WARN_ON() in the encrypt routine therefore always fires and returns -EFAULT.

The result is a WARN that userspace can trigger at will (a panic with panic_on_warn), and the RESPONSE is never sent. Without a Fixes: tag, stable trees that include rxgk (6.16 onwards) might not pick up this fix.

Quoted 3 lines
net/rxrpc/rxgk.c +0 -0
 	response = alloc_skb_with_frags(0, len, 0, &ret, GFP_NOFS);
 	if (!response)
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127125250.1434-1-AeeSec%40126.com