linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
@ 2007-07-09 19:57 Scott Wood
  2007-07-09 20:25 ` Arnd Bergmann
  2007-07-10 13:11 ` Segher Boessenkool
  0 siblings, 2 replies; 15+ messages in thread
From: Scott Wood @ 2007-07-09 19:57 UTC (permalink / raw)
  To: paulus; +Cc: linuxppc-dev

In older versions of glibc (through 2.3), the dynamic linker executes a
small amount of code from the data segment, which is not marked as
executable.  A recent change (commit 9ba4ace39fdfe22268daca9f28c5df384ae462cf)
stops this from working; there should be a deprecation period before
older glibc versions stop working.

The problem has been observed on glibc 2.2.  While glibc 2.3 has the same
code, I did not see the problem; it may be that it accesses the page in
question as data before executing from it, and thus it is already mapped.

Signed-off-by: Scott Wood <scottwood@freescale.com>
---
Unfortunately, this didn't make it into 2.6.22, but it should probably go
into the stable branch...

 arch/powerpc/mm/fault.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 0ece513..2445512 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -125,6 +125,18 @@ static void do_dabr(struct pt_regs *regs, unsigned long address,
 }
 #endif /* !(CONFIG_4xx || CONFIG_BOOKE)*/
 
+#ifdef CONFIG_PPC32
+static void warn_exec_from_noexec(void)
+{
+	if (printk_ratelimit())
+		printk(KERN_WARNING "Process %s (%d) attempted to execute from "
+		                    "a non-executable page.\n"
+		       KERN_WARNING "This may stop working in future kernels.  "
+		                    "Please upgrade your libc.\n",
+		       current->comm, current->pid);
+}
+#endif
+
 /*
  * For 600- and 800-family processors, the error_code parameter is DSISR
  * for a data fault, SRR1 for an instruction fault. For 400-family processors
@@ -283,8 +295,16 @@ good_area:
 		/* protection fault */
 		if (error_code & DSISR_PROTFAULT)
 			goto bad_area;
-		if (!(vma->vm_flags & VM_EXEC))
+		if (!(vma->vm_flags & VM_EXEC)) {
+#ifdef CONFIG_PPC32
+			if (vma->vm_flags & VM_READ)
+				warn_exec_from_noexec();
+			else
+				goto bad_area;
+#else
 			goto bad_area;
+#endif
+		}
 #else
 		pte_t *ptep;
 		pmd_t *pmdp;
