Commit c290649e authored by Rusty Russell's avatar Rusty Russell Committed by Linus Torvalds

[PATCH] get rid of exec_usermodehelper, replace with call_usermodehelper

Urban Widmark points out that modprobe calls system() in many
configurations, which drops privs since request_module() doesn't
set ruid and rguid.

This gets rid of exec_usermodehelper and makes everyone use
call_usermodehelper, which has a new "wait" flag.
parent 817f3eee
...@@ -57,7 +57,7 @@ voyager_thread_start(void) ...@@ -57,7 +57,7 @@ voyager_thread_start(void)
} }
static int static int
execute_helper(void *string) execute(const char *string)
{ {
int ret; int ret;
...@@ -74,22 +74,13 @@ execute_helper(void *string) ...@@ -74,22 +74,13 @@ execute_helper(void *string)
NULL, NULL,
}; };
if((ret = exec_usermodehelper(argv[0], argv, envp)) < 0) { if ((ret = call_usermodehelper(argv[0], argv, envp, 1)) != 0) {
printk(KERN_ERR "Voyager failed to execute \"%s\"\n", printk(KERN_ERR "Voyager failed to run \"%s\": %i\n",
(char *)string); string, ret);
} }
return ret; return ret;
} }
static void
execute(char *string)
{
if(kernel_thread(execute_helper, (void *)string, CLONE_VFORK | SIGCHLD) < 0) {
printk(KERN_ERR "Voyager failed to fork before exec of \"%s\"\n",
string);
}
}
static void static void
check_from_kernel(void) check_from_kernel(void)
{ {
......
...@@ -436,7 +436,7 @@ acpi_thermal_call_usermode ( ...@@ -436,7 +436,7 @@ acpi_thermal_call_usermode (
envp[0] = "HOME=/"; envp[0] = "HOME=/";
envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
call_usermodehelper(argv[0], argv, envp); call_usermodehelper(argv[0], argv, envp, 0);
return_VALUE(0); return_VALUE(0);
} }
......
...@@ -114,7 +114,7 @@ static int do_hotplug (struct device *dev, char *argv1, const char *action, ...@@ -114,7 +114,7 @@ static int do_hotplug (struct device *dev, char *argv1, const char *action,
pr_debug ("%s: %s %s %s %s %s %s\n", __FUNCTION__, argv [0], argv[1], pr_debug ("%s: %s %s %s %s %s %s\n", __FUNCTION__, argv [0], argv[1],
envp[0], envp[1], envp[2], envp[3]); envp[0], envp[1], envp[2], envp[3]);
retval = call_usermodehelper (argv [0], argv, envp); retval = call_usermodehelper (argv [0], argv, envp, 0);
if (retval) if (retval)
pr_debug ("%s - call_usermodehelper returned %d\n", pr_debug ("%s - call_usermodehelper returned %d\n",
__FUNCTION__, retval); __FUNCTION__, retval);
......
...@@ -24,18 +24,14 @@ ...@@ -24,18 +24,14 @@
#include <linux/config.h> #include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
#define __KERNEL_SYSCALLS__
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/kmod.h> #include <linux/kmod.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/delay.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/unistd.h>
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
...@@ -405,7 +401,6 @@ void bt3c_interrupt(int irq, void *dev_inst, struct pt_regs *regs) ...@@ -405,7 +401,6 @@ void bt3c_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
/* ======================== HCI interface ======================== */ /* ======================== HCI interface ======================== */
...@@ -489,65 +484,23 @@ static int bt3c_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long ...@@ -489,65 +484,23 @@ static int bt3c_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long
#define FW_LOADER "/sbin/bluefw" #define FW_LOADER "/sbin/bluefw"
static int errno;
static int bt3c_fw_loader_exec(void *dev)
{
char *argv[] = { FW_LOADER, "pccard", dev, NULL };
char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
int err;
err = exec_usermodehelper(FW_LOADER, argv, envp);
if (err)
printk(KERN_WARNING "bt3c_cs: Failed to exec \"%s pccard %s\".\n", FW_LOADER, (char *)dev);
return err;
}
static int bt3c_firmware_load(bt3c_info_t *info) static int bt3c_firmware_load(bt3c_info_t *info)
{ {
sigset_t tmpsig;
char dev[16]; char dev[16];
pid_t pid; int err;
int result;
/* Check if root fs is mounted */ char *argv[] = { FW_LOADER, "pccard", dev, NULL };
if (!current->fs->root) { char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
printk(KERN_WARNING "bt3c_cs: Root filesystem is not mounted.\n");
return -EPERM;
}
sprintf(dev, "%04x", info->link.io.BasePort1); sprintf(dev, "%04x", info->link.io.BasePort1);
pid = kernel_thread(bt3c_fw_loader_exec, (void *)dev, 0); err = call_usermodehelper(FW_LOADER, argv, envp, 1);
if (pid < 0) { if (err)
printk(KERN_WARNING "bt3c_cs: Forking of kernel thread failed (errno=%d).\n", -pid); printk(KERN_WARNING "bt3c_cs: Failed to run \"%s pccard %s\" (errno=%d).\n", FW_LOADER, dev, err);
return pid;
}
/* Block signals, everything but SIGKILL/SIGSTOP */
spin_lock_irq(&current->sighand->siglock);
tmpsig = current->blocked;
siginitsetinv(&current->blocked, sigmask(SIGKILL) | sigmask(SIGSTOP));
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);
result = waitpid(pid, NULL, __WCLONE);
/* Allow signals again */
spin_lock_irq(&current->sighand->siglock);
current->blocked = tmpsig;
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);
if (result != pid) {
printk(KERN_WARNING "bt3c_cs: Waiting for pid %d failed (errno=%d).\n", pid, -result);
return -result;
}
return 0; return err;
} }
......
...@@ -786,7 +786,7 @@ static void nodemgr_call_policy(char *verb, struct unit_directory *ud) ...@@ -786,7 +786,7 @@ static void nodemgr_call_policy(char *verb, struct unit_directory *ud)
#ifdef CONFIG_IEEE1394_VERBOSEDEBUG #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
HPSB_DEBUG("NodeMgr: %s %s %016Lx", argv[0], verb, (long long unsigned)ud->ne->guid); HPSB_DEBUG("NodeMgr: %s %s %016Lx", argv[0], verb, (long long unsigned)ud->ne->guid);
#endif #endif
value = call_usermodehelper(argv[0], argv, envp); value = call_usermodehelper(argv[0], argv, envp, 0);
kfree(buf); kfree(buf);
kfree(envp); kfree(envp);
if (value != 0) if (value != 0)
......
...@@ -383,7 +383,7 @@ static void input_call_hotplug(char *verb, struct input_dev *dev) ...@@ -383,7 +383,7 @@ static void input_call_hotplug(char *verb, struct input_dev *dev)
argv[0], argv[1], envp[0], envp[1], envp[2], envp[3], envp[4]); argv[0], argv[1], envp[0], envp[1], envp[2], envp[3], envp[4]);
#endif #endif
value = call_usermodehelper(argv [0], argv, envp); value = call_usermodehelper(argv [0], argv, envp, 0);
kfree(buf); kfree(buf);
kfree(envp); kfree(envp);
......
...@@ -263,7 +263,7 @@ static void diva_adapter_trapped(void *context) ...@@ -263,7 +263,7 @@ static void diva_adapter_trapped(void *context)
pdpc->card_failed = 0; pdpc->card_failed = 0;
argv[2] = &adapter[0]; argv[2] = &adapter[0];
ret = call_usermodehelper(argv[0], argv, envp); ret = call_usermodehelper(argv[0], argv, envp, 0);
if (ret) { if (ret) {
printk(KERN_ERR printk(KERN_ERR
......
...@@ -369,15 +369,14 @@ static char eppconfig_path[256] = "/usr/sbin/eppfpga"; ...@@ -369,15 +369,14 @@ static char eppconfig_path[256] = "/usr/sbin/eppfpga";
static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/usr/bin:/bin", NULL }; static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/usr/bin:/bin", NULL };
static int errno; /* eppconfig: called during ifconfig up to configure the modem */
static int eppconfig(struct baycom_state *bc)
static int exec_eppfpga(void *b)
{ {
struct baycom_state *bc = (struct baycom_state *)b;
char modearg[256]; char modearg[256];
char portarg[16]; char portarg[16];
char *argv[] = { eppconfig_path, "-s", "-p", portarg, "-m", modearg, NULL}; char *argv[] = { eppconfig_path, "-s", "-p", portarg, "-m", modearg,
int i; NULL };
int ret;
/* set up arguments */ /* set up arguments */
sprintf(modearg, "%sclk,%smodem,fclk=%d,bps=%d,divider=%d%s,extstat", sprintf(modearg, "%sclk,%smodem,fclk=%d,bps=%d,divider=%d%s,extstat",
...@@ -388,39 +387,7 @@ static int exec_eppfpga(void *b) ...@@ -388,39 +387,7 @@ static int exec_eppfpga(void *b)
sprintf(portarg, "%ld", bc->pdev->port->base); sprintf(portarg, "%ld", bc->pdev->port->base);
printk(KERN_DEBUG "%s: %s -s -p %s -m %s\n", bc_drvname, eppconfig_path, portarg, modearg); printk(KERN_DEBUG "%s: %s -s -p %s -m %s\n", bc_drvname, eppconfig_path, portarg, modearg);
i = exec_usermodehelper(eppconfig_path, argv, envp); return call_usermodehelper(eppconfig_path, argv, envp, 1);
if (i < 0) {
printk(KERN_ERR "%s: failed to exec %s -s -p %s -m %s, errno = %d\n",
bc_drvname, eppconfig_path, portarg, modearg, i);
return i;
}
return 0;
}
/* eppconfig: called during ifconfig up to configure the modem */
static int eppconfig(struct baycom_state *bc)
{
int i, pid, r;
mm_segment_t fs;
pid = kernel_thread(exec_eppfpga, bc, CLONE_FS);
if (pid < 0) {
printk(KERN_ERR "%s: fork failed, errno %d\n", bc_drvname, -pid);
return pid;
}
fs = get_fs();
set_fs(KERNEL_DS); /* Allow i to be in kernel space. */
r = waitpid(pid, &i, __WCLONE);
set_fs(fs);
if (r != pid) {
printk(KERN_ERR "%s: waitpid(%d) failed, returning %d\n",
bc_drvname, pid, r);
return -1;
}
printk(KERN_DEBUG "%s: eppfpga returned %d\n", bc_drvname, i);
return i;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
......
...@@ -602,7 +602,7 @@ static int pnp_dock_event(int dock, struct pnp_docking_station_info *info) ...@@ -602,7 +602,7 @@ static int pnp_dock_event(int dock, struct pnp_docking_station_info *info)
info->location_id, info->serial, info->capabilities); info->location_id, info->serial, info->capabilities);
envp[i] = 0; envp[i] = 0;
value = call_usermodehelper (argv [0], argv, envp); value = call_usermodehelper (argv [0], argv, envp, 0);
kfree (buf); kfree (buf);
kfree (envp); kfree (envp);
return 0; return 0;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/config.h> #include <linux/config.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/compiler.h>
#ifdef CONFIG_KMOD #ifdef CONFIG_KMOD
extern int request_module(const char * name); extern int request_module(const char * name);
...@@ -29,8 +30,7 @@ static inline int request_module(const char * name) { return -ENOSYS; } ...@@ -29,8 +30,7 @@ static inline int request_module(const char * name) { return -ENOSYS; }
#endif #endif
#define try_then_request_module(x, mod) ((x) ?: request_module(mod), (x)) #define try_then_request_module(x, mod) ((x) ?: request_module(mod), (x))
extern int exec_usermodehelper(char *program_path, char *argv[], char *envp[]); extern int call_usermodehelper(char *path, char *argv[], char *envp[], int wait);
extern int call_usermodehelper(char *path, char *argv[], char *envp[]);
#ifdef CONFIG_HOTPLUG #ifdef CONFIG_HOTPLUG
extern char hotplug_path []; extern char hotplug_path [];
......
This diff is collapsed.
...@@ -114,7 +114,7 @@ static int hci_run_hotplug(char *dev, char *action) ...@@ -114,7 +114,7 @@ static int hci_run_hotplug(char *dev, char *action)
envp[3] = astr; envp[3] = astr;
envp[4] = NULL; envp[4] = NULL;
return call_usermodehelper(argv[0], argv, envp); return call_usermodehelper(argv[0], argv, envp, 0);
} }
#else #else
#define hci_run_hotplug(A...) #define hci_run_hotplug(A...)
......
...@@ -2942,6 +2942,6 @@ static int net_run_sbin_hotplug(struct net_device *dev, char *action) ...@@ -2942,6 +2942,6 @@ static int net_run_sbin_hotplug(struct net_device *dev, char *action)
envp [i++] = action_str; envp [i++] = action_str;
envp [i] = 0; envp [i] = 0;
return call_usermodehelper(argv [0], argv, envp); return call_usermodehelper(argv [0], argv, envp, 0);
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment