2005-04-17 06:20:36 +08:00
|
|
|
#ifndef __LINUX_KMOD_H__
|
|
|
|
#define __LINUX_KMOD_H__
|
|
|
|
|
|
|
|
/*
|
|
|
|
* include/linux/kmod.h
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2017-09-09 07:17:08 +08:00
|
|
|
#include <linux/umh.h>
|
2008-07-25 16:45:38 +08:00
|
|
|
#include <linux/gfp.h>
|
2005-06-24 13:00:51 +08:00
|
|
|
#include <linux/stddef.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/compiler.h>
|
kmod: add init function to usermodehelper
About 6 months ago, I made a set of changes to how the core-dump-to-a-pipe
feature in the kernel works. We had reports of several races, including
some reports of apps bypassing our recursion check so that a process that
was forked as part of a core_pattern setup could infinitely crash and
refork until the system crashed.
We fixed those by improving our recursion checks. The new check basically
refuses to fork a process if its core limit is zero, which works well.
Unfortunately, I've been getting grief from maintainer of user space
programs that are inserted as the forked process of core_pattern. They
contend that in order for their programs (such as abrt and apport) to
work, all the running processes in a system must have their core limits
set to a non-zero value, to which I say 'yes'. I did this by design, and
think thats the right way to do things.
But I've been asked to ease this burden on user space enough times that I
thought I would take a look at it. The first suggestion was to make the
recursion check fail on a non-zero 'special' number, like one. That way
the core collector process could set its core size ulimit to 1, and enable
the kernel's recursion detection. This isn't a bad idea on the surface,
but I don't like it since its opt-in, in that if a program like abrt or
apport has a bug and fails to set such a core limit, we're left with a
recursively crashing system again.
So I've come up with this. What I've done is modify the
call_usermodehelper api such that an extra parameter is added, a function
pointer which will be called by the user helper task, after it forks, but
before it exec's the required process. This will give the caller the
opportunity to get a call back in the processes context, allowing it to do
whatever it needs to to the process in the kernel prior to exec-ing the
user space code. In the case of do_coredump, this callback is ues to set
the core ulimit of the helper process to 1. This elimnates the opt-in
problem that I had above, as it allows the ulimit for core sizes to be set
to the value of 1, which is what the recursion check looks for in
do_coredump.
This patch:
Create new function call_usermodehelper_fns() and allow it to assign both
an init and cleanup function, as we'll as arbitrary data.
The init function is called from the context of the forked process and
allows for customization of the helper process prior to calling exec. Its
return code gates the continuation of the process, or causes its exit.
Also add an arbitrary data pointer to the subprocess_info struct allowing
for data to be passed from the caller to the new process, and the
subsequent cleanup process
Also, use this patch to cleanup the cleanup function. It currently takes
an argp and envp pointer for freeing, which is ugly. Lets instead just
make the subprocess_info structure public, and pass that to the cleanup
and init routines
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-27 05:42:58 +08:00
|
|
|
#include <linux/workqueue.h>
|
2011-04-02 05:07:50 +08:00
|
|
|
#include <linux/sysctl.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define KMOD_PATH_LEN 256
|
|
|
|
|
2008-07-09 01:00:17 +08:00
|
|
|
#ifdef CONFIG_MODULES
|
2010-03-11 07:24:06 +08:00
|
|
|
extern char modprobe_path[]; /* for sysctl */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* modprobe exit status on success, -ve on error. Return value
|
|
|
|
* usually useless though. */
|
2011-11-01 08:11:33 +08:00
|
|
|
extern __printf(2, 3)
|
|
|
|
int __request_module(bool wait, const char *name, ...);
|
2009-02-09 02:42:01 +08:00
|
|
|
#define request_module(mod...) __request_module(true, mod)
|
|
|
|
#define request_module_nowait(mod...) __request_module(false, mod)
|
|
|
|
#define try_then_request_module(x, mod...) \
|
2009-04-09 10:35:47 +08:00
|
|
|
((x) ?: (__request_module(true, mod), (x)))
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
2009-02-09 02:42:01 +08:00
|
|
|
static inline int request_module(const char *name, ...) { return -ENOSYS; }
|
|
|
|
static inline int request_module_nowait(const char *name, ...) { return -ENOSYS; }
|
2008-07-09 01:00:18 +08:00
|
|
|
#define try_then_request_module(x, mod...) (x)
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __LINUX_KMOD_H__ */
|