[PATCH v2 0/6] arm64/signal: Signal handling cleanups

Mark Brown posted 6 patches 3 years, 3 months ago
There is a newer version of this series
arch/arm64/kernel/signal.c | 91 +++++++++++++++++++++++-----------------------
1 file changed, 46 insertions(+), 45 deletions(-)
[PATCH v2 0/6] arm64/signal: Signal handling cleanups
Posted by Mark Brown 3 years, 3 months ago
This series collects a number of small cleanups to the signal handling
code which removes redundant validation of size information and avoids
reading the same data from userspace twice.

There are some overlaps with both the TPIDR2 signal handling and SME2
serieses which are also in flight, applying this will require
adjustments in those serieses and vice versa.

v2:
 - Rebase onto v6.2-rc1

To: Catalin Marinas <catalin.marinas@arm.com>
To: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>

---
Mark Brown (6):
      arm64/signal: Don't redundantly verify FPSIMD magic
      arm64/signal: Remove redundant size validation from parse_user_sigframe()
      arm64/signal: Make interface for restore_fpsimd_context() consistent
      arm64/signal: Avoid rereading context frame sizes
      arm64/signal: Only read new data when parsing the SVE context
      arm64/signal: Only read new data when parsing the ZA context

 arch/arm64/kernel/signal.c | 91 +++++++++++++++++++++++-----------------------
 1 file changed, 46 insertions(+), 45 deletions(-)
---
base-commit: 1b929c02afd37871d5afb9d498426f83432e71c2
change-id: 20221212-arm64-signal-cleanup-bcd7272de5a9

Best regards,
-- 
Mark Brown <broonie@kernel.org>
Re: [PATCH v2 0/6] arm64/signal: Signal handling cleanups
Posted by Catalin Marinas 3 years, 2 months ago
Hi Mark,

On Tue, Jan 03, 2023 at 08:25:15PM +0000, Mark Brown wrote:
> This series collects a number of small cleanups to the signal handling
> code which removes redundant validation of size information and avoids
> reading the same data from userspace twice.
> 
> There are some overlaps with both the TPIDR2 signal handling and SME2
> serieses which are also in flight, applying this will require
> adjustments in those serieses and vice versa.
[...]
> Mark Brown (6):
>       arm64/signal: Don't redundantly verify FPSIMD magic
>       arm64/signal: Remove redundant size validation from parse_user_sigframe()
>       arm64/signal: Make interface for restore_fpsimd_context() consistent

I'm fine with the first three patches, they seem correct and make the
frame checking more consistent.

>       arm64/signal: Avoid rereading context frame sizes
>       arm64/signal: Only read new data when parsing the SVE context
>       arm64/signal: Only read new data when parsing the ZA context

I'm not sure these add much to the code readability (and the performance
improvement I guess is negligible). We avoid some copy_from_user() into
the context structures but rely on data read previously or some
get_user() into local variables. Personally I'd make the
restore_fpsimd_context() also do a copy_from_user() for consistency with
the current sve and za frames restoring.

Personal preference, not sure whether Will has the same view.

-- 
Catalin
Re: [PATCH v2 0/6] arm64/signal: Signal handling cleanups
Posted by Will Deacon 3 years, 2 months ago
On Tue, Jan 31, 2023 at 12:51:33PM +0000, Catalin Marinas wrote:
> Hi Mark,
> 
> On Tue, Jan 03, 2023 at 08:25:15PM +0000, Mark Brown wrote:
> > This series collects a number of small cleanups to the signal handling
> > code which removes redundant validation of size information and avoids
> > reading the same data from userspace twice.
> > 
> > There are some overlaps with both the TPIDR2 signal handling and SME2
> > serieses which are also in flight, applying this will require
> > adjustments in those serieses and vice versa.
> [...]
> > Mark Brown (6):
> >       arm64/signal: Don't redundantly verify FPSIMD magic
> >       arm64/signal: Remove redundant size validation from parse_user_sigframe()
> >       arm64/signal: Make interface for restore_fpsimd_context() consistent
> 
> I'm fine with the first three patches, they seem correct and make the
> frame checking more consistent.
> 
> >       arm64/signal: Avoid rereading context frame sizes
> >       arm64/signal: Only read new data when parsing the SVE context
> >       arm64/signal: Only read new data when parsing the ZA context
> 
> I'm not sure these add much to the code readability (and the performance
> improvement I guess is negligible). We avoid some copy_from_user() into
> the context structures but rely on data read previously or some
> get_user() into local variables. Personally I'd make the
> restore_fpsimd_context() also do a copy_from_user() for consistency with
> the current sve and za frames restoring.
> 
> Personal preference, not sure whether Will has the same view.

