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


Groups > linux.kernel > #1616430

Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78!

Path csiph.com!xmission!news.snarked.org!news.redatomik.org!news.gegeweb.eu!gegeweb.org!aioe.org!bofh.it!news.nic.it!robomod
From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78!
Date Wed, 05 Apr 2017 00:40:01 +0200
Message-ID <tsFhf-2yy-7@gated-at.bofh.it> (permalink)
References <tqLqO-KI-15@gated-at.bofh.it> <tqLqO-KI-13@gated-at.bofh.it> <tqOf0-2K2-11@gated-at.bofh.it> <tqOoG-2NT-33@gated-at.bofh.it> <tr8nn-7xP-7@gated-at.bofh.it> <tr8GJ-7Fk-9@gated-at.bofh.it> <tr9t8-8dB-9@gated-at.bofh.it> <tsFhf-2yy-9@gated-at.bofh.it>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=uS8ecWbE5E8F0O1lQsTSAhfwq2nRdOXgxR/hEVQFCuU=; b=VEWIh0l2RA4jsfAGWoCOMNIouMqmtLiPOHljUaLCaKvRrXbNQV4/LZzpQucB8IaKLz K6CUTuG7C/bZgFE6ZHpZELG9El5QpalUC547e3DKSIjlKpv7CJ7LRDaKN9nHlUhjLgOx VOfDR1YbS9TiHd7QIJbvHfWhJ+kUtASg8fRezwKpj8cHUGmkRmYCOMTedwWOcBOqwQXd r+3TnG0l9fHgaqK0BbYkkxG13bvEFfQ5FZnv/Ivd0R0VP8LmMSVToVe2K57ufLkqLIIP YAjuETmDAPTwlqeah6M7VdHXSHHCr6dFegXI9PCzUP/WFzTwLqxSsBm3j6vZTzL8+9qg FIcw==
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=uS8ecWbE5E8F0O1lQsTSAhfwq2nRdOXgxR/hEVQFCuU=; b=IYSnKi+biTKB2ckqVGCu9E6RE+SxqPbNc50syzHEtWZUXrZpeMwxP/iySJnFQUJuQV jVn9TdA/NsfOuFmrpFwkbXxKjTCsWrYNmULspTtw/GzmpESPlr7UW66hp2U09BqAjzYh 9zvADLnIaFhhojzrDmwQFGB8GFCHS9Bnp/0TY=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=uS8ecWbE5E8F0O1lQsTSAhfwq2nRdOXgxR/hEVQFCuU=; b=avw7dfZbJ9NlBNuKGIWMQh3EEA2M3xUp88/zqFJJrh1sJTElsYN3MWGCmzRdJJ9K6X 2OkUpTQe5K8uQlTzZncMxPYs8tcQmCJDQR+HnzIXZ8GrgAxa9/3PmYXlMewd2Lus5zvD JRG51y529+GDy12H6+WBYpO/giMWgq/GmH2YSO2m7tmBfQX60+IfkCxH+bj+pjZvE2gf CwwXcJ2eVHopMPQpzUSo/ex3zjqgKN5aM40K1NzuvcQV3f4A0lzgHk3DMw62I4AOTShW tti7HxkAhrHzUxmcc7TDOSbcuddGzyYR9B2BCGlNyu7nV4Yl9PJJb1s2RgtdbvBGd/UQ F2hw==
X-Gm-Message-State AFeK/H1HkrJYDwMchl4UZKjvGyVXxMag/NExHt2wc86jHe8mZjwqWo8Lmtaezg5vBJHuNe22Ke2B0/6OmuwJk4Qw
X-Received by 10.107.133.159 with SMTP id p31mr25399150ioi.101.1491345428432; Tue, 04 Apr 2017 15:37:08 -0700 (PDT)
MIME-Version 1.0
X-Google-Sender-Auth gJDKaLsmms-UMPZ4FEf8tA42AS0
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 101
Organization linux.* mail to news gateway
X-Original-Cc Linus Torvalds <torvalds@linux-foundation.org>, Dave Jones <davej@codemonkey.org.uk>, Linux-MM <linux-mm@kvack.org>, LKML <linux-kernel@vger.kernel.org>, Laura Abbott <labbott@redhat.com>, Ingo Molnar <mingo@kernel.org>, Josh Poimboeuf <jpoimboe@redhat.com>, Mark Rutland <mark.rutland@arm.com>, Eric Biggers <ebiggers@google.com>
X-Original-Date Tue, 4 Apr 2017 15:37:07 -0700
X-Original-Message-ID <CAGXu5jJAd9Qg4gkXE=1+8q6Ej=8boiH4ovkzX5n+PbhkBrnt5g@mail.gmail.com>
X-Original-References <d928849c-e7c3-6b81-e551-a39fa976f341@nokia.com> <CAGXu5jKo4gw=RHCmcY3v+GTiUUgteLbmvHDghd-Lrm7RprL8=Q@mail.gmail.com> <20170330194143.cbracica3w3ijrcx@codemonkey.org.uk> <CAGXu5jK8=g8rBx1J4+gC8-3nwRLe2Va89hHX=S-P6SvvgiVb9A@mail.gmail.com> <20170331171724.nm22iqiellfsvj5z@codemonkey.org.uk> <CAGXu5jL7MGNut_izksDKJHNJjPZqvu_84GBwHjqVeRbjDJyMWw@mail.gmail.com> <CA+55aFwOCnhSF4Tyk8x0+EpcWmaDd9X5bi1w=O1aReEK53OY8A@mail.gmail.com> <a6543d13-6247-08de-903e-f4d1bbb52881@nokia.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1616430

