Linux Security Modules development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH 2/2] selftests/safesetid: test GID policy with mismatched real IDs
Date: Sat, 03 Oct 2026 10:44:43 +0000	[thread overview]
Message-ID: <20261003104443.9DE661F0089B@smtp.kernel.org> (raw)
In-Reply-To: <899af06e29dd599246082096e27edd51eda1fb27.1791023194.git.tjdqudcks0424@naver.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] selftests: false test failure on older kernels due to strict prctl() check
- [Low] selftests: build failure on older glibc due to SYS_pidfd_open dependency
--

commit dbf0ec68f44394083debd3f938ca7365c6cad4f1
Author: Sung Byeongchan <tjdqudcks0424@naver.com>

selftests/safesetid: test GID policy with mismatched real IDs

This commit adds child-process cases to the SafeSetID selftests that use
mismatched real IDs to properly distinguish the source of a GID policy lookup.
It verifies that allowed and forbidden transitions are handled correctly using
both setresgid() and setgroups().

> diff --git a/tools/testing/selftests/safesetid/safesetid-gid-policy-test.c b/tools/testing/selftests/safesetid/safesetid-gid-policy-test.c
> new file mode 100644
> index 0000000000000..873d65627c494
> --- /dev/null
> +++ b/tools/testing/selftests/safesetid/safesetid-gid-policy-test.c
[ ... ]
> +static int check_child_credentials(void)
> +{
[ ... ]
> +	if (effective != expected || permitted != expected || inheritable) {
> +		fprintf(stderr, "child does not hold only CAP_SETGID\n");
> +		return -1;
> +	}
> +	for (i = 0; i <= CAP_LAST_CAP; i++) {
> +		if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, i, 0, 0) != 0) {

[Severity: Medium]
Will this strict non-zero check cause the test to falsely fail on older
kernels?

If the selftest is compiled with newer kernel headers (where CAP_LAST_CAP is
higher) but executed on an older kernel, prctl(PR_CAP_AMBIENT_IS_SET) will
return -1 (-EINVAL) for newly defined capabilities that the older kernel does
not support.

Since the test checks for != 0 instead of exactly == 1 (or explicitly
ignoring -1), the -EINVAL error return is treated as an unexpected ambient
capability.

Could this be updated to check for == 1 or ignore -1 to prevent false
failures?

> +			fprintf(stderr, "unexpected ambient capability %d\n", i);
> +			return -1;
> +		}
> +	}
> +	return 0;
> +}
[ ... ]
> +static int run_case(const char *name, enum test_operation operation,
> +		    gid_t target, bool expect_kill)
> +{
> +	struct pollfd pollfd = {};
> +	int status;
> +	int pidfd;
> +	pid_t child;
> +
> +	child = fork();
> +	if (child < 0) {
> +		perror("fork");
> +		return -1;
> +	}
> +	if (!child)
> +		run_child(operation, target);
> +
> +	pidfd = syscall(SYS_pidfd_open, child, 0);

[Severity: Low]
Does this rely on host glibc syscall definitions instead of the kernel-provided
headers?

Older glibc versions (prior to 2.36) do not define SYS_pidfd_open, which will
result in a compilation error when building the selftests on an older host.

Using the kernel-provided __NR_pidfd_open is the standard approach in
selftests to maintain backwards compatibility and independence from the host
libc's system call knowledge. Could __NR_pidfd_open be used here instead?

> +	if (pidfd < 0) {
> +		perror("pidfd_open");
> +		kill(child, SIGKILL);
> +		waitpid(child, &status, 0);
> +		return -1;
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791023194.git.tjdqudcks0424@naver.com?part=2

      reply	other threads:[~2026-10-03 10:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-03 10:34 [PATCH 0/2] SafeSetID: use real GID for GID policy lookups tjdqudcks0424
2026-10-03 10:34 ` [PATCH 1/2] security: safesetid: use real GID for GID policy lookup tjdqudcks0424
2026-10-03 10:39   ` sashiko-bot
2026-10-04 22:05   ` Serge E. Hallyn
2026-10-03 10:34 ` [PATCH 2/2] selftests/safesetid: test GID policy with mismatched real IDs tjdqudcks0424
2026-10-03 10:44   ` sashiko-bot [this message]

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=20261003104443.9DE661F0089B@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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