Skip to contentSkip to conversation

Fix si->si_code for guard page access on PowerPC

RFC In review Gustavo Romero 2 participants 2 messages Jan 22, 2016 – Feb 24, 2016 PowerPC

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Fix si->si_code for guard page access on PowerPC

Fix si->si_code for guard page access on PowerPC

Currently, the mm code on PowerPC/POWER returns a si->si_code = 2 (SEGV_ACCERR) when the stack tries to grow beyond the stack guard (stack ulimit). On other architectures, notably x86, the si->si_code returned when a guard page access occurs is 1 (SEGV_MAPERR).

Although si->si_code is not historically reliable and hence no program should trust it for any semantic behavior, the right si->si_code for a guard page access is 1 (SEGV_MAPERR) and, besides that, some tests still trust it in specific cases.

On PowerPC/POWER, if the mm tries to expand the stack and hits a page mapped by the program (say, an anonymous page with permission ---p) it generates a SIG_SEGV and a si->si_code = 2 (SEGV_ACCERR), the same way it happens on x86. But then, when this guard page is removed (un-mapped) and the stack grows again reaching the stack guard (stack ulimit), the mm generates a SIG_SEGV and a si->si_code = 2 (SEGV_ACCERR) again, contrary to, for example, what happens on x86 (si->si_code = 1 (SIG_MAPERR)). It means that on PowerPC/POWER there is no semantic difference between a stack growth hitting a mapped area the stack has no permission to rd/wr and reaching the stack limit (stack ulimit), although indeed there is a difference.

---
 arch/powerpc/mm/fault.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/mm/fault.c +3 -1
index a67c6d7..6954971 100644
@@ -431,8 +431,10 @@ good_area:
           */
          fault = handle_mm_fault(mm, vma, address, flags);
          if (unlikely(fault & (VM_FAULT_RETRY|VM_FAULT_ERROR))) {
-                  if (fault & VM_FAULT_SIGSEGV)
+                  if (fault & VM_FAULT_SIGSEGV) {
+                           code = SEGV_MAPERR;
                            goto bad_area;
+                  }
                   rc = mm_fault_error(regs, address, fault);
                   if (rc >= MM_FAULT_RETURN)
                            goto bail;
#1 lore raw

Hi Gustavo,

Quoted 2 lines · Gustavo Romero

Fix si->si_code for guard page access on PowerPC

...

Quoted 7 lines
arch/powerpc/mm/fault.c +0 -0
index a67c6d7..6954971 100644
@@ -431,8 +431,10 @@ good_area:
            */

arch/powerpc/mm/fault.c good_area: · line 440

Quoted 10 lines
arch/powerpc/mm/fault.c +3 -1
           fault = handle_mm_fault(mm, vma, address, flags);
           if (unlikely(fault & (VM_FAULT_RETRY|VM_FAULT_ERROR))) {
-                  if (fault & VM_FAULT_SIGSEGV)
+                  if (fault & VM_FAULT_SIGSEGV) {
+                           code = SEGV_MAPERR;
                             goto bad_area;
+                  }
                    rc = mm_fault_error(regs, address, fault);
                    if (rc >= MM_FAULT_RETURN)
                             goto bail;

As we discussed on IRC, I'd prefer if this case was handled in mm_fault_error(). So please send a v2 which does that, or let us know if you have problems.

cheers