linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] x86/mm/fault: Allow stack access below %rsp
@ 2018-11-02 19:40 Waiman Long
  2018-11-02 19:44 ` Dave Hansen
  0 siblings, 1 reply; 12+ messages in thread
From: Waiman Long @ 2018-11-02 19:40 UTC (permalink / raw)
  To: Dave Hansen, Andy Lutomirski, Peter Zijlstra, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov
  Cc: H. Peter Anvin, x86, linux-kernel, Waiman Long

The current x86 page fault handler allows stack access below the stack
pointer if it is no more than 64k+256 bytes. Any access beyond the 64k+
limit will cause a segmentation fault.

The gcc -fstack-check option generates code to probe the stack for
large stack allocation to see if the stack is accessible. The newer gcc
does that while updating the %rsp simultaneously. Older gcc's like gcc4
doesn't do that. As a result, an application compiled with an old gcc
and the -fstack-check option may fail to start at all.

% cat test.c
int main() {
	char tmp[1024*128];
	printf("### ok\n");
	return 0;
}
% gcc -fstack-check -g -o test test.c
% ./test
Segmentation fault

The 64k+ limit check is kind of arbitrary. So the check is now removed
to just let expand_stack() decide if a segmentation fault should happen.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 arch/x86/mm/fault.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 71d4b9d..29525cf 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -1380,18 +1380,6 @@ void do_user_addr_fault(struct pt_regs *regs,
 		bad_area(regs, sw_error_code, address);
 		return;
 	}
-	if (sw_error_code & X86_PF_USER) {
-		/*
-		 * Accessing the stack below %sp is always a bug.
-		 * The large cushion allows instructions like enter
-		 * and pusha to work. ("enter $65535, $31" pushes
-		 * 32 pointers and then decrements %sp by 65535.)
-		 */
-		if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
-			bad_area(regs, sw_error_code, address);
-			return;
-		}
-	}
 	if (unlikely(expand_stack(vma, address))) {
 		bad_area(regs, sw_error_code, address);
 		return;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-11-05 19:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-02 19:40 [RFC PATCH] x86/mm/fault: Allow stack access below %rsp Waiman Long
2018-11-02 19:44 ` Dave Hansen
2018-11-02 19:50   ` Waiman Long
2018-11-02 20:11     ` Andy Lutomirski
2018-11-02 20:34       ` Waiman Long
2018-11-02 22:28     ` Dave Hansen
2018-11-05  5:11       ` Andy Lutomirski
2018-11-05  5:14         ` Andy Lutomirski
2018-11-05 17:20           ` Dave Hansen
2018-11-05 19:21             ` Andy Lutomirski
2018-11-05 16:27       ` Waiman Long
2018-11-05 17:51         ` Dave Hansen

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).