Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1545751

Re: [RFC 10/10] kmod: add a sanity check on module loading

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod
From "Luis R. Rodriguez" <mcgrof@kernel.org>
Newsgroups linux.kernel
Subject Re: [RFC 10/10] kmod: add a sanity check on module loading
Date Wed, 21 Dec 2016 14:10:03 +0100
Message-ID <sQOOD-3SW-53@gated-at.bofh.it> (permalink)
References <sMbVv-188-1@gated-at.bofh.it> <sMcRA-1I2-25@gated-at.bofh.it> <sOt1T-7Ou-3@gated-at.bofh.it> <sOWdz-135-5@gated-at.bofh.it> <sPek9-4cv-3@gated-at.bofh.it> <sQiYp-8dz-13@gated-at.bofh.it> <sQiYp-8dz-11@gated-at.bofh.it> <sQxNL-Pw-15@gated-at.bofh.it> <sQHDs-7EN-13@gated-at.bofh.it>
X-Gm-Message-State AIkVDXJTPz4xlQJxS9CnT9j+d9v8a/+A+W87NpCLxqL2xL+a6zhRwWpG/beQb7NgDqCMpZlIiZralmMvnRcv4w==
X-Received by 10.28.107.77 with SMTP id g74mr6612558wmc.109.1482325726329; Wed, 21 Dec 2016 05:08:46 -0800 (PST)
MIME-Version 1.0
X-Gmail-Original-Message-ID <CAB=NE6Wd4jvUVS6pNds0yND_PX-MMpVjtvnJOHsNWX_5H7Mdkg@mail.gmail.com>
Content-Type text/plain; charset=UTF-8
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 48
Organization linux.* mail to news gateway
X-Original-Cc Filipe Manana <fdmanana@suse.com>, "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>, "linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>, rgoldwyn@suse.com, hare <hare@suse.com>, Jonathan Corbet <corbet@lwn.net>, Linus Torvalds <torvalds@linux-foundation.org>, linux-kselftest@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>, Dan Williams <dan.j.williams@intel.com>, Aaron Tomlin <atomlin@redhat.com>, rwright@hpe.com, Heinrich Schuchardt <xypron.glpk@gmx.de>, Michal Marek <mmarek@suse.com>, martin.wilck@suse.com, Jeff Mahoney <jeffm@suse.com>, Ingo Molnar <mingo@redhat.com>, Petr Mladek <pmladek@suse.com>, Dmitry Torokhov <dmitry.torokhov@gmail.com>, Guenter Roeck <linux@roeck-us.net>, "Eric W. Biederman" <ebiederm@xmission.com>, shuah@kernel.org, DSterba@suse.com, Kees Cook <keescook@chromium.org>, Josh Poimboeuf <jpoimboe@redhat.com>, Arnaldo Carvalho de Melo <acme@redhat.com>, Miroslav Benes <mbenes@suse.cz>, NeilBrown <neilb@suse.com>, "linux-kernel@vger.kernel.o rg" <linux-kernel@vger.kernel.org>, David Miller <davem@davemloft.net>, Jessica Yu <jeyu@redhat.com>, Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>, Julia Lawall <julia.lawall@lip6.fr>
X-Original-Date Wed, 21 Dec 2016 07:08:25 -0600
X-Original-Message-ID <CAB=NE6Wd4jvUVS6pNds0yND_PX-MMpVjtvnJOHsNWX_5H7Mdkg@mail.gmail.com>
X-Original-References <20161208184801.1689-1-mcgrof@kernel.org> <20161208194930.2816-1-mcgrof@kernel.org> <87k2b2kpdt.fsf@rustcorp.com.au> <20161216083123.GF13946@wotan.suse.de> <87zijvjjm1.fsf@rustcorp.com.au> <CAB=NE6VvuA9a6hf6yoopGfUxVJQM5HyV5bNzUdsEtUV0UhbG-g@mail.gmail.com> <87fuljjua3.fsf@rustcorp.com.au> <CAB=NE6UgFir2u2UKUSqoxFYyuY9rQyJAvifBGi3QU1u15J=ihQ@mail.gmail.com> <87a8bqja3i.fsf@rustcorp.com.au>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1545751

Show key headers only | View raw


On Tue, Dec 20, 2016 at 8:21 PM, Rusty Russell <rusty@rustcorp.com.au> wrote:
> "Luis R. Rodriguez" <mcgrof@kernel.org> writes:
>> OK -- if userspace messes up again it may be a bit hard to prove
>> unless we have a validation debug thing in place, would such a thing
>> in debug form be reasonable ?
>
> That makes perfect sense.  Untested hack:
>
> diff --git a/fs/filesystems.c b/fs/filesystems.c
> index c5618db110be..e5c90e80c7d3 100644
> --- a/fs/filesystems.c
> +++ b/fs/filesystems.c
> @@ -275,9 +275,10 @@ struct file_system_type *get_fs_type(const char *name)
>         int len = dot ? dot - name : strlen(name);
>
>         fs = __get_fs_type(name, len);
> -       if (!fs && (request_module("fs-%.*s", len, name) == 0))
> +       if (!fs && (request_module("fs-%.*s", len, name) == 0)) {
>                 fs = __get_fs_type(name, len);
> -
> +               WARN_ONCE(!fs, "request_module fs-%.*s succeeded, but still no fs?\n", len, name);
> +       }
>         if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
>                 put_filesystem(fs);
>                 fs = NULL;

This is precisely a type of debug patch we had added first to verify "WTF".

> Maybe a similar hack for try_then_request_module(), but many places seem
> to open-code request_module() so it's not as trivial...

Right, out of ~350 request_module() calls (not included try requests)
only ~46 check the return value. Hence a validation check, and come to
think of it, *this* was the issue that originally had me believing
that in some places we might end up in a null deref --if those open
coded request_module() calls assume the driver is loaded there could
be many places where a NULL is inevitable. Granted, I agree they
should be fixed, we could add a grammar rule to start nagging at
driver developers for started, but it does beg the question also of
what a tightly knit validation for modprobe might look like, and hence
this patch and now the completed not-yet-posted alias work.

Would it be worthy as a kconfig kmod debugging aide for now? I can
follow up with a semantic patch to nag about checking the return value
of request_module(), and we can  have 0-day then also complain about
new invalid uses.

  Luis

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [RFC 10/10] kmod: add a sanity check on module loading Rusty Russell <rusty@rustcorp.com.au> - 2016-12-15 02:30 +0100
  Re: [RFC 10/10] kmod: add a sanity check on module loading "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-12-16 09:40 +0100
    Re: [RFC 10/10] kmod: add a sanity check on module loading Rusty Russell <rusty@rustcorp.com.au> - 2016-12-17 05:00 +0100
      Re: [RFC 10/10] kmod: add a sanity check on module loading Rusty Russell <rusty@rustcorp.com.au> - 2016-12-20 04:10 +0100
        Re: [RFC 10/10] kmod: add a sanity check on module loading "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-12-20 20:00 +0100
          Re: [RFC 10/10] kmod: add a sanity check on module loading Rusty Russell <rusty@rustcorp.com.au> - 2016-12-21 06:30 +0100
            Re: [RFC 10/10] kmod: add a sanity check on module loading "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-12-21 14:10 +0100
              Re: [RFC 10/10] kmod: add a sanity check on module loading Rusty Russell <rusty@rustcorp.com.au> - 2017-01-03 03:10 +0100

csiph-web