Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: "Björn Töpel" <bjorn@kernel.org>
To: Adrian Reber <areber@redhat.com>,
	Christian Brauner <brauner@kernel.org>,
	Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org
Cc: "Björn Töpel" <bjorn@rivosinc.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] selftests: clone3: Avoid fragile struct poking
Date: Fri, 27 Sep 2024 17:04:53 +0200	[thread overview]
Message-ID: <20240927150455.360843-1-bjorn@kernel.org> (raw)

From: Björn Töpel <bjorn@rivosinc.com>

The struct libcap in the selftest, and the what libcap is actually
using doesn't match, so the test fail. Libcap internals have changed,
but the selftest hasn't.

Fix by avoid poking the libcap internals.

Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
---
 .../clone3/clone3_cap_checkpoint_restore.c      | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c b/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c
index 31b56d625655..9e6ee8c5316e 100644
--- a/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c
+++ b/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c
@@ -89,14 +89,9 @@ static int test_clone3_set_tid(struct __test_metadata *_metadata,
 	return ret;
 }
 
-struct libcap {
-	struct __user_cap_header_struct hdr;
-	struct __user_cap_data_struct data[2];
-};
-
 static int set_capability(void)
 {
-	cap_value_t cap_values[] = { CAP_SETUID, CAP_SETGID };
+	cap_value_t cap_values[] = { CAP_SETUID, CAP_SETGID, CAP_CHECKPOINT_RESTORE };
 	struct libcap *cap;
 	int ret = -1;
 	cap_t caps;
@@ -113,14 +108,8 @@ static int set_capability(void)
 		goto out;
 	}
 
-	cap_set_flag(caps, CAP_EFFECTIVE, 2, cap_values, CAP_SET);
-	cap_set_flag(caps, CAP_PERMITTED, 2, cap_values, CAP_SET);
-
-	cap = (struct libcap *) caps;
-
-	/* 40 -> CAP_CHECKPOINT_RESTORE */
-	cap->data[1].effective |= 1 << (40 - 32);
-	cap->data[1].permitted |= 1 << (40 - 32);
+	cap_set_flag(caps, CAP_EFFECTIVE, 3, cap_values, CAP_SET);
+	cap_set_flag(caps, CAP_PERMITTED, 3, cap_values, CAP_SET);
 
 	if (cap_set_proc(caps)) {
 		perror("cap_set_proc");

base-commit: 075dbe9f6e3c21596c5245826a4ee1f1c1676eb8
-- 
2.43.0


                 reply	other threads:[~2024-09-27 15:05 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=20240927150455.360843-1-bjorn@kernel.org \
    --to=bjorn@kernel.org \
    --cc=areber@redhat.com \
    --cc=bjorn@rivosinc.com \
    --cc=brauner@kernel.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