From: james.morse@arm.com (James Morse)
To: linux-arm-kernel@lists.infradead.org
Subject: [kernel-hardening] [PATCH v4 3/3] arm64/uaccess: Add hardened usercopy check for bad stack accesses
Date: Thu, 30 Mar 2017 09:32:00 +0100 [thread overview]
Message-ID: <58DCC280.5030608@arm.com> (raw)
In-Reply-To: <CA+KhAHavP2eg4Ci-ZMWo_6-0X9UFoyz2j+tmvxMqyyBwUu9=yQ@mail.gmail.com>
Hi,
On 17/02/17 18:09, Keun-O Park wrote:
>> diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
>> index 46da3ea638bb..d3494840a61c 100644
>> --- a/arch/arm64/include/asm/uaccess.h
>> +++ b/arch/arm64/include/asm/uaccess.h
>> @@ -356,6 +356,22 @@ do { \
>> +static inline void check_obj_in_unused_stack(const void *obj, unsigned long len)
>> +{
>> + unsigned long stack = (unsigned long)task_stack_page(current);
>> +
>> + if (__builtin_constant_p(len) || !IS_ENABLED(CONFIG_HARDENED_USERCOPY) || !len)
>> + return;
>> +
>> + /*
>> + * If current_stack_pointer is on the task stack, obj must not lie
>> + * between current_stack_pointer and the last stack address.
>> + */
>> + if ((current_stack_pointer & ~(THREAD_SIZE-1)) == stack)
>> + BUG_ON(stack <= (unsigned long)obj &&
>> + (unsigned long)obj < current_stack_pointer);
>> +}
>> +
>
> It looks to me that this function is just doing the similar check that
> check_stack_object() may do.
> Probably I guess you had a problem in checking the correct fp of
> caller's function while you tried to use walk_stackframe().
The value needs to be taken in a hopefully-inlined function if you want to catch
LKDTMs 'just off the stack' writes. Doing it like this saved meddling with the
generic code.
> Instead of creating check_obj_in_unused_stack(), how about handing
> over current_stack_pointer to check_stack_object();
Sure, do you want to give this a go? (I have my hands full at the moment)
It might not be the right check on all architectures, x86 redzone comes to mind,
but it doesn't look like they use this in the kernel.
There is also Al Viro's uaccess unification work that may affect whether this is
worth doing now:
https://lkml.org/lkml/2015/12/3/494
Thanks,
James
next prev parent reply other threads:[~2017-03-30 8:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-16 18:29 [PATCH v4 0/3] arm64: usercopy: Implement stack frame object validation James Morse
2017-02-16 18:29 ` [PATCH v4 1/3] usercopy: create enum stack_type James Morse
2017-04-04 22:19 ` Kees Cook
2017-02-16 18:29 ` [PATCH v4 2/3] arm64: Add arch_within_stack_frames() for hardened usercopy James Morse
2017-02-17 0:47 ` Kees Cook
2017-02-16 18:29 ` [PATCH v4 3/3] arm64/uaccess: Add hardened usercopy check for bad stack accesses James Morse
2017-02-17 0:44 ` Kees Cook
2017-02-17 18:09 ` [kernel-hardening] " Keun-O Park
2017-03-30 8:32 ` James Morse [this message]
2017-02-17 0:54 ` [PATCH v4 0/3] arm64: usercopy: Implement stack frame object validation Kees Cook
2017-03-28 22:34 ` Kees Cook
2017-03-30 8:30 ` James Morse
2017-03-30 19:54 ` 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=58DCC280.5030608@arm.com \
--to=james.morse@arm.com \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).