All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Popov <alex.popov@linux.com>
To: Laura Abbott <labbott@redhat.com>, Mark Rutland <mark.rutland@arm.com>
Cc: Kees Cook <keescook@chromium.org>,
	kernel-hardening@lists.openwall.com,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Tycho Andersen <tycho@docker.com>,
	PaX Team <pageexec@freemail.hu>
Subject: [kernel-hardening] Re: [RFC][PATCH 2/2] arm64: Clear the stack
Date: Fri, 21 Jul 2017 19:56:13 +0300	[thread overview]
Message-ID: <f100d5f3-fabc-a6b4-ef5f-91fc5f123299@linux.com> (raw)
In-Reply-To: <2f24df9e-64b1-ffef-ddbb-08f7fe8d2a96@redhat.com>

Hello Laura and Mark,

[+ Tycho Andersen and Pax Team]

On 14.07.2017 23:51, Laura Abbott wrote:
> On 07/11/2017 12:51 PM, Mark Rutland wrote:
>> On Mon, Jul 10, 2017 at 03:04:43PM -0700, Laura Abbott wrote:
>>> +	/* The poison function */
>>> +4:
>>> +	/* Generate the address we found */
>>> +	add     x5, x1, x3, lsl #3
>>> +	orr     x5, x5, #16
>>
>> Have you figured out what the forced 16 byte offset is for?
>>
>> I've not managed to figure out why it's there, and it looks like
>> Alexander couldn't either, judging by his comments in the x86 asm.
> 
> From get_wchan in arch/x86/kernel/process.c, it might be be to
> account for the start of the frame correctly? I don't have a
> definitive answer though and plan on just removing this for the
> next version.

I've investigated it carefully: we should not remove this 16-byte offset.

I looked at the bottom of the kernel stack with the debugger and found a
non-zero value 0x57AC6E9D. It is STACK_END_MAGIC, which is defined in
include/uapi/linux/magic.h. This value is checked if we enable
CONFIG_SCHED_STACK_END_CHECK.

Then I removed this 16-byte offset in stackleak patch (including the OR
instruction in erase_kstack()) to see how the first erase_kstack() call happily
overwrites that magic value:

[    1.574655] Freeing unused kernel memory: 1244K
[    1.575026] Kernel memory protection disabled.
[    1.578575] Kernel panic - not syncing: corrupted stack end detected inside
scheduler
[    1.578575]
[    1.579420] CPU: 0 PID: 1 Comm: init Not tainted 4.12.0+ #9
[    1.579420] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
Ubuntu-1.8.2-1ubuntu1 04/01/2014
[    1.579420] Call Trace:
[    1.579420]  dump_stack+0x63/0x81
[    1.579420]  panic+0xd0/0x212
[    1.579420]  __schedule+0x6d8/0x6e0
[    1.579420]  schedule+0x31/0x80
[    1.579420]  io_schedule+0x11/0x40
[    1.579420]  __lock_page_or_retry+0x17d/0x2b0
[    1.579420]  ? page_cache_tree_insert+0x90/0x90
[    1.579420]  filemap_fault+0x3aa/0x5c0
[    1.579420]  ? filemap_map_pages+0x1a6/0x280
[    1.579420]  ext4_filemap_fault+0x2d/0x40
[    1.579420]  __do_fault+0x1b/0x60
[    1.579420]  __handle_mm_fault+0x641/0x8b0
[    1.579420]  handle_mm_fault+0x87/0x130
[    1.579420]  __do_page_fault+0x25f/0x4a0
[    1.579420]  trace_do_page_fault+0x37/0xd0
[    1.579420]  do_async_page_fault+0x23/0x80
[    1.579420]  async_page_fault+0x28/0x30
[    1.579420] RIP: 0033:0x7f81be514ab0
[    1.579420] RSP: 002b:00007ffc8de73768 EFLAGS: 00010202
[    1.579420] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[    1.579420] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00007ffc8de73770
[    1.579420] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
[    1.579420] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
[    1.579420] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[    1.579420] Dumping ftrace buffer:
[    1.579420]    (ftrace buffer empty)
[    1.579420] Kernel Offset: disabled
[    1.579420] Rebooting in 86400 seconds..


So let's keep it not to break CONFIG_SCHED_STACK_END_CHECK.

Again, I want to say kudos to PaX Team for his awesome code.
Best regards,
Alexander

  reply	other threads:[~2017-07-21 16:56 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-09 14:30 [kernel-hardening] [PATCH RFC v2 1/1] gcc-plugins: Add stackleak feature erasing the kernel stack at the end of syscalls Alexander Popov
2017-06-09 17:28 ` [kernel-hardening] " Kees Cook
2017-06-09 23:00   ` Alexander Popov
2017-06-20 19:20     ` Kees Cook
2017-06-13 21:51   ` Laura Abbott
2017-06-20 11:20     ` Mark Rutland
2017-06-20 14:13       ` Ard Biesheuvel
2017-06-20 19:11       ` Kees Cook
2017-06-21  9:24         ` Mark Rutland
2017-06-21 15:54           ` Laura Abbott
2017-07-10 22:04             ` [kernel-hardening] [RFC][PATCH 0/2] draft of stack clearing for arm64 Laura Abbott
2017-07-10 22:04               ` [kernel-hardening] [RFC][PATCH 1/2] stackleak: Update " Laura Abbott
2017-07-10 22:04               ` [kernel-hardening] [RFC][PATCH 2/2] arm64: Clear the stack Laura Abbott
2017-07-11 19:51                 ` [kernel-hardening] " Mark Rutland
2017-07-11 20:04                   ` Mark Rutland
2017-07-12  6:01                   ` Alexander Popov
2017-07-14 20:51                   ` Laura Abbott
2017-07-21 16:56                     ` Alexander Popov [this message]
2017-07-22  0:23                       ` Laura Abbott
2017-07-24  8:19                         ` Alexander Popov
2017-07-25  3:34                           ` Kees Cook
2017-08-18  8:07                             ` Alexander Popov
2017-07-11 22:56               ` [kernel-hardening] Re: [RFC][PATCH 0/2] draft of stack clearing for arm64 Alexander Popov
2017-06-23 22:48   ` [kernel-hardening] Re: [PATCH RFC v2 1/1] gcc-plugins: Add stackleak feature erasing the kernel stack at the end of syscalls Tycho Andersen
2017-06-29 21:33     ` Kees Cook
2017-06-29 22:13       ` Tycho Andersen
2017-06-20  9:06 ` [kernel-hardening] " Hector Martin "marcan"
2017-06-20 19:07   ` Kees Cook
2017-06-20 20:22     ` Hector Martin "marcan"
2017-06-20 19:14 ` [kernel-hardening] " Kees Cook

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=f100d5f3-fabc-a6b4-ef5f-91fc5f123299@linux.com \
    --to=alex.popov@linux.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=labbott@redhat.com \
    --cc=mark.rutland@arm.com \
    --cc=pageexec@freemail.hu \
    --cc=tycho@docker.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.