* [PATCH 0/3] Fix private compat syscall emulation
@ 2019-01-03 18:13 Will Deacon
2019-01-03 18:13 ` [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers Will Deacon
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Will Deacon @ 2019-01-03 18:13 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Will Deacon, Dave.Martin, pihsun
Hi all,
These three fixes should address the issues reported in [1] relating to
our emulation of the ARM private syscall region.
Cheers,
Will
[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-January/623132.html
--->8
Will Deacon (3):
arm64: compat: Avoid sending SIGILL for unallocated syscall numbers
arm64: compat: Don't pull syscall number from regs in
arm_compat_syscall
arm64: compat: Hook up io_pgetevents() for 32-bit tasks
arch/arm64/include/asm/unistd.h | 7 ++++---
arch/arm64/include/asm/unistd32.h | 2 ++
arch/arm64/kernel/sys_compat.c | 11 +++++------
arch/arm64/kernel/syscall.c | 9 ++++-----
4 files changed, 15 insertions(+), 14 deletions(-)
--
2.1.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers
2019-01-03 18:13 [PATCH 0/3] Fix private compat syscall emulation Will Deacon
@ 2019-01-03 18:13 ` Will Deacon
2019-01-04 4:50 ` Sasha Levin
2019-01-04 12:54 ` Dave Martin
2019-01-03 18:13 ` [PATCH 2/3] arm64: compat: Don't pull syscall number from regs in arm_compat_syscall Will Deacon
2019-01-03 18:14 ` [PATCH 3/3] arm64: compat: Hook up io_pgetevents() for 32-bit tasks Will Deacon
2 siblings, 2 replies; 10+ messages in thread
From: Will Deacon @ 2019-01-03 18:13 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: stable, Will Deacon, Dave.Martin, pihsun
The ARM Linux kernel handles the EABI syscall numbers as follows:
0 - NR_SYSCALLS-1 : Invoke syscall via syscall table
NR_SYSCALLS - 0xeffff : -ENOSYS (to be allocated in future)
0xf0000 - 0xf07ff : Private syscall or -ENOSYS if not allocated
> 0xf07ff : SIGILL
Our compat code gets this wrong and ends up sending SIGILL in response
to all syscalls greater than NR_SYSCALLS which have a value greater
than 0x7ff in the bottom 16 bits.
Fix this by defining the end of the ARM private syscall region and
checking the syscall number against that directly. Update the comment
while we're at it.
Cc: <stable@vger.kernel.org>
Cc: Dave Martin <Dave.Martin@arm.com>
Reported-by: Pi-Hsun Shih <pihsun@chromium.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm64/include/asm/unistd.h | 5 +++--
arch/arm64/kernel/sys_compat.c | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index b13ca091f833..be66a54ee3a1 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -40,8 +40,9 @@
* The following SVCs are ARM private.
*/
#define __ARM_NR_COMPAT_BASE 0x0f0000
-#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE+2)
-#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE+5)
+#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE + 2)
+#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)
+#define __ARM_NR_compat_syscall_end (__ARM_NR_COMPAT_BASE + 0x800)
#define __NR_compat_syscalls 399
#endif
diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
index 32653d156747..5972b7533fa0 100644
--- a/arch/arm64/kernel/sys_compat.c
+++ b/arch/arm64/kernel/sys_compat.c
@@ -102,12 +102,12 @@ long compat_arm_syscall(struct pt_regs *regs)
default:
/*
- * Calls 9f00xx..9f07ff are defined to return -ENOSYS
+ * Calls 0xf0xxx..0xf07ff are defined to return -ENOSYS
* if not implemented, rather than raising SIGILL. This
* way the calling program can gracefully determine whether
* a feature is supported.
*/
- if ((no & 0xffff) <= 0x7ff)
+ if (no < __ARM_NR_compat_syscall_end)
return -ENOSYS;
break;
}
--
2.1.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/3] arm64: compat: Don't pull syscall number from regs in arm_compat_syscall
2019-01-03 18:13 [PATCH 0/3] Fix private compat syscall emulation Will Deacon
2019-01-03 18:13 ` [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers Will Deacon
@ 2019-01-03 18:13 ` Will Deacon
2019-01-04 4:50 ` Sasha Levin
2019-01-04 12:37 ` Dave Martin
2019-01-03 18:14 ` [PATCH 3/3] arm64: compat: Hook up io_pgetevents() for 32-bit tasks Will Deacon
2 siblings, 2 replies; 10+ messages in thread
From: Will Deacon @ 2019-01-03 18:13 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: stable, Will Deacon, Dave.Martin, pihsun
The syscall number may have been changed by a tracer, so we should pass
the actual number in from the caller instead of pulling it from the
saved r7 value directly.
Cc: <stable@vger.kernel.org>
Cc: Dave Martin <Dave.Martin@arm.com>
Cc: Pi-Hsun Shih <pihsun@chromium.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm64/kernel/sys_compat.c | 9 ++++-----
arch/arm64/kernel/syscall.c | 9 ++++-----
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
index 5972b7533fa0..54c29cd38ff9 100644
--- a/arch/arm64/kernel/sys_compat.c
+++ b/arch/arm64/kernel/sys_compat.c
@@ -66,12 +66,11 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags)
/*
* Handle all unrecognised system calls.
*/
-long compat_arm_syscall(struct pt_regs *regs)
+long compat_arm_syscall(struct pt_regs *regs, int scno)
{
- unsigned int no = regs->regs[7];
void __user *addr;
- switch (no) {
+ switch (scno) {
/*
* Flush a region from virtual address 'r0' to virtual address 'r1'
* _exclusive_. There is no alignment requirement on either address;
@@ -107,7 +106,7 @@ long compat_arm_syscall(struct pt_regs *regs)
* way the calling program can gracefully determine whether
* a feature is supported.
*/
- if (no < __ARM_NR_compat_syscall_end)
+ if (scno < __ARM_NR_compat_syscall_end)
return -ENOSYS;
break;
}
@@ -116,6 +115,6 @@ long compat_arm_syscall(struct pt_regs *regs)
(compat_thumb_mode(regs) ? 2 : 4);
arm64_notify_die("Oops - bad compat syscall(2)", regs,
- SIGILL, ILL_ILLTRP, addr, no);
+ SIGILL, ILL_ILLTRP, addr, scno);
return 0;
}
diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
index 032d22312881..5610ac01c1ec 100644
--- a/arch/arm64/kernel/syscall.c
+++ b/arch/arm64/kernel/syscall.c
@@ -13,16 +13,15 @@
#include <asm/thread_info.h>
#include <asm/unistd.h>
-long compat_arm_syscall(struct pt_regs *regs);
-
+long compat_arm_syscall(struct pt_regs *regs, int scno);
long sys_ni_syscall(void);
-asmlinkage long do_ni_syscall(struct pt_regs *regs)
+static long do_ni_syscall(struct pt_regs *regs, int scno)
{
#ifdef CONFIG_COMPAT
long ret;
if (is_compat_task()) {
- ret = compat_arm_syscall(regs);
+ ret = compat_arm_syscall(regs, scno);
if (ret != -ENOSYS)
return ret;
}
@@ -47,7 +46,7 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno,
syscall_fn = syscall_table[array_index_nospec(scno, sc_nr)];
ret = __invoke_syscall(regs, syscall_fn);
} else {
- ret = do_ni_syscall(regs);
+ ret = do_ni_syscall(regs, scno);
}
regs->regs[0] = ret;
--
2.1.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/3] arm64: compat: Hook up io_pgetevents() for 32-bit tasks
2019-01-03 18:13 [PATCH 0/3] Fix private compat syscall emulation Will Deacon
2019-01-03 18:13 ` [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers Will Deacon
2019-01-03 18:13 ` [PATCH 2/3] arm64: compat: Don't pull syscall number from regs in arm_compat_syscall Will Deacon
@ 2019-01-03 18:14 ` Will Deacon
2 siblings, 0 replies; 10+ messages in thread
From: Will Deacon @ 2019-01-03 18:14 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Will Deacon, Dave.Martin, pihsun
Commit 73aeb2cbcdc9 ("ARM: 8787/1: wire up io_pgetevents syscall")
hooked up the io_pgetevents() system call for 32-bit ARM, so we can
do the same for the compat wrapper on arm64.
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm64/include/asm/unistd.h | 2 +-
arch/arm64/include/asm/unistd32.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index be66a54ee3a1..395097caf0ea 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -44,7 +44,7 @@
#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)
#define __ARM_NR_compat_syscall_end (__ARM_NR_COMPAT_BASE + 0x800)
-#define __NR_compat_syscalls 399
+#define __NR_compat_syscalls 400
#endif
#define __ARCH_WANT_SYS_CLONE
diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h
index 2cd6dcf8d246..04ee190b90fe 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -819,6 +819,8 @@ __SYSCALL(__NR_pkey_free, sys_pkey_free)
__SYSCALL(__NR_statx, sys_statx)
#define __NR_rseq 398
__SYSCALL(__NR_rseq, sys_rseq)
+#define __NR_io_pgetevents 399
+__SYSCALL(__NR_io_pgetevents, compat_sys_io_pgetevents)
/*
* Please add new compat syscalls above this comment and update
--
2.1.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] arm64: compat: Don't pull syscall number from regs in arm_compat_syscall
2019-01-03 18:13 ` [PATCH 2/3] arm64: compat: Don't pull syscall number from regs in arm_compat_syscall Will Deacon
@ 2019-01-04 4:50 ` Sasha Levin
2019-01-04 12:37 ` Dave Martin
1 sibling, 0 replies; 10+ messages in thread
From: Sasha Levin @ 2019-01-04 4:50 UTC (permalink / raw)
To: Sasha Levin, Will Deacon, linux-arm-kernel
Cc: stable, Dave Martin, Pi-Hsun Shih
Hi,
[This is an automated email]
This commit has been processed because it contains a -stable tag.
The stable tag indicates that it's relevant for the following trees: all
The bot has tested the following trees: v4.20.0, v4.19.13, v4.14.91, v4.9.148, v4.4.169, v3.18.131,
v4.20.0: Failed to apply! Possible dependencies:
caf41328c3a5 ("arm64: compat: Avoid sending SIGILL for unallocated syscall numbers")
v4.19.13: Failed to apply! Possible dependencies:
6fa998e83ef9 ("signal/arm64: Push siginfo generation into arm64_notify_die")
caf41328c3a5 ("arm64: compat: Avoid sending SIGILL for unallocated syscall numbers")
v4.14.91: Failed to apply! Possible dependencies:
1fc5dce78ad1 ("arm64/sve: Low-level SVE architectural state manipulation functions")
2923f5ea7738 ("nds32: Exception handling")
2c9120f3a86a ("arm64: signal: Make force_signal_inject more robust")
3eb0f5193b49 ("signal: Ensure every siginfo we send has all bits initialized")
3f7c86b2382e ("arm64: Update fault_info table with new exception types")
42dbf54e8890 ("arm64: consistently log ESR and page table")
4fb158f65ac5 ("powerpc: track allocation status of all pkeys")
526c3ddb6aa2 ("signal/arm64: Document conflicts with SI_USER and SIGFPE,SIGTRAP,SIGBUS")
532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
664eec400bf8 ("nds32: MMU fault handling and page table management")
6fa998e83ef9 ("signal/arm64: Push siginfo generation into arm64_notify_die")
76d2a0493a17 ("RISC-V: Init and Halt Code")
92e3da3cf193 ("powerpc: initial pkey plumbing")
92ff0674f5d8 ("arm64: mm: Rework unhandled user pagefaults to call arm64_force_sig_info")
94ef7ecbdf6f ("arm64: fpsimd: Correctly annotate exception helpers called from asm")
af40ff687bc9 ("arm64: signal: Ensure si_code is valid for all fault signals")
bc0ee4760364 ("arm64/sve: Core task context handling")
c5cc1f4df6b1 ("powerpc/ptrace: Add memory protection key regset")
v4.9.148: Failed to apply! Possible dependencies:
0e3a9026396c ("arm64: mm: Update perf accounting to handle poison faults")
32015c235603 ("arm64: exception: handle Synchronous External Abort")
3eb0f5193b49 ("signal: Ensure every siginfo we send has all bits initialized")
3f7c86b2382e ("arm64: Update fault_info table with new exception types")
4e2648db9c5f ("ARM: remove indirection of asm/mach-types.h")
526c3ddb6aa2 ("signal/arm64: Document conflicts with SI_USER and SIGFPE,SIGTRAP,SIGBUS")
532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
5b53696a30d5 ("ACPI / APEI: Switch to use new generic UUID API")
67ce16ec15ce ("arm64: mm: print out correct page table entries")
6bc51cbaa9d7 ("signal: Remove non-uapi <asm/siginfo.h>")
6fa998e83ef9 ("signal/arm64: Push siginfo generation into arm64_notify_die")
7edda0886bc3 ("acpi: apei: handle SEA notification type for ARMv8")
80dce5e37493 ("signal/ia64: Document a conflict with SI_USER with SIGFPE")
83016b204225 ("arm64: mm: print file name of faulting vma")
92ff0674f5d8 ("arm64: mm: Rework unhandled user pagefaults to call arm64_force_sig_info")
96a8fae0fe09 ("ARM: convert to generated system call tables")
a8ada146f517 ("arm64: Update the synchronous external abort fault description")
af40ff687bc9 ("arm64: signal: Ensure si_code is valid for all fault signals")
b9253a43370e ("signal: Move copy_siginfo_to_user to <linux/signal.h>")
bbcc2e7b642e ("ras: acpi/apei: cper: add support for generic data v3 structure")
c07ab957d9af ("arm64: Call __show_regs directly")
cc731525f26a ("signal: Remove kernel interal si_code magic")
cc9f72e474a4 ("signal/sparc: Document a conflict with SI_USER with SIGFPE")
e2bd64d92a10 ("signal/alpha: Document a conflict with SI_USER for SIGTRAP")
e7c600f149b8 ("arm64: hwpoison: add VM_FAULT_HWPOISON[_LARGE] handling")
ea1b75cf9138 ("signal/mips: Document a conflict with SI_USER with SIGFPE")
v4.4.169: Failed to apply! Possible dependencies:
09a6adf53d42 ("arm64: mm: unaligned access by user-land should be received as SIGBUS")
0a8ea52c3eb1 ("arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature")
0e3a9026396c ("arm64: mm: Update perf accounting to handle poison faults")
2dd0e8d2d2a1 ("arm64: Kprobes with single stepping support")
3eb0f5193b49 ("signal: Ensure every siginfo we send has all bits initialized")
3eca86e75ec7 ("arm64: Remove fixmap include fragility")
532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
67ce16ec15ce ("arm64: mm: print out correct page table entries")
6fa998e83ef9 ("signal/arm64: Push siginfo generation into arm64_notify_die")
83016b204225 ("arm64: mm: print file name of faulting vma")
92ff0674f5d8 ("arm64: mm: Rework unhandled user pagefaults to call arm64_force_sig_info")
bbb1681ee365 ("arm64: mm: mark fault_info table const")
c07ab957d9af ("arm64: Call __show_regs directly")
cab15ce604e5 ("arm64: Introduce execute-only page access permissions")
d59bee887231 ("arm64: Add more test functions to insn.c")
e04a28d45ff3 ("arm64: debug: re-enable irqs before sending breakpoint SIGTRAP")
e7c600f149b8 ("arm64: hwpoison: add VM_FAULT_HWPOISON[_LARGE] handling")
v3.18.131: Failed to apply! Possible dependencies:
04597a65c5ef ("arm64: Track system support for mixed endian EL0")
1b907f46db07 ("arm64: kconfig: move emulation option under kernel features")
2d888f48e056 ("arm64: Emulate SETEND for AArch32 tasks")
338d4f49d6f7 ("arm64: kernel: Add support for Privileged Access Never")
359b706473b4 ("arm64: Extract feature parsing code from cpu_errata.c")
3eb0f5193b49 ("signal: Ensure every siginfo we send has all bits initialized")
532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
587064b610c7 ("arm64: Add framework for legacy instruction emulation")
6fa998e83ef9 ("signal/arm64: Push siginfo generation into arm64_notify_die")
7209c868600b ("arm64: mm: Set PSTATE.PAN from the cpu_enable_pan() call")
736d474f0faf ("arm64: Consolidate hotplug notifier for instruction emulation")
870828e57b14 ("arm64: kernel: Move config_sctlr_el1")
92ff0674f5d8 ("arm64: mm: Rework unhandled user pagefaults to call arm64_force_sig_info")
94a9e04aa16a ("arm64: alternative: Introduce feature for GICv3 CPU interface")
9b79f52d1a70 ("arm64: Add support for hooks to handle undefined instructions")
a4980448ed65 ("arm: Remove signal translation and exec_domain")
bd35a4adc413 ("arm64: Port SWP/SWPB emulation support from arm")
c852f3205846 ("arm64: Emulate CP15 Barrier instructions")
c9453a3ab1a3 ("arm64: alternatives: fix pr_fmt string for consistency")
e7c600f149b8 ("arm64: hwpoison: add VM_FAULT_HWPOISON[_LARGE] handling")
How should we proceed with this patch?
--
Thanks,
Sasha
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers
2019-01-03 18:13 ` [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers Will Deacon
@ 2019-01-04 4:50 ` Sasha Levin
2019-01-04 12:54 ` Dave Martin
1 sibling, 0 replies; 10+ messages in thread
From: Sasha Levin @ 2019-01-04 4:50 UTC (permalink / raw)
To: Sasha Levin, Will Deacon, linux-arm-kernel; +Cc: stable, Dave Martin, pihsun
Hi,
[This is an automated email]
This commit has been processed because it contains a -stable tag.
The stable tag indicates that it's relevant for the following trees: all
The bot has tested the following trees: v4.20.0, v4.19.13, v4.14.91, v4.9.148, v4.4.169, v3.18.131,
v4.20.0: Build OK!
v4.19.13: Build OK!
v4.14.91: Failed to apply! Possible dependencies:
532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
v4.9.148: Failed to apply! Possible dependencies:
532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
v4.4.169: Failed to apply! Possible dependencies:
532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
v3.18.131: Failed to apply! Possible dependencies:
532826f3712b ("arm64: Mirror arm for unimplemented compat syscalls")
How should we proceed with this patch?
--
Thanks,
Sasha
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] arm64: compat: Don't pull syscall number from regs in arm_compat_syscall
2019-01-03 18:13 ` [PATCH 2/3] arm64: compat: Don't pull syscall number from regs in arm_compat_syscall Will Deacon
2019-01-04 4:50 ` Sasha Levin
@ 2019-01-04 12:37 ` Dave Martin
1 sibling, 0 replies; 10+ messages in thread
From: Dave Martin @ 2019-01-04 12:37 UTC (permalink / raw)
To: Will Deacon; +Cc: pihsun, stable, linux-arm-kernel
On Thu, Jan 03, 2019 at 06:13:59PM +0000, Will Deacon wrote:
> The syscall number may have been changed by a tracer, so we should pass
> the actual number in from the caller instead of pulling it from the
> saved r7 value directly.
Reviewed-by: Dave Martin <Dave.Martin@arm.com>
I was confused by the history here: commit 4141c857fd09 ("arm64: convert
raw syscall invocation to C") breaks syscall changing via
discarding the return from syscall_trace_enter() (which would also break
this case for compat), but the subsequent patch that migrates the
syscall code to C appears to fix it again.
>
> Cc: <stable@vger.kernel.org>
> Cc: Dave Martin <Dave.Martin@arm.com>
> Cc: Pi-Hsun Shih <pihsun@chromium.org>
> Signed-off-by: Will Deacon <will.deacon@arm.com>
> ---
> arch/arm64/kernel/sys_compat.c | 9 ++++-----
> arch/arm64/kernel/syscall.c | 9 ++++-----
> 2 files changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
> index 5972b7533fa0..54c29cd38ff9 100644
> --- a/arch/arm64/kernel/sys_compat.c
> +++ b/arch/arm64/kernel/sys_compat.c
> @@ -66,12 +66,11 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags)
> /*
> * Handle all unrecognised system calls.
> */
> -long compat_arm_syscall(struct pt_regs *regs)
> +long compat_arm_syscall(struct pt_regs *regs, int scno)
> {
> - unsigned int no = regs->regs[7];
> void __user *addr;
>
> - switch (no) {
> + switch (scno) {
> /*
> * Flush a region from virtual address 'r0' to virtual address 'r1'
> * _exclusive_. There is no alignment requirement on either address;
> @@ -107,7 +106,7 @@ long compat_arm_syscall(struct pt_regs *regs)
> * way the calling program can gracefully determine whether
> * a feature is supported.
> */
> - if (no < __ARM_NR_compat_syscall_end)
> + if (scno < __ARM_NR_compat_syscall_end)
> return -ENOSYS;
> break;
> }
> @@ -116,6 +115,6 @@ long compat_arm_syscall(struct pt_regs *regs)
> (compat_thumb_mode(regs) ? 2 : 4);
>
> arm64_notify_die("Oops - bad compat syscall(2)", regs,
> - SIGILL, ILL_ILLTRP, addr, no);
> + SIGILL, ILL_ILLTRP, addr, scno);
> return 0;
> }
> diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
> index 032d22312881..5610ac01c1ec 100644
> --- a/arch/arm64/kernel/syscall.c
> +++ b/arch/arm64/kernel/syscall.c
> @@ -13,16 +13,15 @@
> #include <asm/thread_info.h>
> #include <asm/unistd.h>
>
> -long compat_arm_syscall(struct pt_regs *regs);
> -
> +long compat_arm_syscall(struct pt_regs *regs, int scno);
> long sys_ni_syscall(void);
>
> -asmlinkage long do_ni_syscall(struct pt_regs *regs)
> +static long do_ni_syscall(struct pt_regs *regs, int scno)
> {
> #ifdef CONFIG_COMPAT
> long ret;
> if (is_compat_task()) {
> - ret = compat_arm_syscall(regs);
> + ret = compat_arm_syscall(regs, scno);
> if (ret != -ENOSYS)
> return ret;
> }
> @@ -47,7 +46,7 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno,
> syscall_fn = syscall_table[array_index_nospec(scno, sc_nr)];
> ret = __invoke_syscall(regs, syscall_fn);
> } else {
> - ret = do_ni_syscall(regs);
> + ret = do_ni_syscall(regs, scno);
> }
>
> regs->regs[0] = ret;
> --
> 2.1.4
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers
2019-01-03 18:13 ` [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers Will Deacon
2019-01-04 4:50 ` Sasha Levin
@ 2019-01-04 12:54 ` Dave Martin
2019-01-04 13:47 ` Will Deacon
1 sibling, 1 reply; 10+ messages in thread
From: Dave Martin @ 2019-01-04 12:54 UTC (permalink / raw)
To: Will Deacon; +Cc: pihsun, stable, linux-arm-kernel
On Thu, Jan 03, 2019 at 06:13:58PM +0000, Will Deacon wrote:
> The ARM Linux kernel handles the EABI syscall numbers as follows:
>
> 0 - NR_SYSCALLS-1 : Invoke syscall via syscall table
> NR_SYSCALLS - 0xeffff : -ENOSYS (to be allocated in future)
> 0xf0000 - 0xf07ff : Private syscall or -ENOSYS if not allocated
> > 0xf07ff : SIGILL
>
> Our compat code gets this wrong and ends up sending SIGILL in response
> to all syscalls greater than NR_SYSCALLS which have a value greater
> than 0x7ff in the bottom 16 bits.
>
> Fix this by defining the end of the ARM private syscall region and
> checking the syscall number against that directly. Update the comment
> while we're at it.
>
> Cc: <stable@vger.kernel.org>
> Cc: Dave Martin <Dave.Martin@arm.com>
> Reported-by: Pi-Hsun Shih <pihsun@chromium.org>
> Signed-off-by: Will Deacon <will.deacon@arm.com>
> ---
> arch/arm64/include/asm/unistd.h | 5 +++--
> arch/arm64/kernel/sys_compat.c | 4 ++--
> 2 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
> index b13ca091f833..be66a54ee3a1 100644
> --- a/arch/arm64/include/asm/unistd.h
> +++ b/arch/arm64/include/asm/unistd.h
> @@ -40,8 +40,9 @@
> * The following SVCs are ARM private.
> */
> #define __ARM_NR_COMPAT_BASE 0x0f0000
> -#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE+2)
> -#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE+5)
> +#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE + 2)
> +#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)
> +#define __ARM_NR_compat_syscall_end (__ARM_NR_COMPAT_BASE + 0x800)
Nit: there is no compat_syscall_end(). Can we make this #define upper
case, like __ARM_NR_COMPAT_BASE, since a symbolic bound, not a syscall
number?
It would be nice to have this for arch/arm too rather than the current
magic numbers.
> #define __NR_compat_syscalls 399
> #endif
> diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
> index 32653d156747..5972b7533fa0 100644
> --- a/arch/arm64/kernel/sys_compat.c
> +++ b/arch/arm64/kernel/sys_compat.c
> @@ -102,12 +102,12 @@ long compat_arm_syscall(struct pt_regs *regs)
>
> default:
> /*
> - * Calls 9f00xx..9f07ff are defined to return -ENOSYS
> + * Calls 0xf0xxx..0xf07ff are defined to return -ENOSYS
> * if not implemented, rather than raising SIGILL. This
> * way the calling program can gracefully determine whether
> * a feature is supported.
> */
> - if ((no & 0xffff) <= 0x7ff)
> + if (no < __ARM_NR_compat_syscall_end)
arm_syscall() in arch/arm is not responsible for handling syscalls less
__ARM_NR_BASE; the code in entry-common.S redirects those directly to
sys_ni_syscall() instead.
Given how fiddly this is I think it's preferable if we keep to the
arch/arm code structure as much as possible, and call this function only
when no >= __ARM_NR_COMPAT_BASE?
Regular (possibly unallocated) Linux syscalls can be more naturally
handled in do_ni_syscall() instead IMHO, mirroring the entry-common.S
code that it replaces.
Cheers
---Dave
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers
2019-01-04 12:54 ` Dave Martin
@ 2019-01-04 13:47 ` Will Deacon
2019-01-04 14:15 ` Dave Martin
0 siblings, 1 reply; 10+ messages in thread
From: Will Deacon @ 2019-01-04 13:47 UTC (permalink / raw)
To: Dave Martin; +Cc: pihsun, stable, linux-arm-kernel
On Fri, Jan 04, 2019 at 12:54:26PM +0000, Dave Martin wrote:
> On Thu, Jan 03, 2019 at 06:13:58PM +0000, Will Deacon wrote:
> > The ARM Linux kernel handles the EABI syscall numbers as follows:
> >
> > 0 - NR_SYSCALLS-1 : Invoke syscall via syscall table
> > NR_SYSCALLS - 0xeffff : -ENOSYS (to be allocated in future)
> > 0xf0000 - 0xf07ff : Private syscall or -ENOSYS if not allocated
> > > 0xf07ff : SIGILL
> >
> > Our compat code gets this wrong and ends up sending SIGILL in response
> > to all syscalls greater than NR_SYSCALLS which have a value greater
> > than 0x7ff in the bottom 16 bits.
> >
> > Fix this by defining the end of the ARM private syscall region and
> > checking the syscall number against that directly. Update the comment
> > while we're at it.
> >
> > Cc: <stable@vger.kernel.org>
> > Cc: Dave Martin <Dave.Martin@arm.com>
> > Reported-by: Pi-Hsun Shih <pihsun@chromium.org>
> > Signed-off-by: Will Deacon <will.deacon@arm.com>
> > ---
> > arch/arm64/include/asm/unistd.h | 5 +++--
> > arch/arm64/kernel/sys_compat.c | 4 ++--
> > 2 files changed, 5 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
> > index b13ca091f833..be66a54ee3a1 100644
> > --- a/arch/arm64/include/asm/unistd.h
> > +++ b/arch/arm64/include/asm/unistd.h
> > @@ -40,8 +40,9 @@
> > * The following SVCs are ARM private.
> > */
> > #define __ARM_NR_COMPAT_BASE 0x0f0000
> > -#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE+2)
> > -#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE+5)
> > +#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE + 2)
> > +#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)
> > +#define __ARM_NR_compat_syscall_end (__ARM_NR_COMPAT_BASE + 0x800)
>
> Nit: there is no compat_syscall_end(). Can we make this #define upper
> case, like __ARM_NR_COMPAT_BASE, since a symbolic bound, not a syscall
> number?
That's fair; I'll rename it to __ARM_NR_COMPAT_END.
> > #define __NR_compat_syscalls 399
> > #endif
> > diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
> > index 32653d156747..5972b7533fa0 100644
> > --- a/arch/arm64/kernel/sys_compat.c
> > +++ b/arch/arm64/kernel/sys_compat.c
> > @@ -102,12 +102,12 @@ long compat_arm_syscall(struct pt_regs *regs)
> >
> > default:
> > /*
> > - * Calls 9f00xx..9f07ff are defined to return -ENOSYS
> > + * Calls 0xf0xxx..0xf07ff are defined to return -ENOSYS
> > * if not implemented, rather than raising SIGILL. This
> > * way the calling program can gracefully determine whether
> > * a feature is supported.
> > */
> > - if ((no & 0xffff) <= 0x7ff)
> > + if (no < __ARM_NR_compat_syscall_end)
>
> arm_syscall() in arch/arm is not responsible for handling syscalls less
> __ARM_NR_BASE; the code in entry-common.S redirects those directly to
> sys_ni_syscall() instead.
>
> Given how fiddly this is I think it's preferable if we keep to the
> arch/arm code structure as much as possible, and call this function only
> when no >= __ARM_NR_COMPAT_BASE?
I don't think we should be using the arm code structure as a template here.
Although we're providing the same interface, we don't have to worry about
things like OABI or ARM vs THUMB entry code. We're also in the process of
moving more of this out of assembly and into C, so I'd rather keep the
compat code as self-contained as possible.
Even if we did modify the caller so that we only call compat_arm_syscall()
for numbers >= __ARM_NR_COMPAT_BASE, we'd still need the check above to
handle numbers >= __ARM_NR_COMPAT_END, so I don't think we gain anything.
Will
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers
2019-01-04 13:47 ` Will Deacon
@ 2019-01-04 14:15 ` Dave Martin
0 siblings, 0 replies; 10+ messages in thread
From: Dave Martin @ 2019-01-04 14:15 UTC (permalink / raw)
To: Will Deacon; +Cc: linux-arm-kernel, stable, pihsun
On Fri, Jan 04, 2019 at 01:47:49PM +0000, Will Deacon wrote:
> On Fri, Jan 04, 2019 at 12:54:26PM +0000, Dave Martin wrote:
> > On Thu, Jan 03, 2019 at 06:13:58PM +0000, Will Deacon wrote:
> > > The ARM Linux kernel handles the EABI syscall numbers as follows:
> > >
> > > 0 - NR_SYSCALLS-1 : Invoke syscall via syscall table
> > > NR_SYSCALLS - 0xeffff : -ENOSYS (to be allocated in future)
> > > 0xf0000 - 0xf07ff : Private syscall or -ENOSYS if not allocated
> > > > 0xf07ff : SIGILL
> > >
> > > Our compat code gets this wrong and ends up sending SIGILL in response
> > > to all syscalls greater than NR_SYSCALLS which have a value greater
> > > than 0x7ff in the bottom 16 bits.
> > >
> > > Fix this by defining the end of the ARM private syscall region and
> > > checking the syscall number against that directly. Update the comment
> > > while we're at it.
> > >
> > > Cc: <stable@vger.kernel.org>
> > > Cc: Dave Martin <Dave.Martin@arm.com>
> > > Reported-by: Pi-Hsun Shih <pihsun@chromium.org>
> > > Signed-off-by: Will Deacon <will.deacon@arm.com>
> > > ---
> > > arch/arm64/include/asm/unistd.h | 5 +++--
> > > arch/arm64/kernel/sys_compat.c | 4 ++--
> > > 2 files changed, 5 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
> > > index b13ca091f833..be66a54ee3a1 100644
> > > --- a/arch/arm64/include/asm/unistd.h
> > > +++ b/arch/arm64/include/asm/unistd.h
> > > @@ -40,8 +40,9 @@
> > > * The following SVCs are ARM private.
> > > */
> > > #define __ARM_NR_COMPAT_BASE 0x0f0000
> > > -#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE+2)
> > > -#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE+5)
> > > +#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE + 2)
> > > +#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)
> > > +#define __ARM_NR_compat_syscall_end (__ARM_NR_COMPAT_BASE + 0x800)
> >
> > Nit: there is no compat_syscall_end(). Can we make this #define upper
> > case, like __ARM_NR_COMPAT_BASE, since a symbolic bound, not a syscall
> > number?
>
> That's fair; I'll rename it to __ARM_NR_COMPAT_END.
Thanks
>
> > > #define __NR_compat_syscalls 399
> > > #endif
> > > diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
> > > index 32653d156747..5972b7533fa0 100644
> > > --- a/arch/arm64/kernel/sys_compat.c
> > > +++ b/arch/arm64/kernel/sys_compat.c
> > > @@ -102,12 +102,12 @@ long compat_arm_syscall(struct pt_regs *regs)
> > >
> > > default:
> > > /*
> > > - * Calls 9f00xx..9f07ff are defined to return -ENOSYS
> > > + * Calls 0xf0xxx..0xf07ff are defined to return -ENOSYS
> > > * if not implemented, rather than raising SIGILL. This
> > > * way the calling program can gracefully determine whether
> > > * a feature is supported.
> > > */
> > > - if ((no & 0xffff) <= 0x7ff)
> > > + if (no < __ARM_NR_compat_syscall_end)
> >
> > arm_syscall() in arch/arm is not responsible for handling syscalls less
> > __ARM_NR_BASE; the code in entry-common.S redirects those directly to
> > sys_ni_syscall() instead.
> >
> > Given how fiddly this is I think it's preferable if we keep to the
> > arch/arm code structure as much as possible, and call this function only
> > when no >= __ARM_NR_COMPAT_BASE?
>
> I don't think we should be using the arm code structure as a template here.
> Although we're providing the same interface, we don't have to worry about
> things like OABI or ARM vs THUMB entry code. We're also in the process of
> moving more of this out of assembly and into C, so I'd rather keep the
> compat code as self-contained as possible.
>
> Even if we did modify the caller so that we only call compat_arm_syscall()
> for numbers >= __ARM_NR_COMPAT_BASE, we'd still need the check above to
> handle numbers >= __ARM_NR_COMPAT_END, so I don't think we gain anything.
Well, I can live with it either way.
Cross-referencing the arm64 and arm trees for this functionality is
challenging, and will tend to get harder as the code diverges... but
hopefully it's gone about as far as it's going to go by this point.
Cheers
---Dave
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2019-01-04 14:15 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-03 18:13 [PATCH 0/3] Fix private compat syscall emulation Will Deacon
2019-01-03 18:13 ` [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers Will Deacon
2019-01-04 4:50 ` Sasha Levin
2019-01-04 12:54 ` Dave Martin
2019-01-04 13:47 ` Will Deacon
2019-01-04 14:15 ` Dave Martin
2019-01-03 18:13 ` [PATCH 2/3] arm64: compat: Don't pull syscall number from regs in arm_compat_syscall Will Deacon
2019-01-04 4:50 ` Sasha Levin
2019-01-04 12:37 ` Dave Martin
2019-01-03 18:14 ` [PATCH 3/3] arm64: compat: Hook up io_pgetevents() for 32-bit tasks Will Deacon
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).