Skip to contentSkip to conversation

check put_user fail in do_signal when enable OABI_COMPACT

PATCH New Janboe Ye 7 participants 29 messages Oct 21, 2009 – Nov 23, 2009 Arm (32-bit)

lore
Share & tools
lore

Janboe Ye

author
#0 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Using OABI, do_signal need to copy restart_syscall to user stack. It is possible that put_user fail. This triggers flush_icache page fault and crash kernel.

---
 arch/arm/kernel/signal.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)
arch/arm/kernel/signal.c +13 -8
index f6bc5d4..2122d43 100644
@@ -626,6 +626,7 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
 	struct k_sigaction ka;
 	siginfo_t info;
 	int signr;
+	int ret = 0;
 
 	/*
 	 * We want the common case to go fast, which
@@ -679,16 +680,20 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
 				 */
 				swival = swival - __NR_SYSCALL_BASE + __NR_OABI_SYSCALL_BASE;
 
-				put_user(regs->ARM_pc, &usp[0]);
+				ret |= put_user(regs->ARM_pc, &usp[0]);
 				/* swi __NR_restart_syscall */
-				put_user(0xef000000 | swival, &usp[1]);
+				ret |= put_user(0xef000000 | swival, &usp[1]);
 				/* ldr	pc, [sp], #12 */
-				put_user(0xe49df00c, &usp[2]);
-
-				flush_icache_range((unsigned long)usp,
-						   (unsigned long)(usp + 3));
-
-				regs->ARM_pc = regs->ARM_sp + 4;
+				ret |= put_user(0xe49df00c, &usp[2]);
+				if (!ret) {
+					flush_icache_range((unsigned long)usp,
+						(unsigned long)(usp + 3));
+
+					regs->ARM_pc = regs->ARM_sp + 4;
+				} else {
+					regs->ARM_sp += 12;
+					force_sigsegv(0, current);
+				}
 #endif
 			}
 		}
Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

hi,
No one think that it is possible that put_user could fail in some situation even if currently kernel subtract 12 from ARM_sp and cross page bound?

Thanks

Janboe

2009/10/21 Janboe Ye <[email protected]>:

Quoted 59 lines

Using OABI, do_signal need to copy restart_syscall to user stack. It is possible that put_user fail. This triggers flush_icache page fault and crash kernel.

---
?arch/arm/kernel/signal.c | ? 21 +++++++++++++-------- ?1 files changed, 13 insertions(+), 8 deletions(-)

arch/arm/kernel/signal.c +1 -0
index f6bc5d4..2122d43 100644
@@ -626,6 +626,7 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
 ? ? ? ?struct k_sigaction ka;
 ? ? ? ?siginfo_t info;
 ? ? ? ?int signr;
+ ? ? ? int ret = 0;
 

? ? ? ?/*
? ? ? ? * We want the common case to go fast, which

arch/arm/kernel/signal.c +0 -0
@@ -679,16 +680,20 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? */
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?swival = swival - __NR_SYSCALL_BASE + __NR_OABI_SYSCALL_BASE;

- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? put_user(regs->ARM_pc, &usp[0]);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ret |= put_user(regs->ARM_pc, &usp[0]); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/* swi __NR_restart_syscall */
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? put_user(0xef000000 | swival, &usp[1]);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ret |= put_user(0xef000000 | swival, &usp[1]); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/* ldr ?pc, [sp], #12 */
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? put_user(0xe49df00c, &usp[2]);

arch/arm/kernel/signal.c +10 -5
-
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? flush_icache_range((unsigned long)usp,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(unsigned long)(usp + 3));
-
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? regs->ARM_pc = regs->ARM_sp + 4;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ret |= put_user(0xe49df00c, &usp[2]);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (!ret) {
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? flush_icache_range((unsigned long)usp,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (unsigned long)(usp + 3));
+
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? regs->ARM_pc = regs->ARM_sp + 4;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } else {
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? regs->ARM_sp += 12;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? force_sigsegv(0, current);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

?#endif
? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?}
--
1.6.3.3

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 4 lines · ye janboe

hi,
No one think that it is possible that put_user could fail in some situation even if currently kernel subtract 12 from ARM_sp and cross page bound?

