1. 01 5月, 2013 2 次提交
  2. 23 1月, 2013 1 次提交
    • T
      async, kmod: warn on synchronous request_module() from async workers · 0fdff3ec
      Tejun Heo 提交于
      Synchronous requet_module() from an async worker can lead to deadlock
      because module init path may invoke async_synchronize_full().  The
      async worker waits for request_module() to complete and the module
      loading waits for the async task to finish.  This bug happened in the
      block layer because of default elevator auto-loading.
      
      Block layer has been updated not to do default elevator auto-loading
      and it has been decided to disallow synchronous request_module() from
      async workers.
      
      Trigger WARN_ON_ONCE() on synchronous request_module() from async
      workers.
      
      For more details, please refer to the following thread.
      
        http://thread.gmane.org/gmane.linux.kernel/1420814Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NAlex Riesen <raa.lkml@gmail.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Arjan van de Ven <arjan@linux.intel.com>
      0fdff3ec
  3. 20 12月, 2012 1 次提交
  4. 13 10月, 2012 1 次提交
    • A
      infrastructure for saner ret_from_kernel_thread semantics · a74fb73c
      Al Viro 提交于
      * allow kernel_execve() leave the actual return to userland to
      caller (selected by CONFIG_GENERIC_KERNEL_EXECVE).  Callers
      updated accordingly.
      * architecture that does select GENERIC_KERNEL_EXECVE in its
      Kconfig should have its ret_from_kernel_thread() do this:
      	call schedule_tail
      	call the callback left for it by copy_thread(); if it ever
      returns, that's because it has just done successful kernel_execve()
      	jump to return from syscall
      IOW, its only difference from ret_from_fork() is that it does call the
      callback.
      * such an architecture should also get rid of ret_from_kernel_execve()
      and __ARCH_WANT_KERNEL_EXECVE
      
      This is the last part of infrastructure patches in that area - from
      that point on work on different architectures can live independently.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      a74fb73c
  5. 12 10月, 2012 1 次提交
    • A
      make sure that kernel_thread() callbacks call do_exit() themselves · fb45550d
      Al Viro 提交于
      Most of them never returned anyway - only two functions had to be
      changed.  That allows to simplify their callers a whole lot.
      
      Note that this does *not* apply to kthread_run() callbacks - all of
      those had been called from the same kernel_thread() callback, which
      did do_exit() already.  This is strictly about very few low-level
      kernel_thread() callbacks (there are only 6 of those, mostly as part
      of kthread.h and kmod.h exported mechanisms, plus kernel_init()
      itself).
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      fb45550d
  6. 31 7月, 2012 2 次提交
    • T
      kmod: avoid deadlock from recursive kmod call · 0f20784d
      Tetsuo Handa 提交于
      The system deadlocks (at least since 2.6.10) when
      call_usermodehelper(UMH_WAIT_EXEC) request triggers
      call_usermodehelper(UMH_WAIT_PROC) request.
      
      This is because "khelper thread is waiting for the worker thread at
      wait_for_completion() in do_fork() since the worker thread was created
      with CLONE_VFORK flag" and "the worker thread cannot call complete()
      because do_execve() is blocked at UMH_WAIT_PROC request" and "the khelper
      thread cannot start processing UMH_WAIT_PROC request because the khelper
      thread is waiting for the worker thread at wait_for_completion() in
      do_fork()".
      
      The easiest example to observe this deadlock is to use a corrupted
      /sbin/hotplug binary (like shown below).
      
        # : > /tmp/dummy
        # chmod 755 /tmp/dummy
        # echo /tmp/dummy > /proc/sys/kernel/hotplug
        # modprobe whatever
      
      call_usermodehelper("/tmp/dummy", UMH_WAIT_EXEC) is called from
      kobject_uevent_env() in lib/kobject_uevent.c upon loading/unloading a
      module.  do_execve("/tmp/dummy") triggers a call to
      request_module("binfmt-0000") from search_binary_handler() which in turn
      calls call_usermodehelper(UMH_WAIT_PROC).
      
      In order to avoid deadlock, as a for-now and easy-to-backport solution, do
      not try to call wait_for_completion() in call_usermodehelper_exec() if the
      worker thread was created by khelper thread with CLONE_VFORK flag.  Future
      and fundamental solution might be replacing singleton khelper thread with
      some workqueue so that recursive calls up to max_active dependency loop
      can be handled without deadlock.
      
      [akpm@linux-foundation.org: add comment to kmod_thread_locker]
      Signed-off-by: NTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Cc: Arjan van de Ven <arjan@linux.intel.com>
      Acked-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      0f20784d
    • A
      kernel/kmod.c: document call_usermodehelper_fns() a bit · 79c743dd
      Andrew Morton 提交于
      This function's interface is, uh, subtle.  Attempt to apologise for it.
      
      Cc: WANG Cong <xiyou.wangcong@gmail.com>
      Cc: Cyrill Gorcunov <gorcunov@openvz.org>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Serge Hallyn <serge.hallyn@canonical.com>
      Cc: "Eric W. Biederman" <ebiederm@xmission.com>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      79c743dd
  7. 01 6月, 2012 3 次提交
  8. 29 3月, 2012 3 次提交
    • R
      PM / Sleep: Mitigate race between the freezer and request_firmware() · 247bc037
      Rafael J. Wysocki 提交于
      There is a race condition between the freezer and request_firmware()
      such that if request_firmware() is run on one CPU and
      freeze_processes() is run on another CPU and usermodehelper_disable()
      called by it succeeds to grab umhelper_sem for writing before
      usermodehelper_read_trylock() called from request_firmware()
      acquires it for reading, the request_firmware() will fail and
      trigger a WARN_ON() complaining that it was called at a wrong time.
      However, in fact, it wasn't called at a wrong time and
      freeze_processes() simply happened to be executed simultaneously.
      
      To avoid this race, at least in some cases, modify
      usermodehelper_read_trylock() so that it doesn't fail if the
      freezing of tasks has just started and hasn't been completed yet.
      Instead, during the freezing of tasks, it will try to freeze the
      task that has called it so that it can wait until user space is
      thawed without triggering the scary warning.
      
      For this purpose, change usermodehelper_disabled so that it can
      take three different values, UMH_ENABLED (0), UMH_FREEZING and
      UMH_DISABLED.  The first one means that usermode helpers are
      enabled, the last one means "hard disable" (i.e. the system is not
      ready for usermode helpers to be used) and the second one
      is reserved for the freezer.  Namely, when freeze_processes() is
      started, it sets usermodehelper_disabled to UMH_FREEZING which
      tells usermodehelper_read_trylock() that it shouldn't fail just
      yet and should call try_to_freeze() if woken up and cannot
      return immediately.  This way all freezable tasks that happen
      to call request_firmware() right before freeze_processes() is
      started and lose the race for umhelper_sem with it will be
      frozen and will sleep until thaw_processes() unsets
      usermodehelper_disabled.  [For the non-freezable callers of
      request_firmware() the race for umhelper_sem against
      freeze_processes() is unfortunately unavoidable.]
      Reported-by: NStephen Boyd <sboyd@codeaurora.org>
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: stable@vger.kernel.org
      247bc037
    • R
      firmware_class: Do not warn that system is not ready from async loads · 9b78c1da
      Rafael J. Wysocki 提交于
      If firmware is requested asynchronously, by calling
      request_firmware_nowait(), there is no reason to fail the request
      (and warn the user) when the system is (presumably temporarily)
      unready to handle it (because user space is not available yet or
      frozen).  For this reason, introduce an alternative routine for
      read-locking umhelper_sem, usermodehelper_read_lock_wait(), that
      will wait for usermodehelper_disabled to be unset (possibly with
      a timeout) and make request_firmware_work_func() use it instead of
      usermodehelper_read_trylock().
      
      Accordingly, modify request_firmware() so that it uses
      usermodehelper_read_trylock() to acquire umhelper_sem and remove
      the code related to that lock from _request_firmware().
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: stable@vger.kernel.org
      9b78c1da
    • R
      firmware_class: Rework usermodehelper check · fe2e39d8
      Rafael J. Wysocki 提交于
      Instead of two functions, read_lock_usermodehelper() and
      usermodehelper_is_disabled(), used in combination, introduce
      usermodehelper_read_trylock() that will only return with umhelper_sem
      held if usermodehelper_disabled is unset (and will return -EAGAIN
      otherwise) and make _request_firmware() use it.
      
      Rename read_unlock_usermodehelper() to
      usermodehelper_read_unlock() to follow the naming convention of the
      new function.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: stable@vger.kernel.org
      fe2e39d8
  9. 24 3月, 2012 6 次提交
  10. 10 12月, 2011 1 次提交
    • S
      PM / Sleep: Fix freezer failures due to racy usermodehelper_is_disabled() · b298d289
      Srivatsa S. Bhat 提交于
      Commit a144c6a6 (PM: Print a warning if firmware is requested when tasks
      are frozen) introduced usermodehelper_is_disabled() to warn and exit
      immediately if firmware is requested when usermodehelpers are disabled.
      
      However, it is racy. Consider the following scenario, currently used in
      drivers/base/firmware_class.c:
      
      ...
      if (usermodehelper_is_disabled())
              goto out;
      
      /* Do actual work */
      ...
      
      out:
              return err;
      
      Nothing prevents someone from disabling usermodehelpers just after the check
      in the 'if' condition, which means that it is quite possible to try doing the
      "actual work" with usermodehelpers disabled, leading to undesirable
      consequences.
      
      In particular, this race condition in _request_firmware() causes task freezing
      failures whenever suspend/hibernation is in progress because, it wrongly waits
      to get the firmware/microcode image from userspace when actually the
      usermodehelpers are disabled or userspace has been frozen.
      Some of the example scenarios that cause freezing failures due to this race
      are those that depend on userspace via request_firmware(), such as x86
      microcode module initialization and microcode image reload.
      
      Previous discussions about this issue can be found at:
      http://thread.gmane.org/gmane.linux.kernel/1198291/focus=1200591
      
      This patch adds proper synchronization to fix this issue.
      
      It is to be noted that this patchset fixes the freezing failures but doesn't
      remove the warnings. IOW, it does not attempt to add explicit synchronization
      to x86 microcode driver to avoid requesting microcode image at inopportune
      moments. Because, the warnings were introduced to highlight such cases, in the
      first place. And we need not silence the warnings, since we take care of the
      *real* problem (freezing failure) and hence, after that, the warnings are
      pretty harmless anyway.
      Signed-off-by: NSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      b298d289
  11. 24 11月, 2011 1 次提交
  12. 26 10月, 2011 1 次提交
  13. 04 8月, 2011 1 次提交
    • L
      Boot up with usermodehelper disabled · 288d5abe
      Linus Torvalds 提交于
      The core device layer sends tons of uevent notifications for each device
      it finds, and if the kernel has been built with a non-empty
      CONFIG_UEVENT_HELPER_PATH that will make us try to execute the usermode
      helper binary for all these events very early in the boot.
      
      Not only won't the root filesystem even be mounted at that point, we
      literally won't have necessarily even initialized all the process
      handling data structures at that point, which causes no end of silly
      problems even when the usermode helper doesn't actually succeed in
      executing.
      
      So just use our existing infrastructure to disable the usermodehelpers
      to make the kernel start out with them disabled.  We enable them when
      we've at least initialized stuff a bit.
      
      Problems related to an uninitialized
      
      	init_ipc_ns.ids[IPC_SHM_IDS].rw_mutex
      
      reported by various people.
      Reported-by: NManuel Lauss <manuel.lauss@googlemail.com>
      Reported-by: NRichard Weinberger <richard@nod.at>
      Reported-by: NMarc Zyngier <maz@misterjones.org>
      Acked-by: NKay Sievers <kay.sievers@vrfy.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Vasiliy Kulikov <segoon@openwall.com>
      Cc: Greg KH <greg@kroah.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      288d5abe
  14. 18 6月, 2011 1 次提交
    • D
      KEYS/DNS: Fix ____call_usermodehelper() to not lose the session keyring · 87966996
      David Howells 提交于
      ____call_usermodehelper() now erases any credentials set by the
      subprocess_inf::init() function.  The problem is that commit
      17f60a7d ("capabilites: allow the application of capability limits
      to usermode helpers") creates and commits new credentials with
      prepare_kernel_cred() after the call to the init() function.  This wipes
      all keyrings after umh_keys_init() is called.
      
      The best way to deal with this is to put the init() call just prior to
      the commit_creds() call, and pass the cred pointer to init().  That
      means that umh_keys_init() and suchlike can modify the credentials
      _before_ they are published and potentially in use by the rest of the
      system.
      
      This prevents request_key() from working as it is prevented from passing
      the session keyring it set up with the authorisation token to
      /sbin/request-key, and so the latter can't assume the authority to
      instantiate the key.  This causes the in-kernel DNS resolver to fail
      with ENOKEY unconditionally.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NEric Paris <eparis@redhat.com>
      Tested-by: NJeff Layton <jlayton@redhat.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      87966996
  15. 18 5月, 2011 2 次提交
  16. 04 4月, 2011 1 次提交
    • E
      capabilites: allow the application of capability limits to usermode helpers · 17f60a7d
      Eric Paris 提交于
      There is no way to limit the capabilities of usermodehelpers. This problem
      reared its head recently when someone complained that any user with
      cap_net_admin was able to load arbitrary kernel modules, even though the user
      didn't have cap_sys_module.  The reason is because the actual load is done by
      a usermode helper and those always have the full cap set.  This patch addes new
      sysctls which allow us to bound the permissions of usermode helpers.
      
      /proc/sys/kernel/usermodehelper/bset
      /proc/sys/kernel/usermodehelper/inheritable
      
      You must have CAP_SYS_MODULE  and CAP_SETPCAP to change these (changes are
      &= ONLY).  When the kernel launches a usermodehelper it will do so with these
      as the bset and pI.
      
      -v2:	make globals static
      	create spinlock to protect globals
      
      -v3:	require both CAP_SETPCAP and CAP_SYS_MODULE
      -v4:	fix the typo s/CAP_SET_PCAP/CAP_SETPCAP/ because I didn't commit
      Signed-off-by: NEric Paris <eparis@redhat.com>
      No-objection-from: Serge E. Hallyn <serge.hallyn@canonical.com>
      Acked-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NSerge E. Hallyn <serge.hallyn@canonical.com>
      Acked-by: NAndrew G. Morgan <morgan@kernel.org>
      Signed-off-by: NJames Morris <jmorris@namei.org>
      17f60a7d
  17. 18 8月, 2010 1 次提交
    • D
      Make do_execve() take a const filename pointer · d7627467
      David Howells 提交于
      Make do_execve() take a const filename pointer so that kernel_execve() compiles
      correctly on ARM:
      
      arch/arm/kernel/sys_arm.c:88: warning: passing argument 1 of 'do_execve' discards qualifiers from pointer target type
      
      This also requires the argv and envp arguments to be consted twice, once for
      the pointer array and once for the strings the array points to.  This is
      because do_execve() passes a pointer to the filename (now const) to
      copy_strings_kernel().  A simpler alternative would be to cast the filename
      pointer in do_execve() when it's passed to copy_strings_kernel().
      
      do_execve() may not change any of the strings it is passed as part of the argv
      or envp lists as they are some of them in .rodata, so marking these strings as
      const should be fine.
      
      Further kernel_execve() and sys_execve() need to be changed to match.
      
      This has been test built on x86_64, frv, arm and mips.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Tested-by: NRalf Baechle <ralf@linux-mips.org>
      Acked-by: NRussell King <rmk+kernel@arm.linux.org.uk>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      d7627467
  18. 28 5月, 2010 8 次提交
    • O
      call_usermodehelper: UMH_WAIT_EXEC ignores kernel_thread() failure · 04b1c384
      Oleg Nesterov 提交于
      UMH_WAIT_EXEC should report the error if kernel_thread() fails, like
      UMH_WAIT_PROC does.
      Signed-off-by: NOleg Nesterov <oleg@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      04b1c384
    • O
      call_usermodehelper: simplify/fix UMH_NO_WAIT case · d47419cd
      Oleg Nesterov 提交于
      __call_usermodehelper(UMH_NO_WAIT) has 2 problems:
      
      	- if kernel_thread() fails, call_usermodehelper_freeinfo()
      	  is not called.
      
      	- for unknown reason UMH_NO_WAIT has UMH_WAIT_PROC logic,
      	  we spawn yet another thread which waits until the user
      	  mode application exits.
      
      Change the UMH_NO_WAIT code to use ____call_usermodehelper() instead of
      wait_for_helper(), and do call_usermodehelper_freeinfo() unconditionally.
      We can rely on CLONE_VFORK, do_fork(CLONE_VFORK) until the child exits or
      execs.
      
      With or without this patch UMH_NO_WAIT does not report the error if
      kernel_thread() fails, this is correct since the caller doesn't wait for
      result.
      Signed-off-by: NOleg Nesterov <oleg@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      d47419cd
    • O
      wait_for_helper: SIGCHLD from user-space can lead to use-after-free · 7d642242
      Oleg Nesterov 提交于
      1. wait_for_helper() calls allow_signal(SIGCHLD) to ensure the child
         can't autoreap itself.
      
         However, this means that a spurious SIGCHILD from user-space can
         set TIF_SIGPENDING and:
      
         	- kernel_thread() or sys_wait4() can fail due to signal_pending()
      
         	- worse, wait4() can fail before ____call_usermodehelper() execs
         	  or exits. In this case the caller may kfree(subprocess_info)
         	  while the child still uses this memory.
      
         Change the code to use SIG_DFL instead of magic "(void __user *)2"
         set by allow_signal(). This means that SIGCHLD won't be delivered,
         yet the child won't autoreap itsefl.
      
         The problem is minor, only root can send a signal to this kthread.
      
      2. If sys_wait4(&ret) fails it doesn't populate "ret", in this case
         wait_for_helper() reports a random value from uninitialized var.
      
         With this patch sys_wait4() should never fail, but still it makes
         sense to initialize ret = -ECHILD so that the caller can notice
         the problem.
      Signed-off-by: NOleg Nesterov <oleg@redhat.com>
      Acked-by: NNeil Horman <nhorman@tuxdriver.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      7d642242
    • O
      call_usermodehelper: no need to unblock signals · 363da402
      Oleg Nesterov 提交于
      ____call_usermodehelper() correctly calls flush_signal_handlers() to set
      SIG_DFL, but sigemptyset(->blocked) and recalc_sigpending() are not
      needed.
      
      This kthread was forked by workqueue thread, all signals must be unblocked
      and ignored, no pending signal is possible.
      Signed-off-by: NOleg Nesterov <oleg@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      363da402
    • O
      umh: creds: kill subprocess_info->cred logic · c70a626d
      Oleg Nesterov 提交于
      Now that nobody ever changes subprocess_info->cred we can kill this member
      and related code.  ____call_usermodehelper() always runs in the context of
      freshly forked kernel thread, it has the proper ->cred copied from its
      parent kthread, keventd.
      Signed-off-by: NOleg Nesterov <oleg@redhat.com>
      Acked-by: NNeil Horman <nhorman@tuxdriver.com>
      Acked-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c70a626d
    • O
      umh: creds: convert call_usermodehelper_keys() to use subprocess_info->init() · 685bfd2c
      Oleg Nesterov 提交于
      call_usermodehelper_keys() uses call_usermodehelper_setkeys() to change
      subprocess_info->cred in advance.  Now that we have info->init() we can
      change this code to set tgcred->session_keyring in context of execing
      kernel thread.
      
      Note: since currently call_usermodehelper_keys() is never called with
      UMH_NO_WAIT, call_usermodehelper_keys()->key_get() and umh_keys_cleanup()
      are not really needed, we could rely on install_session_keyring_to_cred()
      which does key_get() on success.
      Signed-off-by: NOleg Nesterov <oleg@redhat.com>
      Acked-by: NNeil Horman <nhorman@tuxdriver.com>
      Acked-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      685bfd2c
    • N
      exec: replace call_usermodehelper_pipe with use of umh init function and resolve limit · 898b374a
      Neil Horman 提交于
      The first patch in this series introduced an init function to the
      call_usermodehelper api so that processes could be customized by caller.
      This patch takes advantage of that fact, by customizing the helper in
      do_coredump to create the pipe and set its core limit to one (for our
      recusrsion check).  This lets us clean up the previous uglyness in the
      usermodehelper internals and factor call_usermodehelper out entirely.
      While I'm at it, we can also modify the helper setup to look for a core
      limit value of 1 rather than zero for our recursion check
      Signed-off-by: NNeil Horman <nhorman@tuxdriver.com>
      Reviewed-by: NOleg Nesterov <oleg@redhat.com>
      Cc: Andi Kleen <andi@firstfloor.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      898b374a
    • N
      kmod: add init function to usermodehelper · a06a4dc3
      Neil Horman 提交于
      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: NNeil Horman <nhorman@tuxdriver.com>
      Reviewed-by: NOleg Nesterov <oleg@redhat.com>
      Cc: Andi Kleen <andi@firstfloor.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      a06a4dc3
  19. 12 1月, 2010 1 次提交
    • M
      kmod: fix resource leak in call_usermodehelper_pipe() · 8767ba27
      Masami Hiramatsu 提交于
      Fix resource (write-pipe file) leak in call_usermodehelper_pipe().
      
      When call_usermodehelper_exec() fails, write-pipe file is opened and
      call_usermodehelper_pipe() just returns an error.  Since it is hard for
      caller to determine whether the error occured when opening the pipe or
      executing the helper, the caller cannot close the pipe by themselves.
      
      I've found this resoruce leak when testing coredump.  You can check how
      the resource leaks as below;
      
      $ echo "|nocommand" > /proc/sys/kernel/core_pattern
      $ ulimit -c unlimited
      $ while [ 1 ]; do ./segv; done &> /dev/null &
      $ cat /proc/meminfo (<- repeat it)
      
      where segv.c is;
      //-----
      int main () {
              char *p = 0;
              *p = 1;
      }
      //-----
      
      This patch closes write-pipe file if call_usermodehelper_exec() failed.
      Signed-off-by: NMasami Hiramatsu <mhiramat@redhat.com>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      8767ba27
  20. 10 11月, 2009 1 次提交
    • E
      security: report the module name to security_module_request · dd8dbf2e
      Eric Paris 提交于
      For SELinux to do better filtering in userspace we send the name of the
      module along with the AVC denial when a program is denied module_request.
      
      Example output:
      
      type=SYSCALL msg=audit(11/03/2009 10:59:43.510:9) : arch=x86_64 syscall=write success=yes exit=2 a0=3 a1=7fc28c0d56c0 a2=2 a3=7fffca0d7440 items=0 ppid=1727 pid=1729 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=rpc.nfsd exe=/usr/sbin/rpc.nfsd subj=system_u:system_r:nfsd_t:s0 key=(null)
      type=AVC msg=audit(11/03/2009 10:59:43.510:9) : avc:  denied  { module_request } for  pid=1729 comm=rpc.nfsd kmod="net-pf-10" scontext=system_u:system_r:nfsd_t:s0 tcontext=system_u:system_r:kernel_t:s0 tclass=system
      Signed-off-by: NEric Paris <eparis@redhat.com>
      Signed-off-by: NJames Morris <jmorris@namei.org>
      dd8dbf2e
  21. 24 9月, 2009 1 次提交
    • S
      Revert "kmod: fix race in usermodehelper code" · 95e0d86b
      Sebastian Andrzej Siewior 提交于
      This reverts commit c02e3f36 ("kmod: fix race in usermodehelper code")
      
      The patch is wrong.  UMH_WAIT_EXEC is called with VFORK what ensures
      that the child finishes prior returing back to the parent.  No race.
      
      In fact, the patch makes it even worse because it does the thing it
      claims not do:
      
       - It calls ->complete() on UMH_WAIT_EXEC
      
       - the complete() callback may de-allocated subinfo as seen in the
         following call chain:
      
          [<c009f904>] (__link_path_walk+0x20/0xeb4) from [<c00a094c>] (path_walk+0x48/0x94)
          [<c00a094c>] (path_walk+0x48/0x94) from [<c00a0a34>] (do_path_lookup+0x24/0x4c)
          [<c00a0a34>] (do_path_lookup+0x24/0x4c) from [<c00a158c>] (do_filp_open+0xa4/0x83c)
          [<c00a158c>] (do_filp_open+0xa4/0x83c) from [<c009ba90>] (open_exec+0x24/0xe0)
          [<c009ba90>] (open_exec+0x24/0xe0) from [<c009bfa8>] (do_execve+0x7c/0x2e4)
          [<c009bfa8>] (do_execve+0x7c/0x2e4) from [<c0026a80>] (kernel_execve+0x34/0x80)
          [<c0026a80>] (kernel_execve+0x34/0x80) from [<c004b514>] (____call_usermodehelper+0x130/0x148)
          [<c004b514>] (____call_usermodehelper+0x130/0x148) from [<c0024858>] (kernel_thread_exit+0x0/0x8)
      
         and the path pointer was NULL.  Good that ARM's kernel_execve()
         doesn't check the pointer for NULL or else I wouldn't notice it.
      
      The only race there might be is with UMH_NO_WAIT but it is too late for
      me to investigate it now.  UMH_WAIT_PROC could probably also use VFORK
      and we could save one exec.  So the only race I see is with UMH_NO_WAIT
      and recent scheduler changes where the child does not always run first
      might have trigger here something but as I said, it is late....
      Signed-off-by: NSebastian Andrzej Siewior <sebastian@breakpoint.cc>
      Acked-by: NNeil Horman <nhorman@tuxdriver.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      95e0d86b