linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: Mirror arm for small unimplemented compat syscalls
@ 2019-01-03  7:45 Pi-Hsun Shih
  2019-01-03 11:50 ` Dave Martin
  0 siblings, 1 reply; 4+ messages in thread
From: Pi-Hsun Shih @ 2019-01-03  7:45 UTC (permalink / raw)
  Cc: Pi-Hsun Shih, Catalin Marinas, Will Deacon, Mark Rutland,
	Dominik Brodowski, Dave Martin,
	moderated list:ARM64 PORT (AARCH64 ARCHITECTURE),
	open list

For syscall number smaller than 0xf0000, arm calls sys_ni_syscall
instead of arm_syscall in arch/arm/kernel/entry-common.S, which returns
-ENOSYS instead of raising SIGILL. Mirror this behavior for compat
syscalls in arm64.

Fixes: 532826f3712b607 ("arm64: Mirror arm for unimplemented compat
syscalls")
Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
---
 arch/arm64/kernel/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
index 8f3371415642ad..95fd8c7ec8a171 100644
--- a/arch/arm64/kernel/syscall.c
+++ b/arch/arm64/kernel/syscall.c
@@ -21,7 +21,7 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs)
 {
 #ifdef CONFIG_COMPAT
 	long ret;
-	if (is_compat_task()) {
+	if (is_compat_task() && regs->regs[7] >= __ARM_NR_COMPAT_BASE) {
 		ret = compat_arm_syscall(regs);
 		if (ret != -ENOSYS)
 			return ret;
-- 
2.20.1.415.g653613c723-goog


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

* Re: [PATCH] arm64: Mirror arm for small unimplemented compat syscalls
  2019-01-03  7:45 [PATCH] arm64: Mirror arm for small unimplemented compat syscalls Pi-Hsun Shih
@ 2019-01-03 11:50 ` Dave Martin
  2019-01-03 16:51   ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Martin @ 2019-01-03 11:50 UTC (permalink / raw)
  To: Pi-Hsun Shih
  Cc: Mark Rutland, Catalin Marinas, Will Deacon, open list,
	Dominik Brodowski,
	moderated list:ARM64 PORT AARCH64 ARCHITECTURE

