All of lore.kernel.org
 help / color / mirror / Atom feed
From: kpark3469@gmail.com
To: kernel-hardening@lists.openwall.com
Cc: keescook@chromium.org, james.morse@arm.com,
	catalin.marinas@arm.com, will.deacon@arm.com,
	mark.rutland@arm.com, keun-o.park@darkmatter.ae
Subject: [PATCH 3/4] arm64: usercopy: consider dynamic array stack variable
Date: Thu,  1 Mar 2018 14:19:50 +0400	[thread overview]
Message-ID: <1519899591-29761-4-git-send-email-kpark3469@gmail.com> (raw)
In-Reply-To: <1519899591-29761-3-git-send-email-kpark3469@gmail.com>

From: Sahara <keun-o.park@darkmatter.ae>

When an array is dynamically declared, the array may be placed
at next frame. If this variable is used for usercopy, then it
will cause an Oops because the current check code does not allow
this exceptional case.

 low -----------------------------------------------------> high
 [__check_object_size fp][lr][args][local vars][caller_fp][lr]
                             ^----------------^
                     dynamically allocated stack variable of
                     caller frame copies are allowed within here

 < example code snippet >
 array_size = get_random_int() & 0x0f;
 if (to_user) {
         unsigned char array[array_size];
         if (copy_to_user((void __user *)user_addr, array,
                          unconst + sizeof(array))) {

Signed-off-by: Sahara <keun-o.park@darkmatter.ae>
---
 arch/arm64/kernel/stacktrace.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 6d37fad..75a8f20 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -162,8 +162,13 @@ int arch_within_stack_frames(const void *stack,
 	 * Skip 4 non-inlined frames: <fake frame>,
 	 * arch_within_stack_frames(), check_stack_object() and
 	 * __check_object_size().
+	 *
+	 * From Akashi's report, an object may be placed between next caller's
+	 * frame, when the object is created as dynamic array.
+	 * Setting the discard_frames to 3 is proper to catch this exceptional
+	 * case.
 	 */
-	arg.discard_frames = 4;
+	arg.discard_frames = 3;
 
 	walk_stackframe(current, &frame, check_frame, &arg);
 
-- 
2.7.4

  reply	other threads:[~2018-03-01 10:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01 10:19 [PATCH 0/4] usercopy: reimplement arch_within_stack_frames kpark3469
2018-03-01 10:19 ` [PATCH 1/4] stacktrace: move arch_within_stack_frames from thread_info.h kpark3469
2018-03-01 10:19   ` [PATCH 2/4] arm64: usercopy: implement arch_within_stack_frames kpark3469
2018-03-01 10:19     ` kpark3469 [this message]
2018-03-01 10:19       ` [PATCH 4/4] x86: usercopy: reimplement arch_within_stack_frames with unwinder kpark3469
2018-04-04 23:10         ` Kees Cook
2018-04-04 23:11           ` Kees Cook
2018-04-09  5:40             ` Keun-O Park
2018-04-04 22:57       ` [PATCH 3/4] arm64: usercopy: consider dynamic array stack variable Kees Cook
2018-04-08  6:45         ` Keun-O Park
2018-04-09  5:54           ` Keun-O Park
2018-04-04 22:55     ` [PATCH 2/4] arm64: usercopy: implement arch_within_stack_frames Kees Cook
2018-04-08  6:39       ` Keun-O Park
2018-04-04 22:52   ` [PATCH 1/4] stacktrace: move arch_within_stack_frames from thread_info.h Kees Cook
2018-03-26 14:35 ` [PATCH 0/4] usercopy: reimplement arch_within_stack_frames Will Deacon
2018-03-28 10:16   ` Keun-O Park
2018-04-04 22:46     ` 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=1519899591-29761-4-git-send-email-kpark3469@gmail.com \
    --to=kpark3469@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=keun-o.park@darkmatter.ae \
    --cc=mark.rutland@arm.com \
    --cc=will.deacon@arm.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.