* [LTP] [PATCH v1] network/sockets: Add handshake01
@ 2026-11-17 23:20 Stephen Bertram via ltp
2026-11-18 4:51 ` [LTP] " linuxtestproject.agent
0 siblings, 1 reply; 2+ messages in thread
From: Stephen Bertram via ltp @ 2026-11-17 23:20 UTC (permalink / raw)
To: ltp; +Cc: Stephen Bertram
From: Stephen Bertram <sbertram@redhat.com>
Add a regression test for CVE-2026-74270 (81246a65303d "handshake:
Require admin permission for DONE command"). Verify that
HANDSHAKE_CMD_DONE returns -EPERM for a sender without CAP_NET_ADMIN,
while root reaches the handler and gets -EINVAL for the missing sockfd.
Register it as cve-2026-74270 in runtest/cve.
Reviewed and tested before submission: builds, passes check-handshake01,
fails on the unfixed kernel and passes on the fixed kernel.
Assisted-by: ClaudeCode:DeepSeek-V4.1-Flash
Signed-off-by: Stephen Bertram <sbertram@redhat.com>
---
runtest/cve | 1 +
testcases/network/sockets/.gitignore | 1 +
testcases/network/sockets/handshake01.c | 243 ++++++++++++++++++++++++
3 files changed, 245 insertions(+)
create mode 100644 testcases/network/sockets/handshake01.c
diff --git a/runtest/cve b/runtest/cve
index 0fe25cd83..fb31cd76f 100644
--- a/runtest/cve
+++ b/runtest/cve
@@ -105,3 +105,4 @@ cve-2026-46300 xfrm02
cve-2026-46300-skb-segment xfrm03
cve-2026-46331 cve-2026-46331
cve-2026-64564 sctphantom
+cve-2026-74270 handshake01
diff --git a/testcases/network/sockets/.gitignore b/testcases/network/sockets/.gitignore
index 3e8962bbf..c7d784d36 100644
--- a/testcases/network/sockets/.gitignore
+++ b/testcases/network/sockets/.gitignore
@@ -1,3 +1,4 @@
+/handshake01
/xfrm01
/xfrm02
/xfrm03
diff --git a/testcases/network/sockets/handshake01.c b/testcases/network/sockets/handshake01.c
new file mode 100644
index 000000000..68384edec
--- /dev/null
+++ b/testcases/network/sockets/handshake01.c
@@ -0,0 +1,243 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Red Hat, Inc.
+ */
+
+/*\
+ * Test for CVE-2026-74270 fixed by:
+ * 81246a65303d ("handshake: Require admin permission for DONE command")
+ *
+ * The handshake generic netlink family exposes the ACCEPT and DONE downcalls
+ * for the trusted handshake agent (tlshd). ACCEPT requires GENL_ADMIN_PERM;
+ * DONE had no privilege check. An unprivileged process that knows a socket
+ * with a pending handshake could send a forged DONE and make the kernel
+ * consumer proceed as if the handshake succeeded, or tear down a legitimate
+ * handshake with a non-zero status.
+ *
+ * The test resolves the ``handshake`` family and sends ``HANDSHAKE_CMD_DONE``
+ * without attributes. The generic netlink permission check runs before
+ * attribute parsing, so no pending handshake is needed: the kernel rejects
+ * the request with ``-EPERM`` for a sender without ``CAP_NET_ADMIN``. A root
+ * control must instead reach the handler and fail with ``-EINVAL`` because
+ * ``HANDSHAKE_A_DONE_SOCKFD`` is missing.
+ *
+ * On an unfixed kernel the unprivileged request reaches the handler and
+ * returns ``-EINVAL`` as well, so the test fails.
+ */
+
+#include <linux/genetlink.h>
+#include <pwd.h>
+
+#include "tst_test.h"
+#include "tst_netlink.h"
+
+/*
+ * Values from include/uapi/linux/handshake.h. Define them locally so the
+ * test builds against kernel headers older than 6.7.
+ */
+#ifndef HANDSHAKE_FAMILY_NAME
+# define HANDSHAKE_FAMILY_NAME "handshake"
+#endif
+#ifndef HANDSHAKE_FAMILY_VERSION
+# define HANDSHAKE_FAMILY_VERSION 1
+#endif
+#ifndef HANDSHAKE_CMD_DONE
+# define HANDSHAKE_CMD_DONE 3
+#endif
+
+static int nl_family_id;
+static uid_t nobody_uid;
+static gid_t nobody_gid;
+
+static void setup(void)
+{
+ struct passwd *pw = SAFE_GETPWNAM("nobody");
+
+ nobody_uid = pw->pw_uid;
+ nobody_gid = pw->pw_gid;
+}
+
+static int resolve_family(const char *name)
+{
+ struct tst_netlink_context *ctx;
+ struct tst_netlink_message *msgs, *m;
+ struct nlmsghdr nlh = {
+ .nlmsg_type = GENL_ID_CTRL,
+ .nlmsg_flags = NLM_F_REQUEST,
+ };
+ struct genlmsghdr gh = {
+ .cmd = CTRL_CMD_GETFAMILY,
+ .version = 1,
+ };
+ char *p;
+ int id = -1, rem;
+ uint16_t fid;
+
+ ctx = NETLINK_CREATE_CONTEXT(NETLINK_GENERIC);
+ NETLINK_ADD_MESSAGE(ctx, &nlh, &gh, sizeof(gh));
+ NETLINK_ADD_ATTR_STRING(ctx, CTRL_ATTR_FAMILY_NAME, name);
+
+ if (NETLINK_SEND(ctx) < 0)
+ tst_brk(TBROK | TERRNO, "send(CTRL_CMD_GETFAMILY) failed");
+
+ if (NETLINK_WAIT(ctx) <= 0)
+ tst_brk(TBROK, "no response to CTRL_CMD_GETFAMILY");
+
+ msgs = NETLINK_RECV(ctx);
+ if (!msgs)
+ tst_brk(TBROK, "no response to CTRL_CMD_GETFAMILY");
+
+ for (m = msgs; m->header; m++) {
+ if (m->err) {
+ if (m->err->error == -ENOENT)
+ tst_brk(TCONF, "family '%s' is not available", name);
+ if (m->err->error)
+ tst_brk(TBROK, "CTRL_CMD_GETFAMILY failed: %s",
+ strerror(-m->err->error));
+ continue;
+ }
+
+ if (m->header->nlmsg_type != GENL_ID_CTRL)
+ continue;
+ if (m->payload_size < GENL_HDRLEN)
+ continue;
+
+ p = (char *)m->payload + GENL_HDRLEN;
+ rem = (int)m->payload_size - GENL_HDRLEN;
+
+ while (rem >= (int)sizeof(struct nlattr)) {
+ struct nlattr *a = (struct nlattr *)p;
+ int alen;
+
+ if (a->nla_len < NLA_HDRLEN)
+ break;
+
+ alen = NLA_ALIGN(a->nla_len);
+ if (alen > rem)
+ break;
+
+ if ((a->nla_type & NLA_TYPE_MASK) == CTRL_ATTR_FAMILY_ID) {
+ if (a->nla_len < NLA_HDRLEN + (int)sizeof(fid))
+ break;
+
+ memcpy(&fid, (char *)a + NLA_HDRLEN, sizeof(fid));
+ id = fid;
+ break;
+ }
+
+ p += alen;
+ rem -= alen;
+ }
+
+ if (id >= 0)
+ break;
+ }
+
+ NETLINK_FREE_MESSAGE(msgs);
+ NETLINK_DESTROY_CONTEXT(ctx);
+
+ if (id < 0)
+ tst_brk(TBROK, "CTRL_ATTR_FAMILY_ID not found for '%s'", name);
+
+ return id;
+}
+
+static int send_done(void)
+{
+ struct tst_netlink_context *ctx;
+ struct nlmsghdr nlh = {
+ .nlmsg_type = nl_family_id,
+ .nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
+ };
+ struct genlmsghdr gh = {
+ .cmd = HANDSHAKE_CMD_DONE,
+ .version = HANDSHAKE_FAMILY_VERSION,
+ };
+ int ret;
+
+ ctx = NETLINK_CREATE_CONTEXT(NETLINK_GENERIC);
+ NETLINK_ADD_MESSAGE(ctx, &nlh, &gh, sizeof(gh));
+
+ ret = NETLINK_SEND_VALIDATE(ctx);
+ NETLINK_DESTROY_CONTEXT(ctx);
+
+ if (ret)
+ return 0;
+
+ /* No ACK and no error means the kernel never replied. */
+ if (!tst_netlink_errno)
+ return -ETIMEDOUT;
+
+ return -tst_netlink_errno;
+}
+
+static int unprivileged_done(void)
+{
+ int fds[2], err = 0;
+ pid_t pid;
+
+ SAFE_PIPE(fds);
+ pid = SAFE_FORK();
+
+ if (!pid) {
+ int ret;
+
+ SAFE_CLOSE(fds[0]);
+
+ SAFE_SETGROUPS(0, NULL);
+ SAFE_SETGID(nobody_gid);
+ SAFE_SETUID(nobody_uid);
+
+ ret = send_done();
+
+ SAFE_WRITE(SAFE_WRITE_ALL, fds[1], &ret, sizeof(ret));
+ _exit(0);
+ }
+
+ SAFE_CLOSE(fds[1]);
+ SAFE_READ(SAFE_READ_ALL, fds[0], &err, sizeof(err));
+ SAFE_CLOSE(fds[0]);
+ SAFE_WAITPID(pid, NULL, 0);
+
+ return err;
+}
+
+static void run(void)
+{
+ int root_err, child_err;
+
+ nl_family_id = resolve_family(HANDSHAKE_FAMILY_NAME);
+
+ root_err = send_done();
+ if (root_err == -EPERM)
+ tst_brk(TBROK, "root was denied HANDSHAKE_CMD_DONE");
+ if (root_err != -EINVAL)
+ tst_brk(TBROK,
+ "root HANDSHAKE_CMD_DONE returned %d (%s), expected EINVAL",
+ root_err, strerror(-root_err));
+
+ child_err = unprivileged_done();
+
+ if (child_err == -EPERM)
+ tst_res(TPASS, "unprivileged HANDSHAKE_CMD_DONE rejected with EPERM");
+ else
+ tst_res(TFAIL,
+ "unprivileged HANDSHAKE_CMD_DONE returned %d (%s), expected EPERM",
+ child_err, strerror(-child_err));
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .test_all = run,
+ .needs_root = 1,
+ .forks_child = 1,
+ .needs_kconfigs = (const char *[]) {
+ "CONFIG_NET_HANDSHAKE",
+ NULL
+ },
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "81246a65303d9635266b1334490142caaf86a11f"},
+ {"CVE", "2026-74270"},
+ {}
+ },
+};
--
2.56.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] network/sockets: Add handshake01
2026-11-17 23:20 [LTP] [PATCH v1] network/sockets: Add handshake01 Stephen Bertram via ltp
@ 2026-11-18 4:51 ` linuxtestproject.agent
0 siblings, 0 replies; 2+ messages in thread
From: linuxtestproject.agent @ 2026-11-18 4:51 UTC (permalink / raw)
To: Stephen Bertram; +Cc: ltp
Hi Stephen,
On Tue, Nov 17, 2026, Stephen Bertram <sbertram@redhat.com> wrote:
> network/sockets: Add handshake01
> +static int unprivileged_done(void)
> +{
> + int fds[2], err = 0;
> + pid_t pid;
> +
> + SAFE_PIPE(fds);
> + pid = SAFE_FORK();
> +
> + if (!pid) {
> + int ret;
> +
> + SAFE_CLOSE(fds[0]);
> +
> + SAFE_SETGROUPS(0, NULL);
> + SAFE_SETGID(nobody_gid);
> + SAFE_SETUID(nobody_uid);
> +
> + ret = send_done();
> +
> + SAFE_WRITE(SAFE_WRITE_ALL, fds[1], &ret, sizeof(ret));
> + _exit(0);
> + }
> +
> + SAFE_CLOSE(fds[1]);
> + SAFE_READ(SAFE_READ_ALL, fds[0], &err, sizeof(err));
> + SAFE_CLOSE(fds[0]);
> + SAFE_WAITPID(pid, NULL, 0);
> +
> + return err;
> +}
Call tst_res() directly in the child process and terminate with exit(0)
instead of _exit(0) rather than sending the result over a pipe to the
parent. Drop SAFE_PIPE() and SAFE_WAITPID(), as the LTP library propagates
child results via shared memory and reaps children automatically.
> +static void run(void)
> +{
> + int root_err, child_err;
> +
> + nl_family_id = resolve_family(HANDSHAKE_FAMILY_NAME);
Move nl_family_id = resolve_family(HANDSHAKE_FAMILY_NAME) to setup() so the
static family ID resolution and TCONF check run once instead of on every -i
iteration.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 4:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 23:20 [LTP] [PATCH v1] network/sockets: Add handshake01 Stephen Bertram via ltp
2026-11-18 4:51 ` [LTP] " linuxtestproject.agent
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.