linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Ebbert <cebbert.lkml@gmail.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Aaron Tomlin <atomlin@redhat.com>, Helge Deller <deller@gmx.de>,
	James Hogan <james.hogan@imgtec.com>
Subject: [RFC/PATCH] Fix end_of_stack() and stack_not_used() for archs using CONFIG_STACK_GROWSUP
Date: Sun, 14 Sep 2014 23:23:05 -0500	[thread overview]
Message-ID: <20140914232305.5390b996@as> (raw)

When looking at Aaron's patches adding extra checks of the stack canary, I
realized the code almost certainly never worked if the stack grows up. Something
like this is needed, I think.

Not-Signed-Off-By: Chuck Ebbert <cebbert.lkml@gmail.com>

---

Not even compile tested.

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 5c2c885..da7f597 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2610,7 +2610,11 @@ static inline void setup_thread_stack(struct task_struct *p, struct task_struct
 
 static inline unsigned long *end_of_stack(struct task_struct *p)
 {
+#ifdef CONFIG_STACK_GROWSUP
+	return (unsigned long *)((unsigned long)task_thread_info(p) + THREAD_SIZE) - 1;
+#else
 	return (unsigned long *)(task_thread_info(p) + 1);
+#endif
 }
 
 #endif
@@ -2629,13 +2633,21 @@ static inline unsigned long stack_not_used(struct task_struct *p)
 {
 	unsigned long *n = end_of_stack(p);
 
+#ifdef CONFIG_STACK_GROWSUP
+	do { 	/* Skip over canary */
+		n--;
+	} while (!*n);
+
+	return (unsigned long)end_of_stack(p) - (unsigned long)n;
+#else
 	do { 	/* Skip over canary */
 		n++;
 	} while (!*n);
 
 	return (unsigned long)n - (unsigned long)end_of_stack(p);
-}
 #endif
+}
+#endif /* CONFIG_DEBUG_STACK_USAGE */
 
 /* set thread flags in other task's structures
  * - see asm/thread_info.h for TIF_xxxx flags available



                 reply	other threads:[~2014-09-15  4:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20140914232305.5390b996@as \
    --to=cebbert.lkml@gmail.com \
    --cc=atomlin@redhat.com \
    --cc=deller@gmx.de \
    --cc=james.hogan@imgtec.com \
    --cc=linux-kernel@vger.kernel.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).