On Thu, Jan 03, 2019 at 03:45:47PM +0800, Pi-Hsun Shih wrote:
> For syscall number smaller than 0xf0000, arm calls sys_ni_syscall
> instead of arm_syscall in arch/arm/kernel/entry-common.S, which returns
> -ENOSYS instead of raising SIGILL. Mirror this behavior for compat
> syscalls in arm64.
> 
> Fixes: 532826f3712b607 ("arm64: Mirror arm for unimplemented compat
> syscalls")
> Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
> ---
>  arch/arm64/kernel/syscall.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
> index 8f3371415642ad..95fd8c7ec8a171 100644
> --- a/arch/arm64/kernel/syscall.c
> +++ b/arch/arm64/kernel/syscall.c
> @@ -21,7 +21,7 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs)
>  {
>  #ifdef CONFIG_COMPAT
>  	long ret;
> -	if (is_compat_task()) {
> +	if (is_compat_task() && regs->regs[7] >= __ARM_NR_COMPAT_BASE) {

compat_arm_syscall() ignores all bits r7 except for bits [15:0].

So, doesn't this mean that 0xf0000, 0x100000, 0x110000 will all do the
same thing now?  (Previously to your patch, 0xe0000, 0xd0000 etc. would
also match in this code I've misunderstood something.)

The gating check in arch/arm/kernel/trapc.s:arm_syscall() is

	if ((no >> 16) != (__ARM_NR_BASE>> 16))

I would expect that arm64 needs a similar check somewhere.  Is the check
already present?  I may have missed it.


Cheers
---Dave

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

* Re: [PATCH] arm64: Mirror arm for small unimplemented compat syscalls
  2019-01-03 11:50 ` Dave Martin
@ 2019-01-03 16:51   ` Will Deacon
  2019-01-03 17:52     ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Will Deacon @ 2019-01-03 16:51 UTC (permalink / raw)
  To: Dave Martin
  Cc: Pi-Hsun Shih, Mark Rutland, Catalin Marinas, open list,
	Dominik Brodowski,
	moderated list:ARM64 PORT AARCH64 ARCHITECTURE

On Thu, Jan 03, 2019 at 11:50:12AM +0000, Dave Martin wrote:
> On Thu, Jan 03, 2019 at 03:45:47PM +0800, Pi-Hsun Shih wrote:
> > For syscall number smaller than 0xf0000, arm calls sys_ni_syscall
> > instead of arm_syscall in arch/arm/kernel/entry-common.S, which returns
> > -ENOSYS instead of raising SIGILL. Mirror this behavior for compat
> > syscalls in arm64.
> > 
> > Fixes: 532826f3712b607 ("arm64: Mirror arm for unimplemented compat
> > syscalls")
> > Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
> > ---
> >  arch/arm64/kernel/syscall.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
> > index 8f3371415642ad..95fd8c7ec8a171 100644
> > --- a/arch/arm64/kernel/syscall.c
> > +++ b/arch/arm64/kernel/syscall.c
> > @@ -21,7 +21,7 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs)
> >  {
> >  #ifdef CONFIG_COMPAT
> >  	long ret;
> > -	if (is_compat_task()) {
> > +	if (is_compat_task() && regs->regs[7] >= __ARM_NR_COMPAT_BASE) {
> 
> compat_arm_syscall() ignores all bits r7 except for bits [15:0].
> 
> So, doesn't this mean that 0xf0000, 0x100000, 0x110000 will all do the
> same thing now?  (Previously to your patch, 0xe0000, 0xd0000 etc. would
> also match in this code I've misunderstood something.)
> 
> The gating check in arch/arm/kernel/trapc.s:arm_syscall() is
> 
> 	if ((no >> 16) != (__ARM_NR_BASE>> 16))
> 
> I would expect that arm64 needs a similar check somewhere.  Is the check
> already present?  I may have missed it.

When not using OABI, __ARM_NR_BASE is zero, so I think the 32-bit semantics
for non-OABI are:

	0       - 399		: Invoke syscall via syscall table
	400     - 0xeffff	: -ENOSYS (to be allocated in future)
	0xf0000 - 0xfffff	: Private syscall or -ENOSYS if not allocated
	> 0xfffff		: SIGILL

so for arm64 compat, we need to do the following:

	1. Ensure we only SIGILL for that last region
	2. Don't pull the syscall number directly from pt_regs, since it
	   may have been changed by a tracer
	3. Hook up compat_sys_io_pgetevents

Patches incoming...

Will

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

* Re: [PATCH] arm64: Mirror arm for small unimplemented compat syscalls
  2019-01-03 16:51   ` Will Deacon
@ 2019-01-03 17:52     ` Will Deacon
  0 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2019-01-03 17:52 UTC (permalink / raw)
  To: Dave Martin
  Cc: Pi-Hsun Shih, Mark Rutland, Catalin Marinas, open list,
	Dominik Brodowski,
	moderated list:ARM64 PORT AARCH64 ARCHITECTURE

On Thu, Jan 03, 2019 at 04:51:44PM +0000, Will Deacon wrote:
> On Thu, Jan 03, 2019 at 11:50:12AM +0000, Dave Martin wrote:
> > On Thu, Jan 03, 2019 at 03:45:47PM +0800, Pi-Hsun Shih wrote:
> > > For syscall number smaller than 0xf0000, arm calls sys_ni_syscall
> > > instead of arm_syscall in arch/arm/kernel/entry-common.S, which returns
> > > -ENOSYS instead of raising SIGILL. Mirror this behavior for compat
> > > syscalls in arm64.
> > > 
> > > Fixes: 532826f3712b607 ("arm64: Mirror arm for unimplemented compat
> > > syscalls")
> > > Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
> > > ---
> > >  arch/arm64/kernel/syscall.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
> > > index 8f3371415642ad..95fd8c7ec8a171 100644
> > > --- a/arch/arm64/kernel/syscall.c
> > > +++ b/arch/arm64/kernel/syscall.c
> > > @@ -21,7 +21,7 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs)
> > >  {
> > >  #ifdef CONFIG_COMPAT
> > >  	long ret;
> > > -	if (is_compat_task()) {
> > > +	if (is_compat_task() && regs->regs[7] >= __ARM_NR_COMPAT_BASE) {
> > 
> > compat_arm_syscall() ignores all bits r7 except for bits [15:0].
> > 
> > So, doesn't this mean that 0xf0000, 0x100000, 0x110000 will all do the
> > same thing now?  (Previously to your patch, 0xe0000, 0xd0000 etc. would
> > also match in this code I've misunderstood something.)
> > 
> > The gating check in arch/arm/kernel/trapc.s:arm_syscall() is
> > 
> > 	if ((no >> 16) != (__ARM_NR_BASE>> 16))
> > 
> > I would expect that arm64 needs a similar check somewhere.  Is the check
> > already present?  I may have missed it.
> 
> When not using OABI, __ARM_NR_BASE is zero, so I think the 32-bit semantics
> for non-OABI are:
> 
> 	0       - 399		: Invoke syscall via syscall table
> 	400     - 0xeffff	: -ENOSYS (to be allocated in future)
> 	0xf0000 - 0xfffff	: Private syscall or -ENOSYS if not allocated
> 	> 0xfffff		: SIGILL

Bah, 0xfffff should be 0xf07ff in the last two lines here.

Will

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

end of thread, other threads:[~2019-01-03 17:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-03  7:45 [PATCH] arm64: Mirror arm for small unimplemented compat syscalls Pi-Hsun Shih
2019-01-03 11:50 ` Dave Martin
2019-01-03 16:51   ` Will Deacon
2019-01-03 17:52     ` 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).