[LTP] [PATCH v2] network/sockets: Add handshake01
Stephen Bertram
sbertram@redhat.com
Wed Nov 18 15:32:54 CET 2026
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 | 230 ++++++++++++++++++++++++
3 files changed, 232 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..a4d04b745
--- /dev/null
+++ b/testcases/network/sockets/handshake01.c
@@ -0,0 +1,230 @@
+// 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 int resolve_family(const char *name);
+
+static void setup(void)
+{
+ struct passwd *pw = SAFE_GETPWNAM("nobody");
+
+ nobody_uid = pw->pw_uid;
+ nobody_gid = pw->pw_gid;
+
+ nl_family_id = resolve_family(HANDSHAKE_FAMILY_NAME);
+}
+
+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 void unprivileged_done(void)
+{
+ int ret;
+
+ if (SAFE_FORK())
+ return;
+
+ SAFE_SETGROUPS(0, NULL);
+ SAFE_SETGID(nobody_gid);
+ SAFE_SETUID(nobody_uid);
+
+ ret = send_done();
+
+ if (ret == -EPERM)
+ tst_res(TPASS, "unprivileged HANDSHAKE_CMD_DONE rejected with EPERM");
+ else
+ tst_res(TFAIL,
+ "unprivileged HANDSHAKE_CMD_DONE returned %d (%s), expected EPERM",
+ ret, strerror(-ret));
+
+ exit(0);
+}
+
+static void run(void)
+{
+ int root_err;
+
+ 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));
+
+ unprivileged_done();
+}
+
+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.1
More information about the ltp
mailing list