mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sahaj Chaudhari <sahaj123.sc@gmail.com>
To: shuah@kernel.org
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	Sahaj Chaudhari <sahaj123.sc@gmail.com>
Subject: [PATCH] selftests/prctl: Test PR_SET_MM_AUXV terminator
Date: Wed,  7 Oct 2026 16:00:33 +0530	[thread overview]
Message-ID: <20261007103033.1549957-1-sahaj123.sc@gmail.com> (raw)

Verify that a shortened vector supplied through PR_SET_MM_AUXV has a
valid AT_NULL terminator when exposed through /proc/self/auxv. This
catches stale AUXV entries left beyond the supplied vector.

Signed-off-by: Sahaj Chaudhari <sahaj123.sc@gmail.com>
---
 tools/testing/selftests/prctl/.gitignore      |  1 +
 tools/testing/selftests/prctl/Makefile        |  1 +
 .../testing/selftests/prctl/pr_set_mm_auxv.c  | 42 +++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 tools/testing/selftests/prctl/pr_set_mm_auxv.c

diff --git a/tools/testing/selftests/prctl/.gitignore b/tools/testing/selftests/prctl/.gitignore
index 05d5e31661dfd..089af0296aeca 100644
--- a/tools/testing/selftests/prctl/.gitignore
+++ b/tools/testing/selftests/prctl/.gitignore
@@ -4,3 +4,4 @@ disable-tsc-on-off-stress-test
 disable-tsc-test
 set-anon-vma-name-test
 set-process-name
+pr_set_mm_auxv
diff --git a/tools/testing/selftests/prctl/Makefile b/tools/testing/selftests/prctl/Makefile
index e770e86fad9ac..a21811a8f6a06 100644
--- a/tools/testing/selftests/prctl/Makefile
+++ b/tools/testing/selftests/prctl/Makefile
@@ -6,6 +6,7 @@ override ARCH := $(shell echo $(ARCH) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
 ifeq ($(ARCH),x86)
 TEST_PROGS := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test \
 		disable-tsc-test set-anon-vma-name-test set-process-name
+TEST_GEN_PROGS := pr_set_mm_auxv
 all: $(TEST_PROGS)
 
 include ../lib.mk
diff --git a/tools/testing/selftests/prctl/pr_set_mm_auxv.c b/tools/testing/selftests/prctl/pr_set_mm_auxv.c
new file mode 100644
index 0000000000000..934ff480c0f4d
--- /dev/null
+++ b/tools/testing/selftests/prctl/pr_set_mm_auxv.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <elf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/prctl.h>
+#include <unistd.h>
+
+#include "kselftest_harness.h"
+
+TEST(set_mm_auxv_terminator)
+{
+	unsigned long auxv[] = {
+		AT_UID, 0x1111,
+		AT_GID, 0x2222,
+	};
+	unsigned long result[64];
+	ssize_t len;
+	int fd;
+
+	if (prctl(PR_SET_MM, PR_SET_MM_AUXV, (unsigned long)auxv,
+		  sizeof(auxv), 0)) {
+		if (errno == EPERM)
+			SKIP(return, "requires CAP_SYS_RESOURCE");
+		ASSERT_EQ(errno, 0);
+	}
+
+	fd = open("/proc/self/auxv", O_RDONLY);
+	ASSERT_GE(fd, 0);
+
+	len = read(fd, result, sizeof(result));
+	close(fd);
+
+	ASSERT_GE(len, (ssize_t)(6 * sizeof(unsigned long)));
+	EXPECT_EQ(result[0], (unsigned long)AT_UID);
+	EXPECT_EQ(result[1], 0x1111UL);
+	EXPECT_EQ(result[2], (unsigned long)AT_GID);
+	EXPECT_EQ(result[3], 0x2222UL);
+	EXPECT_EQ(result[4], (unsigned long)AT_NULL);
+	EXPECT_EQ(result[5], 0UL);
+}
+
+TEST_HARNESS_MAIN
-- 
2.43.0


                 reply	other threads:[~2026-10-07 10:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261007103033.1549957-1-sahaj123.sc@gmail.com \
    --to=sahaj123.sc@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®