That main thing I'm worried about is the potential for ToCToU bugs if we
read userdata more than once. For example, if we end up splitting checks
between the two reads, then an attacker could update the value in the
middle and potential cause us issues. If we just read the stuff once, we
don't have to worry about that.

Will
Re: [PATCH v2 0/6] arm64/signal: Signal handling cleanups
Posted by Catalin Marinas 3 years, 2 months ago
On Tue, Jan 31, 2023 at 03:38:16PM +0000, Will Deacon wrote:
> On Tue, Jan 31, 2023 at 12:51:33PM +0000, Catalin Marinas wrote:
> > Hi Mark,
> > 
> > On Tue, Jan 03, 2023 at 08:25:15PM +0000, Mark Brown wrote:
> > > This series collects a number of small cleanups to the signal handling
> > > code which removes redundant validation of size information and avoids
> > > reading the same data from userspace twice.
> > > 
> > > There are some overlaps with both the TPIDR2 signal handling and SME2
> > > serieses which are also in flight, applying this will require
> > > adjustments in those serieses and vice versa.
> > [...]
> > > Mark Brown (6):
> > >       arm64/signal: Don't redundantly verify FPSIMD magic
> > >       arm64/signal: Remove redundant size validation from parse_user_sigframe()
> > >       arm64/signal: Make interface for restore_fpsimd_context() consistent
> > 
> > I'm fine with the first three patches, they seem correct and make the
> > frame checking more consistent.
> > 
> > >       arm64/signal: Avoid rereading context frame sizes
> > >       arm64/signal: Only read new data when parsing the SVE context
> > >       arm64/signal: Only read new data when parsing the ZA context
> > 
> > I'm not sure these add much to the code readability (and the performance
> > improvement I guess is negligible). We avoid some copy_from_user() into
> > the context structures but rely on data read previously or some
> > get_user() into local variables. Personally I'd make the
> > restore_fpsimd_context() also do a copy_from_user() for consistency with
> > the current sve and za frames restoring.
> > 
> > Personal preference, not sure whether Will has the same view.
> 
> That main thing I'm worried about is the potential for ToCToU bugs if we
> read userdata more than once. For example, if we end up splitting checks
> between the two reads, then an attacker could update the value in the
> middle and potential cause us issues. If we just read the stuff once, we
> don't have to worry about that.

I thought this may be the case but I couldn't come up with an exploit.
The actual size validation is done after the second read. The first read
of the size is used to walk the frame and check the magic values.

Anyway, you are probably right, it's easier to reason about ToCToU if we
only read the size once.

-- 
Catalin
Re: [PATCH v2 0/6] arm64/signal: Signal handling cleanups
Posted by Mark Brown 3 years, 2 months ago
On Tue, Jan 31, 2023 at 12:51:33PM +0000, Catalin Marinas wrote:
> On Tue, Jan 03, 2023 at 08:25:15PM +0000, Mark Brown wrote:

> >       arm64/signal: Avoid rereading context frame sizes
> >       arm64/signal: Only read new data when parsing the SVE context
> >       arm64/signal: Only read new data when parsing the ZA context

> I'm not sure these add much to the code readability (and the performance
> improvement I guess is negligible). We avoid some copy_from_user() into
> the context structures but rely on data read previously or some
> get_user() into local variables. Personally I'd make the
> restore_fpsimd_context() also do a copy_from_user() for consistency with
> the current sve and za frames restoring.

> Personal preference, not sure whether Will has the same view.

I don't particularly care about those changs either, Will seemed to be
asking for something like that.

Note that I should at some point today send a version of this series
rebased on for-next/core due to the TPIDR2 and SME2 changes.