public inbox for kernel-hardening@lists.openwall.com
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Vasiliy Kulikov <segoon@openwall.com>,
	Manuel Lauss <manuel.lauss@googlemail.com>,
	linux-kernel@vger.kernel.org, Richard Weinberger <richard@nod.at>,
	Marc Zyngier <maz@misterjones.org>, Ingo Molnar <mingo@elte.hu>,
	kernel-hardening@lists.openwall.com,
	"Paul E. McKenney" <paul.mckenney@linaro.org>,
	Kay Sievers <kay.sievers@vrfy.org>
Subject: [kernel-hardening] Re: [PATCH] shm: fix a race between shm_exit() and shm_init()
Date: Wed, 3 Aug 2011 12:33:52 -0700	[thread overview]
Message-ID: <20110803123352.88670c9c.akpm@linux-foundation.org> (raw)
In-Reply-To: <CA+55aFx_FMg2Y0jMrzYUpAqgxWFjxnFzzrqvysoqrYyz+Ue6BQ@mail.gmail.com>

On Tue, 2 Aug 2011 21:43:23 -1000
Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Tue, Aug 2, 2011 at 2:45 AM, Vasiliy Kulikov <segoon@openwall.com> wrote:
> >
> > From: Vasiliy Kulikov <segoon@openwall.com>
> > Subject: [PATCH] shm: fix a race between shm_exit() and shm_init()
> 
> This patch is disgusting.
> 

I think it's buggy too.

> 
> > +       /*
> > +        * For init_ipc_ns shm_ids().rw_mutex is statically initialized
> > +        * as kernel threads should be able to use it in do_exit() before
> > +        * shm_init(), which is called on do_initcall()
> > +        */
> > +       if (ns == &init_ipc_ns)
> > +                ipc_init_ids(&shm_ids(ns));
> > +       else
> > +               ipc_init_ids(&shm_ids(ns));

afacit init_ipc_ns.ids[0].rw_mutex and init_ipc_ns.ids[1].rw_mutex
never get initialised with this patch?


Still.  It seems that the real bug is that driver_init() is trying to
invoke userspace helpers before the kernel is ready to run userspace.

We could hack around it with something like

--- a/init/main.c~a
+++ a/init/main.c
@@ -108,6 +108,9 @@ bool early_boot_irqs_disabled __read_mos
 enum system_states system_state __read_mostly;
 EXPORT_SYMBOL(system_state);
 
+/* This gets set when the kernel is ready to execute usermode code */
+bool usermode_available = false;
+
 /*
  * Boot command-line arguments
  */
@@ -804,6 +807,8 @@ static int __init kernel_init(void * unu
 
 	do_basic_setup();
 
+	usermode_available = true;
+
 	/* Open the /dev/console on the rootfs, this should never fail */
 	if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
 		printk(KERN_WARNING "Warning: unable to open an initial console.\n");
diff -puN include/linux/init.h~a include/linux/init.h
--- a/include/linux/init.h~a
+++ a/include/linux/init.h
@@ -149,6 +149,7 @@ extern int do_one_initcall(initcall_t fn
 extern char __initdata boot_command_line[];
 extern char *saved_command_line;
 extern unsigned int reset_devices;
+extern bool usermode_available;
 
 /* used by init/main.c */
 void setup_arch(char **);
diff -puN kernel/kmod.c~a kernel/kmod.c
--- a/kernel/kmod.c~a
+++ a/kernel/kmod.c
@@ -418,6 +418,9 @@ int call_usermodehelper_exec(struct subp
 	DECLARE_COMPLETION_ONSTACK(done);
 	int retval = 0;
 
+	if (usermode_available == false)
+		return -EINVAL;
+
 	helper_lock();
 	if (sub_info->path[0] == '\0')
 		goto out;
_


(which I think deserves a big fat WARN_ON() when it triggers)

But it would be better to fix driver_init() for real.

Save us, Kay!

  parent reply	other threads:[~2011-08-03 19:33 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-01 18:01 [kernel-hardening] initcall dependency problem (ns vs. threads) Vasiliy Kulikov
2011-08-01 18:20 ` [kernel-hardening] " Andrew Morton
2011-08-01 18:34   ` Vasiliy Kulikov
2011-08-01 19:03   ` Vasiliy Kulikov
2011-08-01 19:07     ` Andrew Morton
2011-08-01 19:22       ` Vasiliy Kulikov
2011-08-02  0:01     ` Linus Torvalds
2011-08-02 12:45       ` [kernel-hardening] [PATCH] shm: fix a race between shm_exit() and shm_init() Vasiliy Kulikov
2011-08-02 12:51         ` [kernel-hardening] " Manuel Lauss
2011-08-02 13:23         ` Richard Weinberger
2011-08-02 13:29         ` Marc Zyngier
2011-08-02 20:33         ` Andrew Morton
2011-08-02 20:55         ` Andrew Morton
2011-08-03  5:30           ` Manuel Lauss
2011-08-03  8:05           ` Marc Zyngier
2011-08-03  8:19             ` Linus Torvalds
2011-08-03 10:04               ` Manuel Lauss
2011-08-03 10:30               ` Marc Zyngier
2011-08-04  0:35                 ` Linus Torvalds
2011-08-04  0:50                   ` Andrew Morton
2011-08-04  1:01                     ` Linus Torvalds
2011-08-04  1:15                       ` Kay Sievers
2011-08-04  8:26                   ` Marc Zyngier
2011-08-03  7:43         ` Linus Torvalds
2011-08-03  7:50           ` Manuel Lauss
2011-08-03  8:00             ` Manuel Lauss
2011-08-03 19:33           ` Andrew Morton [this message]
2011-08-03 19:52             ` Vasiliy Kulikov

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=20110803123352.88670c9c.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=kay.sievers@vrfy.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manuel.lauss@googlemail.com \
    --cc=maz@misterjones.org \
    --cc=mingo@elte.hu \
    --cc=paul.mckenney@linaro.org \
    --cc=richard@nod.at \
    --cc=segoon@openwall.com \
    --cc=torvalds@linux-foundation.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