Show key headers only | View raw


On Fri, Mar 31, 2017 at 12:32 PM, Tommi Rantala
<tommi.t.rantala@nokia.com> wrote:
> On 31.03.2017 21:26, Linus Torvalds wrote:
>>
>> Hmm. Thinking more about this, we do allow access to the first 1MB of
>> physical memory unconditionally (see devmem_is_allowed() in
>> arch/x86/mm/init.c). And I think we only _reserve_ the first 64kB or
>> something. So I guess even STRICT_DEVMEM isn't actually all that
>> strict.
>>
>> So this should be visible even *with* STRICT_DEVMEM.
>>
>> Does a simple
>>
>>      sudo dd if=/dev/mem of=/dev/null bs=4096 count=256
>>
>> also show the same issue? Maybe regardless of STRICT_DEVMEM?
>
>
> Yep, it is enough to trigger the bug.
>
> Also crashes with the fedora kernel that has STRICT_DEVMEM:
>
> $ sudo dd if=/dev/mem of=/dev/null bs=4096 count=256
> Segmentation fault
>
> [   73.224025] usercopy: kernel memory exposure attempt detected from
> ffff893a80059000 (dma-kmalloc-16) (4096 bytes)
> [   73.224049] ------------[ cut here ]------------
> [   73.224056] kernel BUG at mm/usercopy.c:75!
> [   73.224060] invalid opcode: 0000 [#1] SMP
> [   73.224237] CPU: 5 PID: 2860 Comm: dd Not tainted 4.9.14-200.fc25.x86_64
> #1

As root, what does dumping /proc/iomem show you?

For one of my systems, I see something like this:

00000000-00000fff : reserved
00001000-0008efff : System RAM
0008f000-0008ffff : reserved
00090000-0009f7ff : System RAM
0009f800-0009ffff : reserved
000a0000-000bffff : PCI Bus 0000:00
000c0000-000c7fff : Video ROM
000e0000-000fffff : reserved
  000e0000-000effff : PCI Bus 0000:00
  000f0000-000fffff : System ROM
00100000-cdee6fff : System RAM
  cbc00000-cc49a653 : Kernel code
  cc49a654-ccb661bf : Kernel data
  cccf3000-cce30fff : Kernel bss
...

I note that there are two "System RAM" areas below 0x100000. In
arch/x86/mm/init.c, devmem_is_allowed() says:

/*
 * devmem_is_allowed() checks to see if /dev/mem access to a certain address
 * is valid. The argument is a physical page number.
 *
 *
 * On x86, access has to be given to the first megabyte of ram because that area
 * contains BIOS code and data regions used by X and dosemu and similar apps.
 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
 * mmio resources as well as potential bios/acpi data regions.
 */
int devmem_is_allowed(unsigned long pagenr)
{
        if (pagenr < 256)
                return 1;
        if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
                return 0;
        if (!page_is_ram(pagenr))
                return 1;
        return 0;
}

This means that it allows reads into even System RAM below 0x100000,
but I think that's a mistake. Shouldn't BIOS code and data regions
already be marked as "reserved", as seen in my /proc/iomem output? I
feel like the "pagenr < 256" exception should be dropped, but I don't
know all the minor details on the history here.

When I remove this exception, x86info blows up for me ("error reading
EBDA pointer").

So, my question is: are there actually BIOS code/data in memory areas
marked as System RAM? If so, what normally keeps them from being used
for kernel memory? If not, then I assume x86info is wrong?

Dave, you implied the latter, but I wanted to make sure this is
actually true? (And if so, we need to do something like what Linus
suggested to return zeros to keep old x86info "happy" -- would that
keep it happy?)

-Kees

-- 
Kees Cook
Pixel Security

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


Thread

Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Kees Cook <keescook@chromium.org> - 2017-03-30 18:50 +0200
  Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Laura Abbott <labbott@redhat.com> - 2017-03-30 19:30 +0200
    Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Kees Cook <keescook@chromium.org> - 2017-03-30 19:40 +0200
      Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Laura Abbott <labbott@redhat.com> - 2017-03-30 19:50 +0200
  Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Mark Rutland <mark.rutland@arm.com> - 2017-03-30 19:30 +0200
  Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Dave Jones <davej@codemonkey.org.uk> - 2017-03-30 21:50 +0200
    Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Kees Cook <keescook@chromium.org> - 2017-03-30 22:00 +0200
      Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Dave Jones <davej@codemonkey.org.uk> - 2017-03-30 22:10 +0200
      Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Dave Jones <davej@codemonkey.org.uk> - 2017-03-31 19:20 +0200
        Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Kees Cook <keescook@chromium.org> - 2017-03-31 19:40 +0200
          Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Dave Jones <davej@codemonkey.org.uk> - 2017-03-31 20:10 +0200
            Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Andy Lutomirski <luto@amacapital.net> - 2017-03-31 21:00 +0200
          Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Linus Torvalds <torvalds@linux-foundation.org> - 2017-03-31 20:30 +0200
            Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Kees Cook <keescook@chromium.org> - 2017-04-01 02:00 +0200
            Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Kees Cook <keescook@chromium.org> - 2017-04-05 00:40 +0200
              Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Linus Torvalds <torvalds@linux-foundation.org> - 2017-04-05 01:00 +0200
                Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Kees Cook <keescook@chromium.org> - 2017-04-05 01:10 +0200
                Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Linus Torvalds <torvalds@linux-foundation.org> - 2017-04-05 02:30 +0200
                Re: sudo x86info -a => kernel BUG at mm/usercopy.c:78! Kees Cook <keescook@chromium.org> - 2017-04-05 21:40 +0200

csiph-web