From: Swarup Laxman Kotiaklapudi <swarupkotikalapudi@gmail.com>
To: shuah@kernel.org, akpm@linux-foundation.org, adobriyan@gmail.com,
hughd@google.com, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org
Cc: Swarup Laxman Kotiaklapudi <swarupkotikalapudi@gmail.com>
Subject: [PATCH] selftests:proc ProtectionKey check in smpas test
Date: Thu, 26 Oct 2023 01:06:27 +0530 [thread overview]
Message-ID: <20231025193627.316508-1-swarupkotikalapudi@gmail.com> (raw)
Check ProtectionKey field in /proc/*/smaps output,
if system supports page-based memory permissions.
Signed-off-by: Swarup Laxman Kotiaklapudi <swarupkotikalapudi@gmail.com>
---
tools/testing/selftests/proc/proc-empty-vm.c | 38 ++++++++++++--------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c
index b16c13688b88..4842f923235c 100644
--- a/tools/testing/selftests/proc/proc-empty-vm.c
+++ b/tools/testing/selftests/proc/proc-empty-vm.c
@@ -37,6 +37,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
+#include "../kselftest.h"
#ifdef __amd64__
#define TEST_VSYSCALL
@@ -83,10 +84,7 @@ static const char proc_pid_smaps_vsyscall_1[] =
"SwapPss: 0 kB\n"
"Locked: 0 kB\n"
"THPeligible: 0\n"
-/*
- * "ProtectionKey:" field is conditional. It is possible to check it as well,
- * but I don't have such machine.
- */
+"ProtectionKey: 0\n"
;
static const char proc_pid_smaps_vsyscall_2[] =
@@ -113,10 +111,7 @@ static const char proc_pid_smaps_vsyscall_2[] =
"SwapPss: 0 kB\n"
"Locked: 0 kB\n"
"THPeligible: 0\n"
-/*
- * "ProtectionKey:" field is conditional. It is possible to check it as well,
- * but I'm too tired.
- */
+"ProtectionKey: 0\n"
;
static void sigaction_SIGSEGV(int _, siginfo_t *__, void *___)
@@ -241,13 +236,26 @@ static int test_proc_pid_smaps(pid_t pid)
} else {
ssize_t rv = read(fd, buf, sizeof(buf));
close(fd);
- if (g_vsyscall == 0) {
- assert(rv == 0);
- } else {
- size_t len = strlen(g_proc_pid_maps_vsyscall);
- /* TODO "ProtectionKey:" */
- assert(rv > len);
- assert(memcmp(buf, g_proc_pid_maps_vsyscall, len) == 0);
+ assert(rv >= 0);
+ assert(rv <= sizeof(buf));
+ if (g_vsyscall != 0) {
+ int pkey = pkey_alloc(0, 0);
+
+ if (pkey < 0) {
+ size_t len = strlen(g_proc_pid_maps_vsyscall);
+
+ assert(rv > len);
+ assert(memcmp(buf, g_proc_pid_maps_vsyscall, len) == 0);
+ } else {
+ pkey_free(pkey);
+ static const char * const S[] = {
+ "ProtectionKey: 0\n"
+ };
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(S); i++)
+ assert(memmem(buf, rv, S[i], strlen(S[i])));
+ }
}
return EXIT_SUCCESS;
}
--
2.34.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
next reply other threads:[~2023-10-25 19:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-25 19:36 Swarup Laxman Kotiaklapudi [this message]
2023-10-27 10:41 ` [PATCH] selftests:proc ProtectionKey check in smpas test Alexey Dobriyan
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=20231025193627.316508-1-swarupkotikalapudi@gmail.com \
--to=swarupkotikalapudi@gmail.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).