All of lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Will Deacon <will@kernel.org>
Cc: Francis Laniel <flaniel@linux.microsoft.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-trace-devel@vger.kernel.org,
	Mark Brown <broonie@kernel.org>,
	Peter Collingbourne <pcc@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Kees Cook <keescook@chromium.org>,
	Daniel Kiss <daniel.kiss@arm.com>,
	linux-kernel@vger.kernel.org, James Morse <james.morse@arm.com>
Subject: Re: [RFC PATCH v1 1/1] arm64: Forget syscall if different from execve*()
Date: Wed, 18 May 2022 14:32:56 +0100	[thread overview]
Message-ID: <YoT1iLPEbteRTQGZ@arm.com> (raw)
In-Reply-To: <20220510140333.GA28104@willie-the-truck>

On Tue, May 10, 2022 at 03:03:33PM +0100, Will Deacon wrote:
> On Tue, May 10, 2022 at 03:00:11PM +0100, Francis Laniel wrote:
> > Le mardi 10 mai 2022, 11:59:48 BST Will Deacon a �crit :
> > > On Mon, May 09, 2022 at 04:19:57PM +0100, Francis Laniel wrote:
> > > > diff --git a/arch/arm64/include/asm/processor.h
> > > > b/arch/arm64/include/asm/processor.h index 73e38d9a540c..e12ceb363d6a
> > > > 100644
> > > > --- a/arch/arm64/include/asm/processor.h
> > > > +++ b/arch/arm64/include/asm/processor.h
> > > > @@ -34,6 +34,8 @@
> > > > 
> > > >  #include <vdso/processor.h>
> > > > 
> > > > +#include <asm-generic/unistd.h>
> > > > +
> > > > 
> > > >  #include <asm/alternative.h>
> > > >  #include <asm/cpufeature.h>
> > > >  #include <asm/hw_breakpoint.h>
> > > > 
> > > > @@ -250,8 +252,12 @@ void tls_preserve_current_state(void);
> > > > 
> > > >  static inline void start_thread_common(struct pt_regs *regs, unsigned
> > > >  long pc) {
> > > > 
> > > > +	s32 previous_syscall = regs->syscallno;
> > > > 
> > > >  	memset(regs, 0, sizeof(*regs));
> > > > 
> > > > -	forget_syscall(regs);
> > > > +	if (previous_syscall == __NR_execve || previous_syscall ==
> > > > __NR_execveat)
> > > > +		regs->syscallno = previous_syscall;
> > > > +	else
> > > > +		forget_syscall(regs);
> > > 
> > > Hmm, this really looks like a bodge and it doesn't handle the compat case
> > > either.
> > > 
> > > How do other architectures handle this?
> > 
> > My understanding of others architectures is quite limited, but here are my 
> > findings and understanding of some of them:
> > * arm (32 bits) EABI: start_thread() sets r7 to previous r7 for ELF FDPIC  and 
> > to 0 for other binfmts [1].
> > * arm (32 bits) OABI: syscall number is set to -1 if 
> > ptrace_report_syscall_entry() failed [2].
> > * mips: start_thread() does not modify current_thread_info->syscall which is 
> > taken directly from v0 [3, 4].
> > * riscv: start_thread() does not modify a7 [5].
> > * x86_64: start_thread_common() does not touch orig_ax which seems to contain 
> > the syscall number [6].
> 
> Hmm, so the million dollar question is why on Earth we have that
> forget_syscall() call to start with. Amusingly I've, err, forgotten;
> forget_forget_syscall() perhaps?
> 
> Catalin? It's been there since day one afaict.

Looking at the old logs, this appeared somewhere between day 0 and 1. We
had a memset(regs, 0) with a pt_regs of 36 registers but moved to
dedicated names for syscallno etc. and that's where I changed it from 0
to ~0UL.

A few weeks ago James Morse (cc'ed) came across this issue and even sent
a patch internally to remove forget_syscall() here. But that looks like
a bodge and James' suggestion was that maybe the core code can preserve
the syscallno and this would fix it for all architectures.

-- 
Catalin

WARNING: multiple messages have this Message-ID (diff)
From: Catalin Marinas <catalin.marinas@arm.com>
To: Will Deacon <will@kernel.org>
Cc: Francis Laniel <flaniel@linux.microsoft.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-trace-devel@vger.kernel.org,
	Mark Brown <broonie@kernel.org>,
	Peter Collingbourne <pcc@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Kees Cook <keescook@chromium.org>,
	Daniel Kiss <daniel.kiss@arm.com>,
	linux-kernel@vger.kernel.org, James Morse <james.morse@arm.com>
Subject: Re: [RFC PATCH v1 1/1] arm64: Forget syscall if different from execve*()
Date: Wed, 18 May 2022 14:32:56 +0100	[thread overview]
Message-ID: <YoT1iLPEbteRTQGZ@arm.com> (raw)
In-Reply-To: <20220510140333.GA28104@willie-the-truck>

On Tue, May 10, 2022 at 03:03:33PM +0100, Will Deacon wrote:
> On Tue, May 10, 2022 at 03:00:11PM +0100, Francis Laniel wrote:
> > Le mardi 10 mai 2022, 11:59:48 BST Will Deacon a �crit :
> > > On Mon, May 09, 2022 at 04:19:57PM +0100, Francis Laniel wrote:
> > > > diff --git a/arch/arm64/include/asm/processor.h
> > > > b/arch/arm64/include/asm/processor.h index 73e38d9a540c..e12ceb363d6a
> > > > 100644
> > > > --- a/arch/arm64/include/asm/processor.h
> > > > +++ b/arch/arm64/include/asm/processor.h
> > > > @@ -34,6 +34,8 @@
> > > > 
> > > >  #include <vdso/processor.h>
> > > > 
> > > > +#include <asm-generic/unistd.h>
> > > > +
> > > > 
> > > >  #include <asm/alternative.h>
> > > >  #include <asm/cpufeature.h>
> > > >  #include <asm/hw_breakpoint.h>
> > > > 
> > > > @@ -250,8 +252,12 @@ void tls_preserve_current_state(void);
> > > > 
> > > >  static inline void start_thread_common(struct pt_regs *regs, unsigned
> > > >  long pc) {
> > > > 
> > > > +	s32 previous_syscall = regs->syscallno;
> > > > 
> > > >  	memset(regs, 0, sizeof(*regs));
> > > > 
> > > > -	forget_syscall(regs);
> > > > +	if (previous_syscall == __NR_execve || previous_syscall ==
> > > > __NR_execveat)
> > > > +		regs->syscallno = previous_syscall;
> > > > +	else
> > > > +		forget_syscall(regs);
> > > 
> > > Hmm, this really looks like a bodge and it doesn't handle the compat case
> > > either.
> > > 
> > > How do other architectures handle this?
> > 
> > My understanding of others architectures is quite limited, but here are my 
> > findings and understanding of some of them:
> > * arm (32 bits) EABI: start_thread() sets r7 to previous r7 for ELF FDPIC  and 
> > to 0 for other binfmts [1].
> > * arm (32 bits) OABI: syscall number is set to -1 if 
> > ptrace_report_syscall_entry() failed [2].
> > * mips: start_thread() does not modify current_thread_info->syscall which is 
> > taken directly from v0 [3, 4].
> > * riscv: start_thread() does not modify a7 [5].
> > * x86_64: start_thread_common() does not touch orig_ax which seems to contain 
> > the syscall number [6].
> 
> Hmm, so the million dollar question is why on Earth we have that
> forget_syscall() call to start with. Amusingly I've, err, forgotten;
> forget_forget_syscall() perhaps?
> 
> Catalin? It's been there since day one afaict.

Looking at the old logs, this appeared somewhere between day 0 and 1. We
had a memset(regs, 0) with a pt_regs of 36 registers but moved to
dedicated names for syscallno etc. and that's where I changed it from 0
to ~0UL.

A few weeks ago James Morse (cc'ed) came across this issue and even sent
a patch internally to remove forget_syscall() here. But that looks like
a bodge and James' suggestion was that maybe the core code can preserve
the syscallno and this would fix it for all architectures.

-- 
Catalin

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

  parent reply	other threads:[~2022-05-18 13:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09 15:19 [RFC PATCH v1 0/1] Call forget_syscall() if different than execve*() Francis Laniel
2022-05-09 15:19 ` Francis Laniel
2022-05-09 15:19 ` [RFC PATCH v1 1/1] arm64: Forget syscall if different from execve*() Francis Laniel
2022-05-09 15:19   ` Francis Laniel
2022-05-10 10:59   ` Will Deacon
2022-05-10 10:59     ` Will Deacon
2022-05-10 14:00     ` Francis Laniel
2022-05-10 14:00       ` Francis Laniel
2022-05-10 14:03       ` Will Deacon
2022-05-10 14:03         ` Will Deacon
2022-05-10 14:12         ` Francis Laniel
2022-05-10 14:12           ` Francis Laniel
2022-05-18 13:32         ` Catalin Marinas [this message]
2022-05-18 13:32           ` Catalin Marinas
2022-05-10 13:33   ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2022-05-12 23:03 kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YoT1iLPEbteRTQGZ@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=broonie@kernel.org \
    --cc=daniel.kiss@arm.com \
    --cc=flaniel@linux.microsoft.com \
    --cc=james.morse@arm.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pcc@google.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.