-- 
1.5.0.3

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-09 19:57 [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning Scott Wood
@ 2007-07-09 20:25 ` Arnd Bergmann
  2007-07-09 21:16   ` Scott Wood
  2007-07-10 13:11 ` Segher Boessenkool
  1 sibling, 1 reply; 15+ messages in thread
From: Arnd Bergmann @ 2007-07-09 20:25 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: paulus

On Monday 09 July 2007, Scott Wood wrote:
> In older versions of glibc (through 2.3), the dynamic linker executes a
> small amount of code from the data segment, which is not marked as
> executable. =A0A recent change (commit 9ba4ace39fdfe22268daca9f28c5df384a=
e462cf)
> stops this from working; there should be a deprecation period before
> older glibc versions stop working.
>=20
> The problem has been observed on glibc 2.2. =A0While glibc 2.3 has the sa=
me
> code, I did not see the problem; it may be that it accesses the page in
> question as data before executing from it, and thus it is already mapped.

I may be missing the obvious, but doesn't that defeat the purpose of
non-executable mappings?

	Arnd <><

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-09 21:16   ` Scott Wood
@ 2007-07-09 20:52     ` Arnd Bergmann
  2007-07-09 21:29     ` Linas Vepstas
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 15+ messages in thread
From: Arnd Bergmann @ 2007-07-09 20:52 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev, paulus

On Monday 09 July 2007, Scott Wood wrote:
> The hardware in question doesn't support non-executable mappings;=20
> otherwise, it'd never have worked in the first place. =A0Note that this i=
s=20
> only allowed on 32-bit, non-book-E.
>=20
> There isn't much value in enforcing non-exec mappings only if it happens=
=20
> to be the first fault on a given page.

Ok, much clearer now. Do you mind adding that explanation to the
changelog text? If it's going into the stable kernel update, there
may be more people reading this with the same problem understanding
the patch.

	Arnd <><

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-09 20:25 ` Arnd Bergmann
@ 2007-07-09 21:16   ` Scott Wood
  2007-07-09 20:52     ` Arnd Bergmann
                       ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Scott Wood @ 2007-07-09 21:16 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linuxppc-dev, paulus

Arnd Bergmann wrote:
> On Monday 09 July 2007, Scott Wood wrote:
> 
>>In older versions of glibc (through 2.3), the dynamic linker executes a
>>small amount of code from the data segment, which is not marked as
>>executable.  A recent change (commit 9ba4ace39fdfe22268daca9f28c5df384ae462cf)
>>stops this from working; there should be a deprecation period before
>>older glibc versions stop working.
>>
>>The problem has been observed on glibc 2.2.  While glibc 2.3 has the same
>>code, I did not see the problem; it may be that it accesses the page in
>>question as data before executing from it, and thus it is already mapped.
> 
> 
> I may be missing the obvious, but doesn't that defeat the purpose of
> non-executable mappings?

The hardware in question doesn't support non-executable mappings; 
otherwise, it'd never have worked in the first place.  Note that this is 
only allowed on 32-bit, non-book-E.

There isn't much value in enforcing non-exec mappings only if it happens 
to be the first fault on a given page.

-Scott

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-09 21:16   ` Scott Wood
  2007-07-09 20:52     ` Arnd Bergmann
@ 2007-07-09 21:29     ` Linas Vepstas
  2007-07-09 21:32     ` Scott Wood
  2007-07-10 13:08     ` Segher Boessenkool
  3 siblings, 0 replies; 15+ messages in thread
From: Linas Vepstas @ 2007-07-09 21:29 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev, paulus, Arnd Bergmann

On Mon, Jul 09, 2007 at 04:16:40PM -0500, Scott Wood wrote:
> Arnd Bergmann wrote:
> > I may be missing the obvious, but doesn't that defeat the purpose of
> > non-executable mappings?
> 
> The hardware in question doesn't support non-executable mappings; 
> otherwise, it'd never have worked in the first place.  Note that this is 
> only allowed on 32-bit, non-book-E.
> 
> There isn't much value in enforcing non-exec mappings only if it happens 
> to be the first fault on a given page.

Thank you. I was reading this thread last week, and scratching my head,
thinking wtf ??

--linas

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-09 21:16   ` Scott Wood
  2007-07-09 20:52     ` Arnd Bergmann
  2007-07-09 21:29     ` Linas Vepstas
@ 2007-07-09 21:32     ` Scott Wood
  2007-07-10 13:08     ` Segher Boessenkool
  3 siblings, 0 replies; 15+ messages in thread
From: Scott Wood @ 2007-07-09 21:32 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev, paulus, Arnd Bergmann

Scott Wood wrote:
> Arnd Bergmann wrote:
>> I may be missing the obvious, but doesn't that defeat the purpose of
>> non-executable mappings?
> 
> 
> The hardware in question doesn't support non-executable mappings; 
> otherwise, it'd never have worked in the first place.  Note that this is 
> only allowed on 32-bit, non-book-E.

To be more precise, the classic MMU does appear to have non-exec 
functionality, but at the segment level, which is less than useful for 
implementing vma flags.

-Scott

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-09 21:16   ` Scott Wood
                       ` (2 preceding siblings ...)
  2007-07-09 21:32     ` Scott Wood
@ 2007-07-10 13:08     ` Segher Boessenkool
  2007-07-10 23:29       ` Paul Mackerras
  3 siblings, 1 reply; 15+ messages in thread
From: Segher Boessenkool @ 2007-07-10 13:08 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev, paulus, Arnd Bergmann

>> I may be missing the obvious, but doesn't that defeat the purpose of
>> non-executable mappings?
>
> The hardware in question doesn't support non-executable mappings;

Not on a per-page basis, anyway.

> otherwise, it'd never have worked in the first place.  Note that  
> this is
> only allowed on 32-bit, non-book-E.
>
> There isn't much value in enforcing non-exec mappings only if it  
> happens
> to be the first fault on a given page.

Yeah.  Giving the warning is a good thing though.


Segher

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-09 19:57 [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning Scott Wood
  2007-07-09 20:25 ` Arnd Bergmann
@ 2007-07-10 13:11 ` Segher Boessenkool
  1 sibling, 0 replies; 15+ messages in thread
From: Segher Boessenkool @ 2007-07-10 13:11 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev, paulus

> In older versions of glibc (through 2.3), the dynamic linker  
> executes a
> small amount of code from the data segment, which is not marked as
> executable.  A recent change (commit  
> 9ba4ace39fdfe22268daca9f28c5df384ae462cf)
> stops this from working; there should be a deprecation period before
> older glibc versions stop working.
>
> The problem has been observed on glibc 2.2.  While glibc 2.3 has  
> the same
> code, I did not see the problem; it may be that it accesses the  
> page in
> question as data before executing from it, and thus it is already  
> mapped.
>
> Signed-off-by: Scott Wood <scottwood@freescale.com>

Acked-by: Segher Boessenkool <segher@kernel.crashing.org>

> Unfortunately, this didn't make it into 2.6.22, but it should  
> probably go
> into the stable branch...

Both .21.x and .22.x I suppose; if we care about glibc 2.2.x
at all still, that is.

So to make double sure, this doesn't warn on glibc 2.3.x?


Segher

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-10 13:08     ` Segher Boessenkool
@ 2007-07-10 23:29       ` Paul Mackerras
  2007-07-11  0:03         ` Segher Boessenkool
  0 siblings, 1 reply; 15+ messages in thread
From: Paul Mackerras @ 2007-07-10 23:29 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, Arnd Bergmann

Segher Boessenkool writes:

> Yeah.  Giving the warning is a good thing though.

No, it isn't; it's just noise, if we're not ever going to do anything
to prevent the behaviour - and we can't.

Paul.

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-10 23:29       ` Paul Mackerras
@ 2007-07-11  0:03         ` Segher Boessenkool
  2007-07-11  1:02           ` Paul Mackerras
  2007-07-17  2:42           ` David Gibson
  0 siblings, 2 replies; 15+ messages in thread
From: Segher Boessenkool @ 2007-07-11  0:03 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: linuxppc-dev, Arnd Bergmann

>> Yeah.  Giving the warning is a good thing though.
>
> No, it isn't; it's just noise, if we're not ever going to do anything
> to prevent the behaviour - and we can't.

The same userland code will not run correctly on PPC64 or BookE
systems.  Is that not a reason to warn?


Segher

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-11  0:03         ` Segher Boessenkool
@ 2007-07-11  1:02           ` Paul Mackerras
  2007-07-17  2:42           ` David Gibson
  1 sibling, 0 replies; 15+ messages in thread
From: Paul Mackerras @ 2007-07-11  1:02 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, Arnd Bergmann

Segher Boessenkool writes:

> >> Yeah.  Giving the warning is a good thing though.
> >
> > No, it isn't; it's just noise, if we're not ever going to do anything
> > to prevent the behaviour - and we can't.
> 
> The same userland code will not run correctly on PPC64 or BookE
> systems.  Is that not a reason to warn?

It *will* run on ppc64 systems, because there we get the
READ_IMPLIES_EXEC personality flag set via the elf_read_implies_exec
thing in include/asm-powerpc/elf.h.  The READ_IMPLIES_EXEC flag is
only set if we don't have the non-executable stack note in the ELF
header, i.e. only for old binaries or libraries.

As for Book E, that could be fixed using elf_read_implies_exec too, if
anyone cared.  In fact maybe the correct solution is to have

#define elf_read_implies_exec(ex, exec_stk) \
	(exec_stk != EXSTACK_DISABLE_X) : 0)

for all 32-bit powerpc.

Paul.

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-11  0:03         ` Segher Boessenkool
  2007-07-11  1:02           ` Paul Mackerras
@ 2007-07-17  2:42           ` David Gibson
  2007-07-17 15:18             ` Segher Boessenkool
  1 sibling, 1 reply; 15+ messages in thread
From: David Gibson @ 2007-07-17  2:42 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, Paul Mackerras, Arnd Bergmann

On Wed, Jul 11, 2007 at 02:03:24AM +0200, Segher Boessenkool wrote:
> >> Yeah.  Giving the warning is a good thing though.
> >
> > No, it isn't; it's just noise, if we're not ever going to do anything
> > to prevent the behaviour - and we can't.
> 
> The same userland code will not run correctly on PPC64 or BookE
> systems.  Is that not a reason to warn?

Way back when, I distinctly recall aborting my plans to implement
per-page exec on 40x, precisely because of executables like this.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-17  2:42           ` David Gibson
@ 2007-07-17 15:18             ` Segher Boessenkool
  2007-07-17 16:30               ` Kumar Gala
  0 siblings, 1 reply; 15+ messages in thread
From: Segher Boessenkool @ 2007-07-17 15:18 UTC (permalink / raw)
  To: David Gibson; +Cc: linuxppc-dev, Paul Mackerras, Arnd Bergmann

>>>> Yeah.  Giving the warning is a good thing though.
>>>
>>> No, it isn't; it's just noise, if we're not ever going to do  
>>> anything
>>> to prevent the behaviour - and we can't.
>>
>> The same userland code will not run correctly on PPC64 or BookE
>> systems.  Is that not a reason to warn?
>
> Way back when, I distinctly recall aborting my plans to implement
> per-page exec on 40x, precisely because of executables like this.

I noticed some comments to that effect in the BookE code,
yes.  It seems userland has been fixed enough that you
could think about enabling it again FWIW.


Segher

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-17 15:18             ` Segher Boessenkool
@ 2007-07-17 16:30               ` Kumar Gala
  2007-07-17 16:37                 ` Segher Boessenkool
  0 siblings, 1 reply; 15+ messages in thread
From: Kumar Gala @ 2007-07-17 16:30 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: linuxppc-dev, Paul Mackerras, Arnd Bergmann, David Gibson


On Jul 17, 2007, at 10:18 AM, Segher Boessenkool wrote:

>>>>> Yeah.  Giving the warning is a good thing though.
>>>>
>>>> No, it isn't; it's just noise, if we're not ever going to do
>>>> anything
>>>> to prevent the behaviour - and we can't.
>>>
>>> The same userland code will not run correctly on PPC64 or BookE
>>> systems.  Is that not a reason to warn?
>>
>> Way back when, I distinctly recall aborting my plans to implement
>> per-page exec on 40x, precisely because of executables like this.
>
> I noticed some comments to that effect in the BookE code,
> yes.  It seems userland has been fixed enough that you
> could think about enabling it again FWIW.

Did I miss the posting of the patch with the fix?

- k

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

* Re: [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning.
  2007-07-17 16:30               ` Kumar Gala
@ 2007-07-17 16:37                 ` Segher Boessenkool
  0 siblings, 0 replies; 15+ messages in thread
From: Segher Boessenkool @ 2007-07-17 16:37 UTC (permalink / raw)
  To: Kumar Gala; +Cc: linuxppc-dev, Paul Mackerras, Arnd Bergmann, David Gibson

>>> Way back when, I distinctly recall aborting my plans to implement
>>> per-page exec on 40x, precisely because of executables like this.
>>
>> I noticed some comments to that effect in the BookE code,
>> yes.  It seems userland has been fixed enough that you
>> could think about enabling it again FWIW.
>
> Did I miss the posting of the patch with the fix?

glibc-2.2 seems to be the last "bad" one.  We are at
glibc-2.6 or so nowadays...


Segher

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

end of thread, other threads:[~2007-07-17 16:37 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-09 19:57 [PATCH] Allow exec on 32-bit from readable, non-exec pages, with a warning Scott Wood
2007-07-09 20:25 ` Arnd Bergmann
2007-07-09 21:16   ` Scott Wood
2007-07-09 20:52     ` Arnd Bergmann
2007-07-09 21:29     ` Linas Vepstas
2007-07-09 21:32     ` Scott Wood
2007-07-10 13:08     ` Segher Boessenkool
2007-07-10 23:29       ` Paul Mackerras
2007-07-11  0:03         ` Segher Boessenkool
2007-07-11  1:02           ` Paul Mackerras
2007-07-17  2:42           ` David Gibson
2007-07-17 15:18             ` Segher Boessenkool
2007-07-17 16:30               ` Kumar Gala
2007-07-17 16:37                 ` Segher Boessenkool
2007-07-10 13:11 ` Segher Boessenkool

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