It is possible, and it's something we should fix. Note there's another fix in this area (I've just posted) which will make your patch invalid. Please wait until we've sorted out this other patch.

#3 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

hi, Russell

Your patch looks good for real fixing this issue.

2009/10/24 Russell King - ARM Linux <[email protected]>:

Quoted 10 lines · ye janboe
Quoted 4 lines

hi,
No one think that it is possible that put_user could fail in some situation even if currently kernel subtract 12 from ARM_sp and cross page bound?

It is possible, and it's something we should fix. ?Note there's another fix in this area (I've just posted) which will make your patch invalid. Please wait until we've sorted out this other patch.

#4 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 3 lines · ye janboe

hi, Russell

Your patch looks good for real fixing this issue.

My patch doesn't address your issue, it only addresses a previous problem. We're still decrementing the stack pointer and writing to a possible new page - which could fault.

Therefore, your patch is still required, but it needs to be modified to apply on top of my patch.

A replacement patch would be welcome.

#5 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Sure. Russell

After you restart_syscall patch are merged, I will send out another patch.

Thanks

2009/10/25 Russell King - ARM Linux <[email protected]>:

Quoted 14 lines · ye janboe
Quoted 3 lines

hi, Russell

Your patch looks good for real fixing this issue.

My patch doesn't address your issue, it only addresses a previous problem. ?We're still decrementing the stack pointer and writing to a possible new page - which could fault.

Therefore, your patch is still required, but it needs to be modified to apply on top of my patch.

A replacement patch would be welcome.

#6 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Russell, Janboe,

Quoted 3 lines · On Monday 26 October 2009 03:59:23 ye janboe wrote:

Sure. Russell

After you restart_syscall patch are merged, I will send out another patch.

Here is what I ended up with after merging.
It has been tested on OMAP3 boards although I could not trigger the failing put_user test case.

What do you think?

Regards,
Jean

Quoted 1 line

From dcaf0812f86948fe1c9dbb9fe53e9040f5a6deeb Mon Sep 17 00:00:00 2001

From: Jean Pihet <[email protected]>
Date: Tue, 27 Oct 2009 10:09:22 +0100
Subject: ARM: Check put_user fail in do_signal when enable OABI_COMPAT

Using OABI, do_signal need to copy restart_syscall to user stack. It is possible that put_user fail. This triggers flush_icache page fault and crash kernel.

Merged from
http://lists.infradead.org/pipermail/linux-arm-kernel/2009-October/002621.html
on top of
http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2

Tested with multiple sleeping apps/threads (using the nanosleep syscall) and suspend/resume.

---
 arch/arm/kernel/signal.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
arch/arm/kernel/signal.c +0 -0
index 998fa8d..8ac56fe 100644
@@ -643,6 +643,7 @@ static int do_signal(sigset_t *oldset, struct pt_regs 

*regs, int syscall)
struct k_sigaction ka;
siginfo_t info;
int signr;
+ int ret = 0;

/*
* We want the common case to go fast, which
@@ -685,8 +686,15 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
regs->ARM_sp -= 4;
usp = (u32 __user *)regs->ARM_sp;

- put_user(regs->ARM_pc, usp);
- regs->ARM_pc = KERN_RESTART_CODE;
+ ret |= put_user(regs->ARM_pc, usp);
+ if (!ret) {
+ flush_icache_range((unsigned long)usp,
+ (unsigned long)(usp + 1));
+ regs->ARM_pc = KERN_RESTART_CODE;
+ } else {
+ regs->ARM_sp += 4;
+ force_sigsegv(0, current);
+ }
#endif
}
}

Quoted 22 lines

Thanks

2009/10/25 Russell King - ARM Linux <[email protected]>:

Quoted 5 lines · ye janboe
Quoted 3 lines

hi, Russell

Your patch looks good for real fixing this issue.

Quoted 8 lines

My patch doesn't address your issue, it only addresses a previous problem. ?We're still decrementing the stack pointer and writing to a possible new page - which could fault.

Therefore, your patch is still required, but it needs to be modified to apply on top of my patch.

A replacement patch would be welcome.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#7 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 11 lines · Jean Pihet

Russell, Janboe,

Quoted 3 lines · On Monday 26 October 2009 03:59:23 ye janboe wrote:

Sure. Russell

After you restart_syscall patch are merged, I will send out another patch.

Here is what I ended up with after merging.
It has been tested on OMAP3 boards although I could not trigger the failing put_user test case.

What do you think?

Looks fine, thanks.

#8 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

looks fine too. Thanks

2009/10/27 Russell King - ARM Linux <[email protected]>:

Quoted 15 lines · Jean Pihet
Quoted 11 lines

Russell, Janboe,

Quoted 3 lines · On Monday 26 October 2009 03:59:23 ye janboe wrote:

Sure. Russell

After you restart_syscall patch are merged, I will send out another patch.

Here is what I ended up with after merging.
It has been tested on OMAP3 boards although I could not trigger the failing put_user test case.

What do you think?

Looks fine, thanks.

#9 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

In reply to Jean Pihet
Quoted 18 lines · Jean Pihet
arch/arm/kernel/signal.c +1 -0
@@ -643,6 +643,7 @@ static int do_signal(sigset_t *oldset, struct pt_regs 
 *regs, int syscall)
 	struct k_sigaction ka;
 	siginfo_t info;
 	int signr;
+	int ret = 0;
 
 	/*
arch/arm/kernel/signal.c +0 -2
 	 * We want the common case to go fast, which
@@ -685,8 +686,15 @@ static int do_signal(sigset_t *oldset, struct pt_regs 
 *regs, int syscall)
 				regs->ARM_sp -= 4;
 				usp = (u32 __user *)regs->ARM_sp;
 
-				put_user(regs->ARM_pc, usp);
-				regs->ARM_pc = KERN_RESTART_CODE;

arch/arm/kernel/signal.c static int do_signal(sigset_t *oldset, struct pt_regs · line 699

Quoted 10 lines
arch/arm/kernel/signal.c +9 -0
+				ret |= put_user(regs->ARM_pc, usp);
+				if (!ret) {
+					flush_icache_range((unsigned long)usp,
+						(unsigned long)(usp + 1));
+					regs->ARM_pc = KERN_RESTART_CODE;
+				} else {
+					regs->ARM_sp += 4;
+					force_sigsegv(0, current);
+				}
 #endif

I don't like this 'ret' variable:
- it's only for OABI, but declared at the top and initialised also for EABI
- you update it with |=, but clearly there's no useful previous value

I'd drop 'ret' and just do:

				if (put_user(regs->ARM_pc, usp) == 0) {
					flush...
				} else {
					... force_sigsegv
				}

(Note: == 0 not !, since ! is often read as "failed" whereas for put_user() 0 means Ok and non-zero means -errno.)

#10 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Hi,

On Tuesday 27 October 2009 16:42:43 Mikael Pettersson wrote:
...

Quoted 7 lines

I don't like this 'ret' variable:
- it's only for OABI, but declared at the top and initialised also for EABI
- you update it with |=, but clearly there's no useful previous value

I'd drop 'ret' and just do:

Quoted 8 lines
				if (put_user(regs->ARM_pc, usp) == 0) {
					flush...
				} else {
					... force_sigsegv
				}

(Note: == 0 not !, since ! is often read as "failed" whereas for put_user() 0 means Ok and non-zero means -errno.)

Yes that improves the code readability. Thanks for the suggestion.

Here is an updated patch.

Regards,
Jean

Quoted 1 line

From 885a5952dd38bc0c023e52f731ea2681d43132ba Mon Sep 17 00:00:00 2001

From: Jean Pihet <[email protected]>
Date: Tue, 27 Oct 2009 10:09:22 +0100
Subject: ARM: Check put_user fail in do_signal when enable OABI_COMPAT

Using OABI, do_signal need to copy restart_syscall to user stack. It is possible that put_user fail. This triggers flush_icache page fault and crash kernel.

Merged from
http://lists.infradead.org/pipermail/linux-arm-kernel/2009-October/002621.html
on top of
http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2

Tested with multiple sleeping apps/threads (using the nanosleep syscall) and suspend/resume.

---
 arch/arm/kernel/signal.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
arch/arm/kernel/signal.c +0 -0
index f330974..4366cc0 100644
@@ -676,8 +676,14 @@ static int do_signal(sigset_t *oldset, struct pt_regs 

*regs, int syscall)
regs->ARM_sp -= 4;
usp = (u32 __user *)regs->ARM_sp;

- put_user(regs->ARM_pc, usp);
- regs->ARM_pc = KERN_RESTART_CODE;
+ if (put_user(regs->ARM_pc, usp) == 0) {
+ flush_icache_range((unsigned long)usp,
+ (unsigned long)(usp + 1));
+ regs->ARM_pc = KERN_RESTART_CODE;
+ } else {
+ regs->ARM_sp += 4;
+ force_sigsegv(0, current);
+ }
#endif
}
}

Signature · 1 line
1.6.2.5.168.g3823
#11 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 5 lines · Jean Pihet
arch/arm/kernel/signal.c +0 -0
index f330974..4366cc0 100644

arch/arm/kernel/signal.c static int do_signal(sigset_t *oldset, struct pt_regs · line 682

Quoted 9 lines
arch/arm/kernel/signal.c +3 -2
@@ -676,8 +676,14 @@ static int do_signal(sigset_t *oldset, struct pt_regs 
 *regs, int syscall)
 				regs->ARM_sp -= 4;
 				usp = (u32 __user *)regs->ARM_sp;
 
-				put_user(regs->ARM_pc, usp);
-				regs->ARM_pc = KERN_RESTART_CODE;
+				if (put_user(regs->ARM_pc, usp) == 0) {
+					flush_icache_range((unsigned long)usp,
+						(unsigned long)(usp + 1));

Why are you flushing the icache? There is no code on the stack anymore.

Nicolas

#12 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 10 lines · On Tuesday 27 October 2009 19:08:07 Nicolas Pitre wrote:
Quoted 9 lines · Jean Pihet
arch/arm/kernel/signal.c +0 -0
index f330974..4366cc0 100644
@@ -676,8 +676,14 @@ static int do_signal(sigset_t *oldset, struct
 pt_regs *regs, int syscall)
 				regs->ARM_sp -= 4;
 				usp = (u32 __user *)regs->ARM_sp;
 
Quoted 7 lines

arch/arm/kernel/signal.c static int do_signal(sigset_t *oldset, struct · line 682

Quoted 5 lines
arch/arm/kernel/signal.c +3 -2
-				put_user(regs->ARM_pc, usp);
-				regs->ARM_pc = KERN_RESTART_CODE;
+				if (put_user(regs->ARM_pc, usp) == 0) {
+					flush_icache_range((unsigned long)usp,
+						(unsigned long)(usp + 1));

Why are you flushing the icache? There is no code on the stack anymore.

Yes indeed there is no more code modified.
Side question: does the put_user requires a flush of some sort? If not, why?

Is it OK to re-send a patch with the call to flush_icache_range removed?

Thanks!

Quoted 1 line

Nicolas

Jean

#13 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 18 lines · Jean Pihet
Quoted 10 lines · On Tuesday 27 October 2009 19:08:07 Nicolas Pitre wrote:
Quoted 9 lines · Jean Pihet
arch/arm/kernel/signal.c +0 -0
index f330974..4366cc0 100644
@@ -676,8 +676,14 @@ static int do_signal(sigset_t *oldset, struct
 pt_regs *regs, int syscall)
 				regs->ARM_sp -= 4;
 				usp = (u32 __user *)regs->ARM_sp;
 
Quoted 7 lines

arch/arm/kernel/signal.c static int do_signal(sigset_t *oldset, struct · line 682

Quoted 5 lines
arch/arm/kernel/signal.c +3 -2
-				put_user(regs->ARM_pc, usp);
-				regs->ARM_pc = KERN_RESTART_CODE;
+				if (put_user(regs->ARM_pc, usp) == 0) {
+					flush_icache_range((unsigned long)usp,
+						(unsigned long)(usp + 1));

Why are you flushing the icache? There is no code on the stack anymore.

Quoted 2 lines

Yes indeed there is no more code modified.
Side question: does the put_user requires a flush of some sort? If not, why?

No because it stores data into the d-cache directly at the virtual address to be used by user space. Previously the d-cache needed to be cleaned for data to hit main memory and the i-cache invalidated for the newly stored _code_ to be seen by the instruction path. Since there is no code involved anymore the cache flushes are useless.

Quoted 1 line

Is it OK to re-send a patch with the call to flush_icache_range removed?

Yes.

Nicolas

#14 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Nicolas,

On Tuesday 27 October 2009 19:59:36 Nicolas Pitre wrote:
...

Quoted 9 lines
Quoted 2 lines

Side question: does the put_user requires a flush of some sort? If not, why?

No because it stores data into the d-cache directly at the virtual address to be used by user space. Previously the d-cache needed to be cleaned for data to hit main memory and the i-cache invalidated for the newly stored _code_ to be seen by the instruction path. Since there is no code involved anymore the cache flushes are useless.

Quoted 3 lines
Quoted 1 line

Is it OK to re-send a patch with the call to flush_icache_range removed?

Yes.

Ok here is the updated patch. Let's hope it is the good one that time ;-)

Can it be merged? It applies cleanly on top of Russell's latest patch
(http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2).

Quoted 3 lines

Nicolas

Regards,
Jean

---

Quoted 1 line

From d862e03679f7ea44fca1bf1ea256bbade3fbe76a Mon Sep 17 00:00:00 2001

From: Jean Pihet <[email protected]>
Date: Tue, 27 Oct 2009 10:09:22 +0100
Subject: ARM: Check put_user fail in do_signal when enable OABI_COMPAT

Using OABI, do_signal need to copy restart_syscall to user stack. It is possible that put_user fail. This triggers flush_icache page fault and crash kernel.

Merged from
http://lists.infradead.org/pipermail/linux-arm-kernel/2009-October/002621.html
on top of
http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2

Tested with multiple sleeping apps/threads (using the nanosleep syscall) and suspend/resume.

---
 arch/arm/kernel/signal.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
arch/arm/kernel/signal.c +0 -0
index f330974..ea9722a 100644
@@ -676,8 +676,12 @@ static int do_signal(sigset_t *oldset, struct pt_regs 

*regs, int syscall)
regs->ARM_sp -= 4;
usp = (u32 __user *)regs->ARM_sp;

- put_user(regs->ARM_pc, usp);
- regs->ARM_pc = KERN_RESTART_CODE;
+ if (put_user(regs->ARM_pc, usp) == 0) {
+ regs->ARM_pc = KERN_RESTART_CODE;
+ } else {
+ regs->ARM_sp += 4;
+ force_sigsegv(0, current);
+ }
#endif
}
}

Signature · 1 line
1.6.2.5.168.g3823
#15 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 13 lines · Jean Pihet

Nicolas,

On Tuesday 27 October 2009 19:59:36 Nicolas Pitre wrote:
...

Quoted 9 lines
Quoted 2 lines

Side question: does the put_user requires a flush of some sort? If not, why?

No because it stores data into the d-cache directly at the virtual address to be used by user space. Previously the d-cache needed to be cleaned for data to hit main memory and the i-cache invalidated for the newly stored _code_ to be seen by the instruction path. Since there is no code involved anymore the cache flushes are useless.

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

Is it OK to re-send a patch with the call to flush_icache_range removed?

Yes.

Ok here is the updated patch. Let's hope it is the good one that time ;-)

Well, the commit message is certainly wrong. There is no copying of restart_syscall to user stack anymore.

And is there a reason for touching sp in the error case?

Quoted 59 lines

Can it be merged? It applies cleanly on top of Russell's latest patch
(http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2).

Quoted 3 lines

Nicolas

Regards,
Jean

---
From d862e03679f7ea44fca1bf1ea256bbade3fbe76a Mon Sep 17 00:00:00 2001
From: Jean Pihet <[email protected]>
Date: Tue, 27 Oct 2009 10:09:22 +0100
Subject: ARM: Check put_user fail in do_signal when enable OABI_COMPAT

Using OABI, do_signal need to copy restart_syscall to user stack. It is possible that put_user fail. This triggers flush_icache page fault and crash kernel.

Merged from
http://lists.infradead.org/pipermail/linux-arm-kernel/2009-October/002621.html
on top of
http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2

Tested with multiple sleeping apps/threads (using the nanosleep syscall) and suspend/resume.

---
 arch/arm/kernel/signal.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
arch/arm/kernel/signal.c +6 -2
index f330974..ea9722a 100644
@@ -676,8 +676,12 @@ static int do_signal(sigset_t *oldset, struct pt_regs 
 *regs, int syscall)
 				regs->ARM_sp -= 4;
 				usp = (u32 __user *)regs->ARM_sp;
 
-				put_user(regs->ARM_pc, usp);
-				regs->ARM_pc = KERN_RESTART_CODE;
+				if (put_user(regs->ARM_pc, usp) == 0) {
+					regs->ARM_pc = KERN_RESTART_CODE;
+				} else {
+					regs->ARM_sp += 4;
+					force_sigsegv(0, current);
+				}
 #endif
 			}

}

Signature · 1 line
1.6.2.5.168.g3823
#16 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 17 lines · Nicolas Pitre
Quoted 15 lines · Jean Pihet

Nicolas,

On Tuesday 27 October 2009 19:59:36 Nicolas Pitre wrote:
...

Quoted 11 lines
Quoted 2 lines

Side question: does the put_user requires a flush of some sort? If not, why?

No because it stores data into the d-cache directly at the virtual address to be used by user space. Previously the d-cache needed to be cleaned for data to hit main memory and the i-cache invalidated for the newly stored _code_ to be seen by the instruction path. Since there is no code involved anymore the cache flushes are useless.

Quoted 1 line

Is it OK to re-send a patch with the call to flush_icache_range removed?

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Yes.

Ok here is the updated patch. Let's hope it is the good one that time ;-)

Well, the commit message is certainly wrong. There is no copying of restart_syscall to user stack anymore.

And is there a reason for touching sp in the error case?

Returning 'sp' seems to be a sane thing to do - otherwise debuggers analysing core dumps could be confused about the location of data on the stack.

#17 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 6 lines · Russell King - ARM Linux
Quoted 1 line · Nicolas Pitre

And is there a reason for touching sp in the error case?

Returning 'sp' seems to be a sane thing to do - otherwise debuggers analysing core dumps could be confused about the location of data on the stack.

Good point.

Nicolas

#18 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

In reply to Nicolas Pitre
Quoted 18 lines · On Tuesday 27 October 2009 20:35:31 Nicolas Pitre wrote:
Quoted 17 lines · Jean Pihet

Nicolas,

On Tuesday 27 October 2009 19:59:36 Nicolas Pitre wrote:
...

Quoted 12 lines
Quoted 2 lines

Side question: does the put_user requires a flush of some sort? If not, why?

No because it stores data into the d-cache directly at the virtual address to be used by user space. Previously the d-cache needed to be cleaned for data to hit main memory and the i-cache invalidated for the newly stored _code_ to be seen by the instruction path. Since there is no code involved anymore the cache flushes are useless.

Quoted 2 lines

Is it OK to re-send a patch with the call to flush_icache_range removed?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Yes.

Ok here is the updated patch. Let's hope it is the good one that time ;-)

Well, the commit message is certainly wrong. There is no copying of restart_syscall to user stack anymore.

Ok thanks for reviewing it! Here is a respin of the patch. Only the commit description has been touched.

Quoted 5 lines

And is there a reason for touching sp in the error case?

Quoted 2 lines

Can it be merged? It applies cleanly on top of Russell's latest patch
(http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2).

Same question: can those 2 patches be merged in? Can they be acked-by?

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

Nicolas

Thanks,
Jean

Quoted 1 line
Quoted 1 line

---

Quoted 1 line

From 28336b68b2e2507ba0922c55147e5e72ec1a88dc Mon Sep 17 00:00:00 2001

From: Jean Pihet <[email protected]>
Date: Tue, 27 Oct 2009 10:09:22 +0100
Subject: ARM: Check put_user fail in do_signal when enable OABI_COMPAT

Using OABI, the call to put_user in do_signal can fail. In that case flush_icache page faults and the calling app goes in an infinite loop.

The solution is to check if put_user fails and force the app to seg fault in that case.

Merged from
http://lists.infradead.org/pipermail/linux-arm-kernel/2009-October/002621.html
on top of
http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2

Tested with multiple sleeping apps/threads (using the nanosleep syscall) and suspend/resume.

---
 arch/arm/kernel/signal.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
arch/arm/kernel/signal.c +0 -0
index f330974..ea9722a 100644
@@ -676,8 +676,12 @@ static int do_signal(sigset_t *oldset, struct pt_regs 

*regs, int syscall)
regs->ARM_sp -= 4;
usp = (u32 __user *)regs->ARM_sp;

- put_user(regs->ARM_pc, usp);
- regs->ARM_pc = KERN_RESTART_CODE;
+ if (put_user(regs->ARM_pc, usp) == 0) {
+ regs->ARM_pc = KERN_RESTART_CODE;
+ } else {
+ regs->ARM_sp += 4;
+ force_sigsegv(0, current);
+ }
#endif
}
}

Signature · 1 line
1.6.2.5.168.g3823
#19 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 5 lines · Jean Pihet
Quoted 2 lines · On Tuesday 27 October 2009 20:35:31 Nicolas Pitre wrote:

Well, the commit message is certainly wrong. There is no copying of restart_syscall to user stack anymore.

Ok thanks for reviewing it! Here is a respin of the patch. Only the commit description has been touched.

[...]

Quoted 2 lines

Using OABI, the call to put_user in do_signal can fail. In that case flush_icache page faults and the calling app goes in an infinite loop.

Still wrong. Why flush_icache?

Nicolas

#20 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 8 lines · On Wednesday 28 October 2009 17:13:28 Nicolas Pitre wrote:
Quoted 6 lines · Jean Pihet
Quoted 2 lines · On Tuesday 27 October 2009 20:35:31 Nicolas Pitre wrote:

Well, the commit message is certainly wrong. There is no copying of restart_syscall to user stack anymore.

Ok thanks for reviewing it! Here is a respin of the patch. Only the commit description has been touched.

Quoted 6 lines

[...]

Quoted 2 lines

Using OABI, the call to put_user in do_signal can fail. In that case flush_icache page faults and the calling app goes in an infinite loop.

Still wrong. Why flush_icache?

Indeed that is wrong (again!). I had put it in the problem description but that does not apply anymore.

Thanks, will send an update.

Quoted 3 lines

Nicolas

Jean

Quoted 5 lines

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#21 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

On Wednesday 28 October 2009 17:23:01 Jean Pihet wrote:
...

Quoted 6 lines
Quoted 1 line

Still wrong. Why flush_icache?

Indeed that is wrong (again!). I had put it in the problem description but that does not apply anymore.

Thanks, will send an update.

Here is the updated patch. Is it OK?

Jean

Quoted 5 lines
Quoted 2 lines

Nicolas

Jean

---

Quoted 1 line

From 28336b68b2e2507ba0922c55147e5e72ec1a88dc Mon Sep 17 00:00:00 2001

From: Jean Pihet <[email protected]>
Date: Tue, 27 Oct 2009 10:09:22 +0100
Subject: ARM: Check put_user fail in do_signal when enable OABI_COMPAT

Source: Janboe Ye <[email protected]>
MR: 36048
Type: Defect Fix
Disposition: Submitted to linux-arm-kernel ML
ChangeID: 689ddf707d2232e9cf01387ac1264bc8812b9ffd Description:

Using OABI, the call to put_user in do_signal can fail causing the calling app to hang.

The solution is to check if put_user fails and force the app to seg fault in that case.

Merged from
http://lists.infradead.org/pipermail/linux-arm-kernel/2009-October/002621.html
on top of
http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2

Tested with multiple sleeping apps/threads (using the nanosleep syscall) and suspend/resume.

---
 arch/arm/kernel/signal.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
arch/arm/kernel/signal.c +0 -0
index f330974..ea9722a 100644
@@ -676,8 +676,12 @@ static int do_signal(sigset_t *oldset, struct pt_regs 

*regs, int syscall)
regs->ARM_sp -= 4;
usp = (u32 __user *)regs->ARM_sp;

- put_user(regs->ARM_pc, usp);
- regs->ARM_pc = KERN_RESTART_CODE;
+ if (put_user(regs->ARM_pc, usp) == 0) {
+ regs->ARM_pc = KERN_RESTART_CODE;
+ } else {
+ regs->ARM_sp += 4;
+ force_sigsegv(0, current);
+ }
#endif
}
}

Signature · 1 line
1.6.2.5.168.g3823
#22 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 9 lines · Jean Pihet

On Wednesday 28 October 2009 17:23:01 Jean Pihet wrote:
...

Quoted 6 lines
Quoted 1 line

Still wrong. Why flush_icache?

Indeed that is wrong (again!). I had put it in the problem description but that does not apply anymore.

Thanks, will send an update.

Here is the updated patch. Is it OK?

ACK.

Quoted 58 lines

---
From 28336b68b2e2507ba0922c55147e5e72ec1a88dc Mon Sep 17 00:00:00 2001
From: Jean Pihet <[email protected]>
Date: Tue, 27 Oct 2009 10:09:22 +0100
Subject: ARM: Check put_user fail in do_signal when enable OABI_COMPAT

Source: Janboe Ye <[email protected]>
MR: 36048
Type: Defect Fix
Disposition: Submitted to linux-arm-kernel ML
ChangeID: 689ddf707d2232e9cf01387ac1264bc8812b9ffd Description:

Using OABI, the call to put_user in do_signal can fail causing the calling app to hang.

The solution is to check if put_user fails and force the app to seg fault in that case.

Merged from
http://lists.infradead.org/pipermail/linux-arm-kernel/2009-October/002621.html
on top of
http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2

Tested with multiple sleeping apps/threads (using the nanosleep syscall) and suspend/resume.

---
 arch/arm/kernel/signal.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
arch/arm/kernel/signal.c +6 -2
index f330974..ea9722a 100644
@@ -676,8 +676,12 @@ static int do_signal(sigset_t *oldset, struct pt_regs 
 *regs, int syscall)
 				regs->ARM_sp -= 4;
 				usp = (u32 __user *)regs->ARM_sp;
 
-				put_user(regs->ARM_pc, usp);
-				regs->ARM_pc = KERN_RESTART_CODE;
+				if (put_user(regs->ARM_pc, usp) == 0) {
+					regs->ARM_pc = KERN_RESTART_CODE;
+				} else {
+					regs->ARM_sp += 4;
+					force_sigsegv(0, current);
+				}
 #endif
 			}

}

Signature · 1 line
1.6.2.5.168.g3823
#23 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

In reply to Jean Pihet

Review

Quoted 13 lines · Jean Pihet
(quoted diff) +6 -2
 				usp = (u32 __user *)regs->ARM_sp;
 
-				put_user(regs->ARM_pc, usp);
-				regs->ARM_pc = KERN_RESTART_CODE;
+				if (put_user(regs->ARM_pc, usp) == 0) {
+					regs->ARM_pc = KERN_RESTART_CODE;
+				} else {
+					regs->ARM_sp += 4;
+					force_sigsegv(0, current);
+				}
 #endif
 			}
 		}

This one looks good to me.

-- Jamie

#24 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

In reply to Jean Pihet

Russell,

Is this one OK? Can it be merged now that your fix for signal restart has been merged into mainline?

Regards,
Jean

Quoted 72 lines · On Wednesday 28 October 2009 18:00:47 Jean Pihet wrote:

On Wednesday 28 October 2009 17:23:01 Jean Pihet wrote:
...

Quoted 6 lines
Quoted 1 line

Still wrong. Why flush_icache?

Indeed that is wrong (again!). I had put it in the problem description but that does not apply anymore.

Thanks, will send an update.

Here is the updated patch. Is it OK?

Jean

Quoted 3 lines
Quoted 1 line

Nicolas

Jean

---
From 28336b68b2e2507ba0922c55147e5e72ec1a88dc Mon Sep 17 00:00:00 2001
From: Jean Pihet <[email protected]>
Date: Tue, 27 Oct 2009 10:09:22 +0100
Subject: ARM: Check put_user fail in do_signal when enable OABI_COMPAT

Source: Janboe Ye <[email protected]>
MR: 36048
Type: Defect Fix
Disposition: Submitted to linux-arm-kernel ML
ChangeID: 689ddf707d2232e9cf01387ac1264bc8812b9ffd Description:

Using OABI, the call to put_user in do_signal can fail causing the calling app to hang.

The solution is to check if put_user fails and force the app to seg fault in that case.

Merged from
http://lists.infradead.org/pipermail/linux-arm-kernel/2009-October/002621.h
tml on top of
http://marc.info/?l=linux-arm-kernel&m=125638133624452&w=2

Tested with multiple sleeping apps/threads (using the nanosleep syscall) and suspend/resume.

---
 arch/arm/kernel/signal.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
arch/arm/kernel/signal.c +6 -2
index f330974..ea9722a 100644
@@ -676,8 +676,12 @@ static int do_signal(sigset_t *oldset, struct pt_regs
 *regs, int syscall)
 				regs->ARM_sp -= 4;
 				usp = (u32 __user *)regs->ARM_sp;
 
-				put_user(regs->ARM_pc, usp);
-				regs->ARM_pc = KERN_RESTART_CODE;
+				if (put_user(regs->ARM_pc, usp) == 0) {
+					regs->ARM_pc = KERN_RESTART_CODE;
+				} else {
+					regs->ARM_sp += 4;
+					force_sigsegv(0, current);
+				}
 #endif
 			}

}

#25 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 2 lines · Jean Pihet

Is this one OK? Can it be merged now that your fix for signal restart has been merged into mainline?

Yes.

#26 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Russell,

Quoted 5 lines · On Wednesday 04 November 2009 20:32:44 Russell King - ARM Linux wrote:
Quoted 2 lines · Jean Pihet

Is this one OK? Can it be merged now that your fix for signal restart has been merged into mainline?

Yes.

May I ask you again to merge the patch? Is this one supposed to reach into mainline via your tree?

Regards,
Jean

#27 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 10 lines · Jean Pihet

Russell,

Quoted 5 lines · On Wednesday 04 November 2009 20:32:44 Russell King - ARM Linux wrote:
Quoted 2 lines · Jean Pihet

Is this one OK? Can it be merged now that your fix for signal restart has been merged into mainline?

Yes.

May I ask you again to merge the patch? Is this one supposed to reach into mainline via your tree?

I have a patch system to avoid patches being dropped like this... I'm really *bad* with emailed patches.

Please submit to the patch system, thanks.

#28 lore raw

PATCH 1/1 check put_user fail in do_signal when enable OABI_COMPACT

Quoted 10 lines · On Monday 23 November 2009 15:06:50 Russell King - ARM Linux wrote:
Quoted 9 lines · Jean Pihet

Russell,

Quoted 5 lines · On Wednesday 04 November 2009 20:32:44 Russell King - ARM Linux wrote:
Quoted 2 lines · Jean Pihet

Is this one OK? Can it be merged now that your fix for signal restart has been merged into mainline?

Yes.

Quoted 7 lines
Quoted 2 lines

May I ask you again to merge the patch? Is this one supposed to reach into mainline via your tree?

I have a patch system to avoid patches being dropped like this... I'm really *bad* with emailed patches.

Please submit to the patch system, thanks.

Ah ok! It is submitted as patch 5793/1.

Thanks,
Jean