From: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
To: "Nathan Chancellor" <nathan@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Willy Tarreau" <w@1wt.eu>,
"Thomas Weißschuh" <linux@weissschuh.net>,
"Brendan Higgins" <brendan.higgins@linux.dev>,
"Shuah Khan" <shuah@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Nicolas Schier" <nicolas.schier@linux.dev>,
"Kees Cook" <kees@kernel.org>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Jan Kara" <jack@suse.cz>, "Christoph Hellwig" <hch@lst.de>,
"Luis Chamberlain" <mcgrof@kernel.org>,
"David Gow" <david@davidgow.net>,
"Rae Moar" <raemoar63@gmail.com>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
linux-doc@vger.kernel.org, workflows@vger.kernel.org,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Christophe Leroy" <chleroy@kernel.org>,
"Nicolas Schier" <nsc@kernel.org>
Subject: [PATCH v6 03/11] umh: add dirfd parameter
Date: Mon, 04 May 2026 11:33:19 +0200 [thread overview]
Message-ID: <20260504-kunit-kselftests-v6-3-712d3d526d97@linutronix.de> (raw)
In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de>
Allow callers to specify the directory against which to resolve the
helper's filename. Enables the running of helpers from private mounts.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
fs/coredump.c | 2 +-
include/linux/umh.h | 3 ++-
kernel/module/kmod.c | 2 +-
kernel/umh.c | 9 ++++++---
lib/kobject_uevent.c | 2 +-
security/keys/request_key.c | 2 +-
6 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/fs/coredump.c b/fs/coredump.c
index bb6fdb1f458e..45df2387be3d 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -1015,7 +1015,7 @@ static bool coredump_pipe(struct core_name *cn, struct coredump_params *cprm,
helper_argv[argi] = cn->corename + argv[argi];
helper_argv[argi] = NULL;
- sub_info = call_usermodehelper_setup(helper_argv[0], helper_argv, NULL,
+ sub_info = call_usermodehelper_setup(AT_FDCWD, helper_argv[0], helper_argv, NULL,
GFP_KERNEL, umh_coredump_setup,
NULL, cprm);
if (!sub_info)
diff --git a/include/linux/umh.h b/include/linux/umh.h
index daa6a7048c11..6670b9ff85d4 100644
--- a/include/linux/umh.h
+++ b/include/linux/umh.h
@@ -20,6 +20,7 @@ struct file;
struct subprocess_info {
struct work_struct work;
struct completion *complete;
+ int dirfd;
const char *path;
char **argv;
char **envp;
@@ -34,7 +35,7 @@ extern int
call_usermodehelper(const char *path, char **argv, char **envp, int wait);
extern struct subprocess_info *
-call_usermodehelper_setup(const char *path, char **argv, char **envp,
+call_usermodehelper_setup(int dirfd, const char *path, char **argv, char **envp,
gfp_t gfp_mask,
int (*init)(struct subprocess_info *info, struct cred *new),
void (*cleanup)(struct subprocess_info *), void *data);
diff --git a/kernel/module/kmod.c b/kernel/module/kmod.c
index a25dccdf7aa7..a85c57a707af 100644
--- a/kernel/module/kmod.c
+++ b/kernel/module/kmod.c
@@ -95,7 +95,7 @@ static int call_modprobe(char *orig_module_name, int wait)
argv[3] = module_name; /* check free_modprobe_argv() */
argv[4] = NULL;
- info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
+ info = call_usermodehelper_setup(AT_FDCWD, modprobe_path, argv, envp, GFP_KERNEL,
NULL, free_modprobe_argv, NULL);
if (!info)
goto free_module_name;
diff --git a/kernel/umh.c b/kernel/umh.c
index bab134fa8c36..5cdcba6005d9 100644
--- a/kernel/umh.c
+++ b/kernel/umh.c
@@ -106,7 +106,7 @@ static int call_usermodehelper_exec_async(void *data)
commit_creds(new);
wait_for_initramfs();
- retval = kernel_execve(AT_FDCWD, sub_info->path,
+ retval = kernel_execve(sub_info->dirfd, sub_info->path,
(const char *const *)sub_info->argv,
(const char *const *)sub_info->envp);
out:
@@ -331,6 +331,7 @@ static void helper_unlock(void)
/**
* call_usermodehelper_setup - prepare to call a usermode helper
+ * @dirfd: directory to resolve path against
* @path: path to usermode executable
* @argv: arg vector for process
* @envp: environment for process
@@ -352,7 +353,7 @@ static void helper_unlock(void)
* Function must be runnable in either a process context or the
* context in which call_usermodehelper_exec is called.
*/
-struct subprocess_info *call_usermodehelper_setup(const char *path, char **argv,
+struct subprocess_info *call_usermodehelper_setup(int dirfd, const char *path, char **argv,
char **envp, gfp_t gfp_mask,
int (*init)(struct subprocess_info *info, struct cred *new),
void (*cleanup)(struct subprocess_info *info),
@@ -366,8 +367,10 @@ struct subprocess_info *call_usermodehelper_setup(const char *path, char **argv,
INIT_WORK(&sub_info->work, call_usermodehelper_exec_work);
#ifdef CONFIG_STATIC_USERMODEHELPER
+ sub_info->dirfd = AT_FDCWD;
sub_info->path = CONFIG_STATIC_USERMODEHELPER_PATH;
#else
+ sub_info->dirfd = dirfd;
sub_info->path = path;
#endif
sub_info->argv = argv;
@@ -484,7 +487,7 @@ int call_usermodehelper(const char *path, char **argv, char **envp, int wait)
struct subprocess_info *info;
gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
- info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
+ info = call_usermodehelper_setup(AT_FDCWD, path, argv, envp, gfp_mask,
NULL, NULL, NULL);
if (info == NULL)
return -ENOMEM;
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index ddbc4d7482d2..426ac83f1d2a 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -628,7 +628,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
goto exit;
retval = -ENOMEM;
- info = call_usermodehelper_setup(env->argv[0], env->argv,
+ info = call_usermodehelper_setup(AT_FDCWD, env->argv[0], env->argv,
env->envp, GFP_KERNEL,
NULL, cleanup_uevent_env, env);
if (info) {
diff --git a/security/keys/request_key.c b/security/keys/request_key.c
index a7673ad86d18..f6f3d4bc0bda 100644
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -101,7 +101,7 @@ static int call_usermodehelper_keys(const char *path, char **argv, char **envp,
{
struct subprocess_info *info;
- info = call_usermodehelper_setup(path, argv, envp, GFP_KERNEL,
+ info = call_usermodehelper_setup(AT_FDCWD, path, argv, envp, GFP_KERNEL,
umh_keys_init, umh_keys_cleanup,
session_keyring);
if (!info)
--
2.53.0
next prev parent reply other threads:[~2026-05-04 9:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 9:33 [PATCH v6 00/11] kunit: Introduce UAPI testing framework Thomas Weißschuh
2026-05-04 9:33 ` [PATCH v6 01/11] kbuild: doc: add label for userprogs section Thomas Weißschuh
2026-05-04 9:33 ` [PATCH v6 02/11] exec: add dirfd parameter to kernel_execve() Thomas Weißschuh
2026-05-04 9:33 ` Thomas Weißschuh [this message]
2026-05-04 9:33 ` [PATCH v6 04/11] mount: add support for __free(kern_unmount) Thomas Weißschuh
2026-05-04 9:33 ` [PATCH v6 05/11] init: add nolibc build support Thomas Weißschuh
2026-05-04 9:33 ` [PATCH v6 06/11] kunit: qemu_configs: loongarch: Enable LSX/LSAX Thomas Weißschuh
2026-05-04 9:33 ` [PATCH v6 07/11] kunit: Introduce UAPI testing framework Thomas Weißschuh
2026-05-04 9:33 ` [PATCH v6 08/11] kunit: uapi: Forward test executable output to KUnit log Thomas Weißschuh
2026-05-04 9:33 ` [PATCH v6 09/11] kunit: uapi: Add example for UAPI tests Thomas Weißschuh
2026-05-04 9:33 ` [PATCH v6 10/11] kunit: uapi: Introduce preinit executable Thomas Weißschuh
2026-05-04 9:33 ` [PATCH v6 11/11] kunit: uapi: Validate usability of /proc Thomas Weißschuh
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=20260504-kunit-kselftests-v6-3-712d3d526d97@linutronix.de \
--to=thomas.weissschuh@linutronix.de \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=chleroy@kernel.org \
--cc=corbet@lwn.net \
--cc=david@davidgow.net \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=kees@kernel.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@weissschuh.net \
--cc=mcgrof@kernel.org \
--cc=nathan@kernel.org \
--cc=nicolas.schier@linux.dev \
--cc=nsc@kernel.org \
--cc=raemoar63@gmail.com \
--cc=shuah@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=w@1wt.eu \
--cc=workflows@vger.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