linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] execve: warn if process starts with executable stack
@ 2019-12-08 17:19 Alexey Dobriyan
  2019-12-11  1:47 ` Andrew Morton
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey Dobriyan @ 2019-12-08 17:19 UTC (permalink / raw)
  To: akpm; +Cc: dan.carpenter, will, ebiederm, linux-arch, security, linux-kernel

There were few episodes of silent downgrade to an executable stack over
years:

1) linking innocent looking assembly file will silently add executable
   stack if proper linker options is not given as well:

	$ cat f.S
	.intel_syntax noprefix
	.text
	.globl f
	f:
	        ret

	$ cat main.c
	void f(void);
	int main(void)
	{
	        f();
	        return 0;
	}

	$ gcc main.c f.S
	$ readelf -l ./a.out
	  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                         0x0000000000000000 0x0000000000000000  RWE    0x10
			 					 ^^^

2) converting C99 nested function into a closure
https://nullprogram.com/blog/2019/11/15/

	void intsort2(int *base, size_t nmemb, _Bool invert)
	{
	    int cmp(const void *a, const void *b)
	    {
	        int r = *(int *)a - *(int *)b;
	        return invert ? -r : r;
	    }
	    qsort(base, nmemb, sizeof(*base), cmp);
	}

will silently require stack trampolines while non-closure version will not.

Without doubt this behaviour is documented somewhere, add a warning so that
developers and users can at least notice. After so many years of x86_64 having
proper executable stack support it should not cause too many problems.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

	v2: print pathname instead of comm/pid

 fs/exec.c |    5 +++++
 1 file changed, 5 insertions(+)

--- a/fs/exec.c
+++ b/fs/exec.c
@@ -761,6 +761,11 @@ int setup_arg_pages(struct linux_binprm *bprm,
 		goto out_unlock;
 	BUG_ON(prev != vma);
 
+	if (unlikely(vm_flags & VM_EXEC)) {
+		pr_warn_once("process '%pD4' started with executable stack\n",
+			     bprm->file);
+	}
+
 	/* Move stack pages down in memory. */
 	if (stack_shift) {
 		ret = shift_arg_pages(vma, stack_shift);

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

end of thread, other threads:[~2020-02-25 21:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-08 17:19 [PATCH v2] execve: warn if process starts with executable stack Alexey Dobriyan
2019-12-11  1:47 ` Andrew Morton
2019-12-11  7:22   ` Alexey Dobriyan
2019-12-11  9:59     ` Willy Tarreau
2019-12-11 18:19       ` Alexey Dobriyan
2019-12-11 18:24         ` Willy Tarreau
2019-12-12 21:25           ` Alexey Dobriyan
2019-12-13  9:56             ` Dan Carpenter
2019-12-13 10:23               ` Willy Tarreau
2020-02-25 21:52   ` Kees Cook

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