Development discussion of WireGuard
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: pageexec@freemail.hu
Cc: WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: Re: Kernel Panic
Date: Tue, 6 Dec 2016 23:39:36 +0100	[thread overview]
Message-ID: <CAHmME9q+oEAo+HuSRf8WJoGv+jbsA46c3GHXCUT4QvX8a+k23w@mail.gmail.com> (raw)
In-Reply-To: <CAHmME9qBAt84jOvJhnSOybekbOFQb1RH+7mmfGK=bc2i9bxADg@mail.gmail.com>

Hey PaXTeam,

I tracked down Samuel's bug to this line in crypto/scatterwalk.c:
        if (sg_page(sg) == virt_to_page(realbuf) &&

virt_to_page is redefined for CONFIG_GRKERNSEC_KSTACKOVERFLOW:

#define virt_to_page(kaddr)     \
       ({ \
               const void *__kaddr = (const void *)(kaddr); \
               BUG_ON(!virt_addr_valid(__kaddr)); \
               pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
       })

So that's where the bug is hit. Now why is this happening?

I call scatterwalk_map_and_copy to read or write from or to a stack
buffer from a scattergather list, inside some crypto code that does
MAC checking. When virt_addr_valid(__kaddr) returns false, it is only
after PaX has additionally messed with its value. A few lines above
the call to virt_to_page is:

#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
       if (object_starts_on_stack(buf))
               realbuf = buf - current->stack + current->lowmem_stack;
#endif

Presumably this condition winds up being true, and then that
arithmetic is wrong somehow. Alternatively, that condition isn't true
due to a bug in object_starts_on_stack, and that arithmetic doesn't
run when it needs to run.

Samuel reported that the problem did not exist on 4.7 but does exist
on 4.8. If my memory serves me correctly, 4.8 introduced virtually
mapped stacks. Could it be that this virtual mapping now eliminates
the need for that arithmetic?

Regards,
Jason

  reply	other threads:[~2016-12-06 22:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06  6:23 Samuel Holland
2016-12-06 18:19 ` Jason A. Donenfeld
2016-12-06 18:26   ` Samuel Holland
2016-12-06 18:31     ` Jason A. Donenfeld
2016-12-06 22:39       ` Jason A. Donenfeld [this message]
2016-12-07  0:44         ` PaX Team
2016-12-07 10:38           ` Jason A. Donenfeld
     [not found]             ` <CAHmME9pVCDu88c6n+LV9Mtd5Ohu8o-7RSQB4kRjsHGRQ3jF8zw@mail.gmail.com>
     [not found]               ` <20161208231626.GA5230@grsecurity.net>
2016-12-09 11:17                 ` Jason A. Donenfeld
     [not found]                   ` <20161209121144.GA31448@grsecurity.net>
2016-12-09 12:56                     ` Jason A. Donenfeld
2016-12-09 13:27                       ` Jason A. Donenfeld
2016-12-09 15:54 ` Jason A. Donenfeld

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=CAHmME9q+oEAo+HuSRf8WJoGv+jbsA46c3GHXCUT4QvX8a+k23w@mail.gmail.com \
    --to=jason@zx2c4.com \
    --cc=pageexec@freemail.hu \
    --cc=wireguard@lists.zx2c4.com \
    /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;
as well as URLs for NNTP newsgroup(s).