[LTP] [PATCH v2] crypto/af_alg09: Test CVE-2026-52972
Ricardo B. Marlière (SUSE)
ricardo@marliere.net
Wed Nov 18 22:20:50 CET 2026
On Mon Nov 16, 2026 at 12:09 PM -03, Stephen Bertram via ltp wrote:
> From: Stephen Bertram <sbertram@redhat.com>
>
> Add a regression test for the missing cap on the AEAD associated data
> length. Kernel commit e4c06479d705 ("crypto: af_alg - Cap AEAD AD
> length to 0x80000000") rejects ALG_SET_AEAD_ASSOCLEN values greater
> than or equal to 0x80000000; without it af_alg_sendmsg() accepts any
> 32-bit value.
>
> The test opens an AF_ALG AEAD request socket, sets ALG_OP_DECRYPT and
> ALG_SET_AEAD_ASSOCLEN to 0x7fffffff, which must be accepted, and to
> 0x80000000 and 0xffffffff, which must fail with EINVAL. It does not
> call recvmsg(), so the test only depends on the control-message
> validation.
>
> Signed-off-by: Stephen Bertram <sbertram@redhat.com>
e4c06479d705 (fixed, 7.1.0-rc2):
3/3 TPASS: 0x7fffffff accepted; 0x80000000 and 0xffffffff → EINVAL
ffdd2bc37895 (before the fix, 7.1.0-rc2):
1 TPASS (0x7fffffff), 2 TFAIL: 0x80000000 and 0xffffffff succeeded instead of EINVAL
20eef29b7c84 (current mainline, 7.4.0-rc3):
lib/tst_af_alg.c:42: TCONF: kernel doesn't support aead algorithm 'gcm(aes)'
20eef29b7c84 (current mainline, 7.4.0-rc3) with
/proc/sys/crypto/af_alg_restrict set to 0:
3/3 TPASS: 0x7fffffff accepted; 0x80000000 and 0xffffffff → EINVAL
Perhaps add a .save_restore entry for /proc/sys/crypto/af_alg_restrict ?
Tested-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
> ---
> runtest/crypto | 1 +
> runtest/cve | 1 +
> testcases/kernel/crypto/.gitignore | 1 +
> testcases/kernel/crypto/af_alg09.c | 107 +++++++++++++++++++++++++++++
> 4 files changed, 110 insertions(+)
> create mode 100644 testcases/kernel/crypto/af_alg09.c
>
> diff --git a/runtest/crypto b/runtest/crypto
> index a8330db9f..082b906c1 100644
> --- a/runtest/crypto
> +++ b/runtest/crypto
> @@ -6,6 +6,7 @@ af_alg05 af_alg05
> af_alg06 af_alg06
> af_alg07 af_alg07
> af_alg08 af_alg08
> +af_alg09 af_alg09
> pcrypt_aead01 pcrypt_aead01
> crypto_user01 crypto_user01
> crypto_user02 crypto_user02
> diff --git a/runtest/cve b/runtest/cve
> index 0fe25cd83..ccd7e3db3 100644
> --- a/runtest/cve
> +++ b/runtest/cve
> @@ -89,6 +89,7 @@ cve-2023-0461 setsockopt10
> cve-2023-31248 nft02
> cve-2023-52879 fanotify25
> cve-2026-43499 ghostlock
> +cve-2026-52972 af_alg09
> cve-2026-53362 setsockopt11
> cve-2026-64600 refluxfs
> cve-2026-99999 pwnescape
> diff --git a/testcases/kernel/crypto/.gitignore b/testcases/kernel/crypto/.gitignore
> index aca016b62..e1890d975 100644
> --- a/testcases/kernel/crypto/.gitignore
> +++ b/testcases/kernel/crypto/.gitignore
> @@ -6,6 +6,7 @@ af_alg05
> af_alg06
> af_alg07
> af_alg08
> +af_alg09
> pcrypt_aead01
> crypto_user01
> crypto_user02
> diff --git a/testcases/kernel/crypto/af_alg09.c b/testcases/kernel/crypto/af_alg09.c
> new file mode 100644
> index 000000000..f91c27ee5
> --- /dev/null
> +++ b/testcases/kernel/crypto/af_alg09.c
> @@ -0,0 +1,107 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2026 Red Hat, Inc.
> + */
> +
> +/*\
> + * Test for CVE-2026-52972.
> + *
> + * Verify that the AF_ALG AEAD interface rejects an associated data length
> + * greater than or equal to 0x80000000 with EINVAL.
> + *
> + * Before kernel commit e4c06479d705 ("crypto: af_alg - Cap AEAD AD length to
> + * 0x80000000") af_alg_sendmsg() accepted any 32-bit ALG_SET_AEAD_ASSOCLEN
> + * value.
> + */
> +
> +#include "tst_test.h"
> +#include "tst_af_alg.h"
> +#include "lapi/socket.h"
> +
> +#define ASSOCLEN_LIMIT 0x80000000U
> +#define SEND_SIZE 16
> +
> +static int algfd = -1;
> +
> +/*
> + * Send SEND_SIZE bytes with ALG_SET_AEAD_ASSOCLEN set to assoclen and
> + * ALG_SET_OP set to ALG_OP_DECRYPT. Return the sendmsg() return value, with
> + * errno from sendmsg() preserved.
> + */
> +static ssize_t send_assoclen(int reqfd, uint32_t assoclen)
> +{
> + char data[SEND_SIZE] = {0};
> + char control[CMSG_SPACE(sizeof(uint32_t)) * 2];
> + struct iovec iov = {
> + .iov_base = data,
> + .iov_len = sizeof(data),
> + };
> + struct msghdr msg = {
> + .msg_iov = &iov,
> + .msg_iovlen = 1,
> + .msg_control = control,
> + .msg_controllen = sizeof(control),
> + };
> + struct cmsghdr *cmsg;
> + uint32_t op = ALG_OP_DECRYPT;
> +
> + memset(control, 0, sizeof(control));
> +
> + cmsg = CMSG_FIRSTHDR(&msg);
> + cmsg->cmsg_level = SOL_ALG;
> + cmsg->cmsg_type = ALG_SET_OP;
> + cmsg->cmsg_len = CMSG_LEN(sizeof(op));
> + memcpy(CMSG_DATA(cmsg), &op, sizeof(op));
> +
> + cmsg = CMSG_NXTHDR(&msg, cmsg);
> + cmsg->cmsg_level = SOL_ALG;
> + cmsg->cmsg_type = ALG_SET_AEAD_ASSOCLEN;
> + cmsg->cmsg_len = CMSG_LEN(sizeof(assoclen));
> + memcpy(CMSG_DATA(cmsg), &assoclen, sizeof(assoclen));
> +
> + return sendmsg(reqfd, &msg, 0);
> +}
> +
> +static const uint32_t assoclens[] = {
> + 0x7fffffff,
> + ASSOCLEN_LIMIT,
> + 0xffffffff,
> +};
> +
> +static void run(unsigned int i)
> +{
> + int reqfd = tst_alg_accept(algfd);
> +
> + if (assoclens[i] < ASSOCLEN_LIMIT) {
> + TST_EXP_VAL(send_assoclen(reqfd, assoclens[i]), SEND_SIZE,
> + "assoclen=%#x", assoclens[i]);
> + } else {
> + TST_EXP_FAIL2(send_assoclen(reqfd, assoclens[i]), EINVAL,
> + "assoclen=%#x", assoclens[i]);
> + }
> +
> + SAFE_CLOSE(reqfd);
> +}
> +
> +static void setup(void)
> +{
> + algfd = tst_alg_setup("aead", "gcm(aes)", NULL, 16);
> +}
> +
> +static void cleanup(void)
> +{
> + if (algfd != -1)
> + SAFE_CLOSE(algfd);
> +}
> +
> +static struct tst_test test = {
> + .setup = setup,
> + .cleanup = cleanup,
> + .test = run,
> + .tcnt = ARRAY_SIZE(assoclens),
> + .tags = (const struct tst_tag[]) {
> + {"linux-git", "e4c06479d7059888adf2f22bc1ebcf053bf691a2"},
> + {"CVE", "2026-52972"},
> + {}
> + },
> +};
More information about the ltp
mailing list