[LTP] [PATCH v3] crypto/af_alg09: Test CVE-2026-52972
Wei Gao
wegao@suse.com
Thu Nov 19 08:42:00 CET 2026
On Wed, Nov 18, 2026 at 05:51:43PM -0500, 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.
>
> Since Linux 7.3, /proc/sys/crypto/af_alg_restrict defaults to 1 and bind()
> of gcm(aes) fails with ENOENT. When that file exists and is writable, the
> test sets it to 0 for the run and restores the previous value.
>
> Assisted-by: Cursor:Grok-4.7
> Signed-off-by: Stephen Bertram <sbertram@redhat.com>
> ---
> runtest/crypto | 1 +
> runtest/cve | 1 +
> testcases/kernel/crypto/.gitignore | 1 +
> testcases/kernel/crypto/af_alg09.c | 112 +++++++++++++++++++++++++++++
> 4 files changed, 115 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..423eee431
> --- /dev/null
> +++ b/testcases/kernel/crypto/af_alg09.c
> @@ -0,0 +1,112 @@
> +// 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),
> + .save_restore = (const struct tst_path_val[]) {
> + {"/proc/sys/crypto/af_alg_restrict", "0",
> + TST_SR_SKIP_MISSING | TST_SR_TCONF_RO},
Consider using TST_SR_SKIP_RO instead of TST_SR_TCONF_RO here if no root needed.
> + {}
> + },
> + .tags = (const struct tst_tag[]) {
> + {"linux-git", "e4c06479d7059888adf2f22bc1ebcf053bf691a2"},
> + {"CVE", "2026-52972"},
> + {}
> + },
> +};
> --
> 2.56.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
More information about the ltp
mailing list