linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] stackleak: fixes and rework
@ 2022-04-25 11:55 Mark Rutland
  2022-04-25 11:55 ` [PATCH 1/8] arm64: stackleak: fix current_top_of_stack() Mark Rutland
                   ` (9 more replies)
  0 siblings, 10 replies; 18+ messages in thread
From: Mark Rutland @ 2022-04-25 11:55 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: akpm, alex.popov, catalin.marinas, keescook, luto, mark.rutland,
	will

This series reworks the stackleak code. The first patch fixes some
latent issues on arm64, and the subsequent patches improve the code to
improve clarity and permit better code generation.

I started working on this as a tangent from rework to arm64's stacktrace
code. Looking at users of the `on_*_stack()` helpers I noticed that the
assembly generated for stackleak was particularly awful as it performed
a lot of redundant work and also called instrumentable code, which isn't
sound.

The first patch fixes the major issues on arm64, and is Cc'd to stable
for backporting.

The second patch is a trivial optimization for when stackleak is
dynamically disabled.

The subsequent patches rework the way stackleak manipulates the stack
boundary values. This is partically for clarity (e.g. with separate
'low' and 'high' boundary variables), and also permits the compiler to
generate more optimal assembly by generating the high and low bounds
from the same base.

Patch 5 changes the way that `current->lowest_stack` is reset prior to
return to userspace. The existing code uses an undocumented offset
relative to the top of the stack which doesn't make much sense (as thie
sometimes falls within the task's pt_regs, or sometimes adds 600+ bytes
to erase upon the next exit to userspace). For now I've removed the
offset entirely.

Patch 7 adds stackleak_erase_on_task_stack() and
stackleak_erase_off_task_stack() that can be used when a caller knows
they're always on or off the task stack respectively, avoiding redundant
logic to check this and generate the high boundary value. On arm64 we
always call stackleak_erase() while on the task stack, so this is used
in patch 8.

Testing the series on arm64 with a QEMU HVF VM on an M1 Macbook Pro with
a few microbenchmarks shows a small but measureable improvement when
stackleak is enabled (relative to v5.18-rc1):

* Calling getpid 1^22 times in a loop (avg 50 runs)
  
  Before: 0.652099387 seconds ( +-  0.13% )
  After:  0.641005661 seconds ( +-  0.13% )

  ~1.7% time decrease

* perf bench sched pipe (single run)

  Before: 2.138 seconds total
  After:  2.118 seconds total

  ~0.93% time decrease

I also tested "perf bench sched messaging" but the noise outweighed the
difference.

While the improvement is small, I think the improvement to clarity and
code generation is a win regardless.

Thanks,
Mark.

Mark Rutland (8):
  arm64: stackleak: fix current_top_of_stack()
  stackleak: move skip_erasing() check earlier
  stackleak: rework stack low bound handling
  stackleak: clarify variable names
  stackleak: rework stack high bound handling
  stackleak: remove redundant check
  stackleak: add on/off stack variants
  arm64: entry: use stackleak_erase_on_task_stack()

 arch/arm64/include/asm/processor.h | 10 ++-
 arch/arm64/kernel/entry.S          |  2 +-
 include/linux/stackleak.h          | 29 ++++++++-
 kernel/stackleak.c                 | 99 ++++++++++++++++++++----------
 4 files changed, 98 insertions(+), 42 deletions(-)

-- 
2.30.2


_______________________________________________
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] 18+ messages in thread

end of thread, other threads:[~2022-04-26 18:02 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-25 11:55 [PATCH 0/8] stackleak: fixes and rework Mark Rutland
2022-04-25 11:55 ` [PATCH 1/8] arm64: stackleak: fix current_top_of_stack() Mark Rutland
2022-04-25 11:55 ` [PATCH 2/8] stackleak: move skip_erasing() check earlier Mark Rutland
2022-04-25 11:55 ` [PATCH 3/8] stackleak: rework stack low bound handling Mark Rutland
2022-04-25 11:55 ` [PATCH 4/8] stackleak: clarify variable names Mark Rutland
2022-04-25 11:56 ` [PATCH 5/8] stackleak: rework stack high bound handling Mark Rutland
2022-04-25 11:56 ` [PATCH 6/8] stackleak: remove redundant check Mark Rutland
2022-04-25 11:56 ` [PATCH 7/8] stackleak: add on/off stack variants Mark Rutland
2022-04-25 11:56 ` [PATCH 8/8] arm64: entry: use stackleak_erase_on_task_stack() Mark Rutland
2022-04-25 22:54 ` [PATCH 0/8] stackleak: fixes and rework Kees Cook
2022-04-26 10:10   ` Mark Rutland
2022-04-26 10:37     ` Mark Rutland
2022-04-26 11:15       ` Mark Rutland
2022-04-26 15:51   ` Alexander Popov
2022-04-26 16:07     ` Mark Rutland
2022-04-26 16:01   ` Mark Rutland
2022-04-26 18:01     ` Kees Cook
2022-04-26 17:51 ` Kees Cook

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).