linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Xu <jeffxu@google.com>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: linux-security-module@vger.kernel.org,
	Jeff Xu <jeffxu@google.com>,
	Jorge Lucangeli Obes <jorgelo@chromium.org>,
	Guenter Roeck <groeck@chromium.org>,
	Kees Cook <keescook@chromium.org>
Subject: [PATCH] selftests/landlock: skip ptrace_test when YAMA is enabled
Date: Tue, 28 Jun 2022 22:29:41 +0000	[thread overview]
Message-ID: <20220628222941.2642917-1-jeffxu@google.com> (raw)

ptrace_test assumes YAMA is disabled, skip it if YAMA is enabled.

Cc: Jorge Lucangeli Obes <jorgelo@chromium.org>
Cc: Guenter Roeck <groeck@chromium.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mickaël Salaün <mic@digikod.net>
Tested-by: Jeff Xu <jeffxu@google.com>
Signed-off-by: Jeff Xu <jeffxu@google.com>
Change-Id: I623742ca9f20ec706a38c92f6c0bab755f73578f
---
 .../testing/selftests/landlock/ptrace_test.c  | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/tools/testing/selftests/landlock/ptrace_test.c b/tools/testing/selftests/landlock/ptrace_test.c
index c28ef98ff3ac..ef2d36f56764 100644
--- a/tools/testing/selftests/landlock/ptrace_test.c
+++ b/tools/testing/selftests/landlock/ptrace_test.c
@@ -226,6 +226,44 @@ FIXTURE_TEARDOWN(hierarchy)
 {
 }
 
+int open_sysfs(const char *path, int flags, int *fd)
+{
+	*fd = open(path, flags);
+
+	if (fd < 0)
+		return -1;
+
+	return 0;
+}
+
+int read_sysfs_int_fd(int fd, int *val)
+{
+	char buf[2];
+
+	if (read(fd, buf, sizeof(buf)) < 0)
+		return -1;
+
+	buf[sizeof(buf) - 1] = '\0';
+	*val = atoi(buf);
+	return 0;
+}
+
+int read_sysfs_int(const char *path, int *val)
+{
+	int fd;
+
+	if (open_sysfs(path, O_RDONLY, &fd) != 0)
+		return -1;
+
+	if (read_sysfs_int_fd(fd, val) != 0) {
+		close(fd);
+		return -1;
+	}
+
+	close(fd);
+	return 0;
+}
+
 /* Test PTRACE_TRACEME and PTRACE_ATTACH for parent and child. */
 TEST_F(hierarchy, trace)
 {
@@ -235,6 +273,17 @@ TEST_F(hierarchy, trace)
 	char buf_parent;
 	long ret;
 
+	int ptrace_val;
+
+	ASSERT_EQ(0, read_sysfs_int("/proc/sys/kernel/yama/ptrace_scope",
+				    &ptrace_val));
+	if (ptrace_val != 0) {
+		/*
+		 * Yama's scoped ptrace is presumed disabled.  If enabled, skip.
+		 */
+		SKIP(return, "yama is enabled, skip current test");
+	}
+
 	/*
 	 * Removes all effective and permitted capabilities to not interfere
 	 * with cap_ptrace_access_check() in case of PTRACE_MODE_FSCREDS.
-- 
2.37.0.rc0.161.g10f37bed90-goog


             reply	other threads:[~2022-06-28 22:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28 22:29 Jeff Xu [this message]
2022-06-30 15:09 ` [PATCH] selftests/landlock: skip ptrace_test when YAMA is enabled Mickaël Salaün
2022-06-30 15:31 ` Mickaël Salaün
2022-07-05 21:49   ` Jeff Xu
2022-07-06 23:41     ` Jeff Xu
2022-07-07 14:24     ` Mickaël Salaün
     [not found]     ` <CALmYWFvcSn_wks0bXo3_DUyYGtVW_MHrrO1dRoYcxY4uiB1KEA@mail.gmail.com>
2022-07-07 14:25       ` Mickaël Salaün
2022-07-13 23:44         ` Jeff Xu
2022-07-14  0:30           ` Guenter Roeck
2022-07-14 18:36             ` Jeff Xu
2022-07-14 20:39               ` Guenter Roeck
2022-07-15  0:35                 ` Jeff Xu
2022-07-15 21:41                   ` Jeff Xu
2022-07-15 22:42                     ` Guenter Roeck
2022-07-16  0:16                       ` Jeff Xu
2022-07-16 21:45                         ` Guenter Roeck
2022-07-18 21:24                           ` Mickaël Salaün

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=20220628222941.2642917-1-jeffxu@google.com \
    --to=jeffxu@google.com \
    --cc=groeck@chromium.org \
    --cc=jorgelo@chromium.org \
    --cc=keescook@chromium.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mic@digikod.net \
    /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;
as well as URLs for NNTP newsgroup(s).