mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Qingshuang Fu <fuqingshuang@kylinos.cn>
Cc: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
	Shuah Khan <shuah@kernel.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/proc: skip fd-003-kthread if run as non-root
Date: Tue, 24 Nov 2026 22:33:55 -0800	[thread overview]
Message-ID: <20261124223355.15a364523377daf5cf2734cb@linux-foundation.org> (raw)
In-Reply-To: <20261120062933.3169112-1-fuqingshuang@kylinos.cn>

On Fri, 20 Nov 2026 14:29:33 +0800 Qingshuang Fu <fuqingshuang@kylinos.cn> wrote:

> /proc/$KERNEL_THREAD/fd can only be opened with ptrace access, so
> openat() on the "fd" directory of a kernel thread returns EACCES
> when the test is run as non-root.  kernel_thread_fd() conflates this
> with "process is userspace process", the scan over /proc runs to
> completion without finding a usable descriptor and the test exits
> with 1 (KSFT_FAIL) instead of 4 (KSFT_SKIP):
> 
>   $ ./fd-003-kthread; echo $?
>   1
> 
> Distinguish the two cases and skip the test like the rest of
> selftests/proc does when privileges are missing, so that unprivileged
> runs report "skip" instead of a false failure.
> 

Fair enough.

> --- a/tools/testing/selftests/proc/fd-003-kthread.c
> +++ b/tools/testing/selftests/proc/fd-003-kthread.c
> @@ -36,6 +36,7 @@
>   *
>   * Return /proc/$PID/fd descriptor if process is kernel thread.
>   * Return -1 if a process is userspace process.
> + * Return -EACCES if run as non-root.
>   */
>  static int kernel_thread_fd(unsigned int pid)
>  {
> @@ -88,6 +89,8 @@ static int kernel_thread_fd(unsigned int pid)
>  	fd = -1;
>  	if (flags & PF_KHTREAD) {
>  		fd = openat(dir_fd, "fd", O_RDONLY|O_DIRECTORY);
> +		if (fd == -1 && errno == EACCES)
> +			fd = -EACCES;
>  	}
>  	close(dir_fd);
>  	return fd;
> @@ -168,6 +171,8 @@ int main(void)
>  		pid++;
>  	}
>  	/* EACCES if run as non-root. */
> +	if (fd == -EACCES)
> +		return 4;
>  	if (pid >= 1024)
>  		return 1;

Why "4"?

(and why didn't they call it EACCESS.  Also s/creat/create/)

  reply	other threads:[~2026-11-25  6:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  6:29 Qingshuang Fu
2026-11-25  6:33 ` Andrew Morton [this message]
2026-11-25  7:48   ` Qingshuang Fu

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=20261124223355.15a364523377daf5cf2734cb@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=adobriyan@gmail.com \
    --cc=apw@canonical.com \
    --cc=fuqingshuang@kylinos.cn \
    --cc=joe@perches.com \
    --cc=linux-fsdevel@vger.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

all inboxes | Powered by JetHome®