* [PATCH v2 0/5] POE sigreturn fix and extra tests
@ 2026-04-27 12:03 Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 1/5] arm64: signal: Preserve POR_EL0 if poe_context is missing Kevin Brodsky
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Kevin Brodsky @ 2026-04-27 12:03 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Kevin Brodsky, Andrew Morton, Catalin Marinas,
David Hildenbrand (Arm), Joey Gouly, Mark Brown, Shuah Khan,
Will Deacon, linux-kselftest, linux-mm, linux-kernel
Commit 2e8a1acea859 ("arm64: signal: Improve POR_EL0 handling to
avoid uaccess failures") introduced special handling for EL0 registers
that impact uaccess. This did not however handle the case where a signal
handler removes the relevant record (poe_context for POE) from the
signal frame; this is clearly not typical behaviour but it is legal.
That commit resulted in arbitrary data from the kernel stack being
written to POR_EL0 in that case.
Patch 1 fixes this by tracking which fields in struct user_access_state
are actually valid. This restores the original behaviour, where POR_EL0
is left untouched if poe_context is removed.
The remaining patches add new tests to the arm64 signal kselftests to
check that POR_EL0 is reset and restored (or preserved) as expected.
Patch 2 fixes an issue found by Sashiko while reusing some code for
the new tests.
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
v1..v2:
- Patch 1: introduced accessors and moved to using {} for zero-init
[Will]
- Patch 1: removed change in setup_sigframe() - using the new flag
isn't actually more consistent than checking system_supports_poe()
and doesn't play well with the new accessors
- Patch 5: fixed the size passed to get_header(), as reported by
Sashiko. Added patch 2 to fix the issue where I had originally
found it.
- Patch 4: improved commit title [Mark]
- Collected R-b
v1: https://lore.kernel.org/all/20260421144252.1440365-1-kevin.brodsky@arm.com/
---
To: linux-arm-kernel@lists.infradead.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Hildenbrand (Arm) <david@kernel.org>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Will Deacon <will@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
Kevin Brodsky (5):
arm64: signal: Preserve POR_EL0 if poe_context is missing
selftests/mm: Fix resv_sz when parsing arm64 signal frame
kselftest/arm64: Add POE as a feature in the signal tests
kselftest/arm64: Move/add POE helpers to test_signals_utils.h
kselftest/arm64: Add tests for POR_EL0 save/reset/restore
arch/arm64/kernel/signal.c | 54 ++++++++++++----
.../testing/selftests/arm64/signal/test_signals.h | 2 +
.../selftests/arm64/signal/test_signals_utils.c | 3 +
.../selftests/arm64/signal/test_signals_utils.h | 16 +++++
.../signal/testcases/poe_missing_poe_context.c | 73 ++++++++++++++++++++++
.../selftests/arm64/signal/testcases/poe_restore.c | 64 +++++++++++++++++++
.../selftests/arm64/signal/testcases/poe_siginfo.c | 15 -----
tools/testing/selftests/mm/pkey-arm64.h | 3 +-
8 files changed, 203 insertions(+), 27 deletions(-)
---
base-commit: 028ef9c96e96197026887c0f092424679298aae8
change-id: 20260423-poe_signal-809193c5225d
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/5] arm64: signal: Preserve POR_EL0 if poe_context is missing
2026-04-27 12:03 [PATCH v2 0/5] POE sigreturn fix and extra tests Kevin Brodsky
@ 2026-04-27 12:03 ` Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 2/5] selftests/mm: Fix resv_sz when parsing arm64 signal frame Kevin Brodsky
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Kevin Brodsky @ 2026-04-27 12:03 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Kevin Brodsky, Andrew Morton, Catalin Marinas,
David Hildenbrand (Arm), Joey Gouly, Mark Brown, Shuah Khan,
Will Deacon, linux-kselftest, linux-mm, linux-kernel
Commit 2e8a1acea859 ("arm64: signal: Improve POR_EL0 handling to
avoid uaccess failures") delayed the write to POR_EL0 in
rt_sigreturn to avoid spurious uaccess failures. This change however
relies on the poe_context frame record being present: on a system
supporting POE, calling sigreturn without a poe_context record now
results in writing arbitrary data from the kernel stack into POR_EL0.
Fix this by adding a __valid_fields member to struct
user_access_state, and zeroing the struct on allocation.
restore_poe_context() then indicates that the por_el0 field is valid
by setting the corresponding bit in __valid_fields, and
restore_user_access_state() only touches POR_EL0 if there is a valid
value to set it to. This is in line with how POR_EL0 was originally
handled; all frame records are currently optional, except
fpsimd_context.
To ensure that __valid_fields is kept in sync, fields (currently
just por_el0) are now accessed via accessors and prefixed with __ to
discourage direct access.
Fixes: 2e8a1acea859 ("arm64: signal: Improve POR_EL0 handling to avoid uaccess failures")
Reported-by: Will Deacon <will@kernel.org>
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
arch/arm64/kernel/signal.c | 54 ++++++++++++++++++++++++++++++++++++----------
1 file changed, 43 insertions(+), 11 deletions(-)
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 08ffc5a5aea4..38e6fa204c17 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -67,6 +67,9 @@ struct rt_sigframe_user_layout {
unsigned long end_offset;
};
+#define TERMINATOR_SIZE round_up(sizeof(struct _aarch64_ctx), 16)
+#define EXTRA_CONTEXT_SIZE round_up(sizeof(struct extra_context), 16)
+
/*
* Holds any EL0-controlled state that influences unprivileged memory accesses.
* This includes both accesses done in userspace and uaccess done in the kernel.
@@ -74,13 +77,35 @@ struct rt_sigframe_user_layout {
* This state needs to be carefully managed to ensure that it doesn't cause
* uaccess to fail when setting up the signal frame, and the signal handler
* itself also expects a well-defined state when entered.
+ *
+ * The struct should be zero-initialised. Its members should only be accessed
+ * via the accessors below. __valid_fields tracks which of the fields are valid
+ * (have been set to some value).
*/
struct user_access_state {
- u64 por_el0;
+ unsigned int __valid_fields;
+ u64 __por_el0;
};
-#define TERMINATOR_SIZE round_up(sizeof(struct _aarch64_ctx), 16)
-#define EXTRA_CONTEXT_SIZE round_up(sizeof(struct extra_context), 16)
+#define UA_STATE_HAS_POR_EL0 BIT(0)
+
+static void set_ua_state_por_el0(struct user_access_state *ua_state,
+ u64 por_el0)
+{
+ ua_state->__por_el0 = por_el0;
+ ua_state->__valid_fields |= UA_STATE_HAS_POR_EL0;
+}
+
+static int get_ua_state_por_el0(const struct user_access_state *ua_state,
+ u64 *por_el0)
+{
+ if (ua_state->__valid_fields & UA_STATE_HAS_POR_EL0) {
+ *por_el0 = ua_state->__por_el0;
+ return 0;
+ }
+
+ return -ENOENT;
+}
/*
* Save the user access state into ua_state and reset it to disable any
@@ -94,7 +119,7 @@ static void save_reset_user_access_state(struct user_access_state *ua_state)
for (int pkey = 0; pkey < arch_max_pkey(); pkey++)
por_enable_all |= POR_ELx_PERM_PREP(pkey, POE_RWX);
- ua_state->por_el0 = read_sysreg_s(SYS_POR_EL0);
+ set_ua_state_por_el0(ua_state, read_sysreg_s(SYS_POR_EL0));
write_sysreg_s(por_enable_all, SYS_POR_EL0);
/*
* No ISB required as we can tolerate spurious Overlay faults -
@@ -122,8 +147,10 @@ static void set_handler_user_access_state(void)
*/
static void restore_user_access_state(const struct user_access_state *ua_state)
{
- if (system_supports_poe())
- write_sysreg_s(ua_state->por_el0, SYS_POR_EL0);
+ u64 por_el0;
+
+ if (get_ua_state_por_el0(ua_state, &por_el0) == 0)
+ write_sysreg_s(por_el0, SYS_POR_EL0);
}
static void init_user_layout(struct rt_sigframe_user_layout *user)
@@ -333,11 +360,16 @@ static int restore_fpmr_context(struct user_ctxs *user)
static int preserve_poe_context(struct poe_context __user *ctx,
const struct user_access_state *ua_state)
{
- int err = 0;
+ int err;
+ u64 por_el0;
+
+ err = get_ua_state_por_el0(ua_state, &por_el0);
+ if (WARN_ON_ONCE(err))
+ return err;
__put_user_error(POE_MAGIC, &ctx->head.magic, err);
__put_user_error(sizeof(*ctx), &ctx->head.size, err);
- __put_user_error(ua_state->por_el0, &ctx->por_el0, err);
+ __put_user_error(por_el0, &ctx->por_el0, err);
return err;
}
@@ -353,7 +385,7 @@ static int restore_poe_context(struct user_ctxs *user,
__get_user_error(por_el0, &(user->poe->por_el0), err);
if (!err)
- ua_state->por_el0 = por_el0;
+ set_ua_state_por_el0(ua_state, por_el0);
return err;
}
@@ -1095,7 +1127,7 @@ SYSCALL_DEFINE0(rt_sigreturn)
{
struct pt_regs *regs = current_pt_regs();
struct rt_sigframe __user *frame;
- struct user_access_state ua_state;
+ struct user_access_state ua_state = {};
/* Always make any pending restarted system calls return -EINTR */
current->restart_block.fn = do_no_restart_syscall;
@@ -1507,7 +1539,7 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
{
struct rt_sigframe_user_layout user;
struct rt_sigframe __user *frame;
- struct user_access_state ua_state;
+ struct user_access_state ua_state = {};
int err = 0;
fpsimd_save_and_flush_current_state();
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/5] selftests/mm: Fix resv_sz when parsing arm64 signal frame
2026-04-27 12:03 [PATCH v2 0/5] POE sigreturn fix and extra tests Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 1/5] arm64: signal: Preserve POR_EL0 if poe_context is missing Kevin Brodsky
@ 2026-04-27 12:03 ` Kevin Brodsky
2026-04-27 22:46 ` Mark Brown
2026-04-27 12:03 ` [PATCH v2 3/5] kselftest/arm64: Add POE as a feature in the signal tests Kevin Brodsky
` (2 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Kevin Brodsky @ 2026-04-27 12:03 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Kevin Brodsky, Andrew Morton, Catalin Marinas,
David Hildenbrand (Arm), Joey Gouly, Mark Brown, Shuah Khan,
Will Deacon, linux-kselftest, linux-mm, linux-kernel
get_header() wants the size of the reserved area in struct
sigcontext, but instead we pass it the size of the entire struct.
This could in theory result in an out-of-bounds read (if the signal
frame is malformed).
Fix this using one of the existing macros from
tools/testing/selftests/arm64/signal/testcases/testcases.h.
This issue was reported by Sashiko on a patch that copied this
portion of the code.
Link: https://sashiko.dev/#/patchset/20260421144252.1440365-1-kevin.brodsky%40arm.com
Fixes: f5b5ea51f78f ("selftests: mm: make protection_keys test work on arm64")
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
tools/testing/selftests/mm/pkey-arm64.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/pkey-arm64.h b/tools/testing/selftests/mm/pkey-arm64.h
index 8e9685e03c44..c5a78a2f211d 100644
--- a/tools/testing/selftests/mm/pkey-arm64.h
+++ b/tools/testing/selftests/mm/pkey-arm64.h
@@ -130,9 +130,10 @@ static inline u64 get_pkey_bits(u64 reg, int pkey)
static inline void aarch64_write_signal_pkey(ucontext_t *uctxt, u64 pkey)
{
struct _aarch64_ctx *ctx = GET_UC_RESV_HEAD(uctxt);
+ size_t resv_size = GET_UCP_RESV_SIZE(uctxt);
struct poe_context *poe_ctx =
(struct poe_context *) get_header(ctx, POE_MAGIC,
- sizeof(uctxt->uc_mcontext), NULL);
+ resv_size, NULL);
if (poe_ctx)
poe_ctx->por_el0 = pkey;
}
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/5] kselftest/arm64: Add POE as a feature in the signal tests
2026-04-27 12:03 [PATCH v2 0/5] POE sigreturn fix and extra tests Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 1/5] arm64: signal: Preserve POR_EL0 if poe_context is missing Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 2/5] selftests/mm: Fix resv_sz when parsing arm64 signal frame Kevin Brodsky
@ 2026-04-27 12:03 ` Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 4/5] kselftest/arm64: Move/add POE helpers to test_signals_utils.h Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 5/5] kselftest/arm64: Add tests for POR_EL0 save/reset/restore Kevin Brodsky
4 siblings, 0 replies; 7+ messages in thread
From: Kevin Brodsky @ 2026-04-27 12:03 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Kevin Brodsky, Andrew Morton, Catalin Marinas,
David Hildenbrand (Arm), Joey Gouly, Mark Brown, Shuah Khan,
Will Deacon, linux-kselftest, linux-mm, linux-kernel
Add the POE feature to the signal tests framework, to allow tests to
require it.
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
tools/testing/selftests/arm64/signal/test_signals.h | 2 ++
tools/testing/selftests/arm64/signal/test_signals_utils.c | 3 +++
2 files changed, 5 insertions(+)
diff --git a/tools/testing/selftests/arm64/signal/test_signals.h b/tools/testing/selftests/arm64/signal/test_signals.h
index ee75a2c25ce7..c7c343494cb8 100644
--- a/tools/testing/selftests/arm64/signal/test_signals.h
+++ b/tools/testing/selftests/arm64/signal/test_signals.h
@@ -36,6 +36,7 @@ enum {
FSME_FA64_BIT,
FSME2_BIT,
FGCS_BIT,
+ FPOE_BIT,
FMAX_END
};
@@ -45,6 +46,7 @@ enum {
#define FEAT_SME_FA64 (1UL << FSME_FA64_BIT)
#define FEAT_SME2 (1UL << FSME2_BIT)
#define FEAT_GCS (1UL << FGCS_BIT)
+#define FEAT_POE (1UL << FPOE_BIT)
/*
* A descriptor used to describe and configure a test case.
diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.c b/tools/testing/selftests/arm64/signal/test_signals_utils.c
index 5d3621921cfe..4b12dbd7669d 100644
--- a/tools/testing/selftests/arm64/signal/test_signals_utils.c
+++ b/tools/testing/selftests/arm64/signal/test_signals_utils.c
@@ -31,6 +31,7 @@ static char const *const feats_names[FMAX_END] = {
" FA64 ",
" SME2 ",
" GCS ",
+ " POE ",
};
#define MAX_FEATS_SZ 128
@@ -341,6 +342,8 @@ int test_init(struct tdescr *td)
td->feats_supported |= FEAT_SME2;
if (getauxval(AT_HWCAP) & HWCAP_GCS)
td->feats_supported |= FEAT_GCS;
+ if (getauxval(AT_HWCAP2) & HWCAP2_POE)
+ td->feats_supported |= FEAT_POE;
if (feats_ok(td)) {
if (td->feats_required & td->feats_supported)
fprintf(stderr,
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 4/5] kselftest/arm64: Move/add POE helpers to test_signals_utils.h
2026-04-27 12:03 [PATCH v2 0/5] POE sigreturn fix and extra tests Kevin Brodsky
` (2 preceding siblings ...)
2026-04-27 12:03 ` [PATCH v2 3/5] kselftest/arm64: Add POE as a feature in the signal tests Kevin Brodsky
@ 2026-04-27 12:03 ` Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 5/5] kselftest/arm64: Add tests for POR_EL0 save/reset/restore Kevin Brodsky
4 siblings, 0 replies; 7+ messages in thread
From: Kevin Brodsky @ 2026-04-27 12:03 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Kevin Brodsky, Andrew Morton, Catalin Marinas,
David Hildenbrand (Arm), Joey Gouly, Mark Brown, Shuah Khan,
Will Deacon, linux-kselftest, linux-mm, linux-kernel
In preparation to adding further POE signal tests, move
get_por_el0() to test_signals_utils.h and add set_por_el0().
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
.../testing/selftests/arm64/signal/test_signals_utils.h | 16 ++++++++++++++++
.../selftests/arm64/signal/testcases/poe_siginfo.c | 15 ---------------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.h b/tools/testing/selftests/arm64/signal/test_signals_utils.h
index 36fc12b3cd60..2c7b8c64a35a 100644
--- a/tools/testing/selftests/arm64/signal/test_signals_utils.h
+++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h
@@ -57,6 +57,22 @@ static inline __attribute__((always_inline)) uint64_t get_gcspr_el0(void)
return val;
}
+#define SYS_POR_EL0 "S3_3_C10_C2_4"
+
+static inline uint64_t get_por_el0(void)
+{
+ uint64_t val;
+
+ asm volatile("mrs %0, " SYS_POR_EL0 "\n" : "=r"(val));
+
+ return val;
+}
+
+static inline void set_por_el0(uint64_t val)
+{
+ asm volatile("msr " SYS_POR_EL0 ", %0\n" :: "r"(val));
+}
+
static inline bool feats_ok(struct tdescr *td)
{
if (td->feats_incompatible & td->feats_supported)
diff --git a/tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c b/tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c
index 36bd9940ee05..e15fedf4da6e 100644
--- a/tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c
+++ b/tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c
@@ -21,21 +21,6 @@ static union {
char buf[1024 * 128];
} context;
-#define SYS_POR_EL0 "S3_3_C10_C2_4"
-
-static uint64_t get_por_el0(void)
-{
- uint64_t val;
-
- asm volatile(
- "mrs %0, " SYS_POR_EL0 "\n"
- : "=r"(val)
- :
- : );
-
- return val;
-}
-
int poe_present(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
{
struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 5/5] kselftest/arm64: Add tests for POR_EL0 save/reset/restore
2026-04-27 12:03 [PATCH v2 0/5] POE sigreturn fix and extra tests Kevin Brodsky
` (3 preceding siblings ...)
2026-04-27 12:03 ` [PATCH v2 4/5] kselftest/arm64: Move/add POE helpers to test_signals_utils.h Kevin Brodsky
@ 2026-04-27 12:03 ` Kevin Brodsky
4 siblings, 0 replies; 7+ messages in thread
From: Kevin Brodsky @ 2026-04-27 12:03 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Kevin Brodsky, Andrew Morton, Catalin Marinas,
David Hildenbrand (Arm), Joey Gouly, Mark Brown, Shuah Khan,
Will Deacon, linux-kselftest, linux-mm, linux-kernel
POR_EL0 is expected to be:
- Saved in the poe_context record
- Reset to POR_EL0_INIT when invoking the signal handler
- Restored from poe_context when returning from the signal handler
Add a new test, poe_restore, to check that the save/reset/restore
mechanism is working as intended. See commit 2e8a1acea859 ("arm64:
signal: Improve POR_EL0 handling to avoid uaccess failures") for
more details.
This commit did not handle the case where poe_context is missing
correctly. This was recently fixed; add a new test,
poe_missing_poe_context, to check this case.
Note: td->pass is only set to true at the very end, as an unexpected
signal may occur in case of failure (especially in
poe_missing_poe_context if POR_EL0 is restored to an invalid value).
Failures are tracked with a global, failed_check.
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
.../signal/testcases/poe_missing_poe_context.c | 73 ++++++++++++++++++++++
.../selftests/arm64/signal/testcases/poe_restore.c | 64 +++++++++++++++++++
2 files changed, 137 insertions(+)
diff --git a/tools/testing/selftests/arm64/signal/testcases/poe_missing_poe_context.c b/tools/testing/selftests/arm64/signal/testcases/poe_missing_poe_context.c
new file mode 100644
index 000000000000..3f22d8cf6106
--- /dev/null
+++ b/tools/testing/selftests/arm64/signal/testcases/poe_missing_poe_context.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Arm Ltd
+ *
+ * Verify that the POR_EL0 register is left untouched on sigreturn if the
+ * POE frame record is missing.
+ */
+
+#include <asm/sigcontext.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+#define POR_EL0_INIT 0x07ul
+#define POR_EL0_CUSTOM 0x77ul
+
+static bool failed_check;
+
+static bool modify_por_el0(struct tdescr *td)
+{
+ set_por_el0(POR_EL0_CUSTOM);
+
+ return true;
+}
+
+static int signal_remove_poe_context(struct tdescr *td, siginfo_t *si,
+ ucontext_t *uc)
+{
+ struct _aarch64_ctx *ctx = GET_UC_RESV_HEAD(uc);
+ size_t resv_size = GET_UCP_RESV_SIZE(uc);
+ struct _aarch64_ctx *poe_ctx_head;
+
+ poe_ctx_head = get_header(ctx, POE_MAGIC, resv_size, NULL);
+ if (!poe_ctx_head) {
+ fprintf(stderr, "Missing poe_context record\n");
+ failed_check = true;
+ return 0;
+ }
+
+ /*
+ * Actually removing the record would require moving down the next
+ * records. An easier option is to turn it into an ESR record, which is
+ * ignored by sigreturn().
+ */
+ poe_ctx_head->magic = ESR_MAGIC;
+
+ return 0;
+}
+
+static void check_por_el0_preserved(struct tdescr *td)
+{
+ uint64_t por_el0 = get_por_el0();
+
+ if (por_el0 == POR_EL0_INIT) {
+ fprintf(stderr, "POR_EL0 preserved\n");
+ } else {
+ fprintf(stderr, "POR_EL0 unexpectedly set to %lx\n", por_el0);
+ failed_check = true;
+ }
+
+ td->pass = !failed_check;
+}
+
+struct tdescr tde = {
+ .name = "POR_EL0 missing poe_context",
+ .descr = "Remove poe_context record and check POR_EL0 is preserved",
+ .feats_required = FEAT_POE,
+ .timeout = 3,
+ .sig_trig = SIGUSR1,
+ .init = modify_por_el0,
+ .run = signal_remove_poe_context,
+ .check_result = check_por_el0_preserved,
+};
diff --git a/tools/testing/selftests/arm64/signal/testcases/poe_restore.c b/tools/testing/selftests/arm64/signal/testcases/poe_restore.c
new file mode 100644
index 000000000000..9f9a61a4214d
--- /dev/null
+++ b/tools/testing/selftests/arm64/signal/testcases/poe_restore.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Arm Ltd
+ *
+ * Verify that the POR_EL0 register is saved and restored as expected on signal
+ * entry/return.
+ */
+
+#include <asm/sigcontext.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+#define POR_EL0_INIT 0x07ul
+#define POR_EL0_CUSTOM 0x77ul
+
+static bool failed_check;
+
+static bool modify_por_el0(struct tdescr *td)
+{
+ set_por_el0(POR_EL0_CUSTOM);
+
+ return true;
+}
+
+static int signal_check_por_el0_reset(struct tdescr *td, siginfo_t *si,
+ ucontext_t *uc)
+{
+ uint64_t signal_por_el0 = get_por_el0();
+
+ if (signal_por_el0 != POR_EL0_INIT) {
+ fprintf(stderr, "POR_EL0 is %lx in signal handler (expected %lx)\n",
+ signal_por_el0, POR_EL0_INIT);
+ failed_check = true;
+ }
+
+ return 0;
+}
+
+static void check_por_el0_restored(struct tdescr *td)
+{
+ uint64_t por_el0 = get_por_el0();
+
+ if (por_el0 == POR_EL0_CUSTOM) {
+ fprintf(stderr, "POR_EL0 restored\n");
+ } else {
+ fprintf(stderr, "POR_EL0 was %lx but is now %lx\n",
+ POR_EL0_CUSTOM, por_el0);
+ failed_check = true;
+ }
+
+ td->pass = !failed_check;
+}
+
+struct tdescr tde = {
+ .name = "POR_EL0 restore",
+ .descr = "Validate that POR_EL0 is saved/restored on signal entry/return",
+ .feats_required = FEAT_POE,
+ .timeout = 3,
+ .sig_trig = SIGUSR1,
+ .init = modify_por_el0,
+ .run = signal_check_por_el0_reset,
+ .check_result = check_por_el0_restored,
+};
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/5] selftests/mm: Fix resv_sz when parsing arm64 signal frame
2026-04-27 12:03 ` [PATCH v2 2/5] selftests/mm: Fix resv_sz when parsing arm64 signal frame Kevin Brodsky
@ 2026-04-27 22:46 ` Mark Brown
0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2026-04-27 22:46 UTC (permalink / raw)
To: Kevin Brodsky
Cc: linux-arm-kernel, Andrew Morton, Catalin Marinas,
David Hildenbrand (Arm), Joey Gouly, Shuah Khan, Will Deacon,
linux-kselftest, linux-mm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 858 bytes --]
On Mon, Apr 27, 2026 at 01:03:34PM +0100, Kevin Brodsky wrote:
> get_header() wants the size of the reserved area in struct
> sigcontext, but instead we pass it the size of the entire struct.
> This could in theory result in an out-of-bounds read (if the signal
> frame is malformed).
> Fix this using one of the existing macros from
> tools/testing/selftests/arm64/signal/testcases/testcases.h.
Oh, good to know this is peering inside the arm64 selftests - it'd be
good to document that on the arm64 side to avoid unpleasant suprirses.
> {
> struct _aarch64_ctx *ctx = GET_UC_RESV_HEAD(uctxt);
> + size_t resv_size = GET_UCP_RESV_SIZE(uctxt);
> struct poe_context *poe_ctx =
> (struct poe_context *) get_header(ctx, POE_MAGIC,
> - sizeof(uctxt->uc_mcontext), NULL);
> + resv_size, NULL);
Reviewed-by: Mark Brown <broonie@kernel.org>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-04-27 22:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 12:03 [PATCH v2 0/5] POE sigreturn fix and extra tests Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 1/5] arm64: signal: Preserve POR_EL0 if poe_context is missing Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 2/5] selftests/mm: Fix resv_sz when parsing arm64 signal frame Kevin Brodsky
2026-04-27 22:46 ` Mark Brown
2026-04-27 12:03 ` [PATCH v2 3/5] kselftest/arm64: Add POE as a feature in the signal tests Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 4/5] kselftest/arm64: Move/add POE helpers to test_signals_utils.h Kevin Brodsky
2026-04-27 12:03 ` [PATCH v2 5/5] kselftest/arm64: Add tests for POR_EL0 save/reset/restore Kevin Brodsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox