All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kselftest/arm64: Copy whole EXTRA context
@ 2023-02-02 17:30 ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2023-02-02 17:30 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Shuah Khan
  Cc: linux-arm-kernel, linux-kselftest, Mark Brown

When copying the EXTRA context our calculation of the amount of data we
need to copy is incorrect, we only calculate the amount of data needed
within uc_mcontext.__reserved, not taking account of the fixed portion
of the context. Add in the offset of the reserved data so that we copy
everything we should.

This will only cause test failures in cases where the last context in the
EXTRA context is smaller than the missing data since we don't currently
validate any of the register data and all the buffers we copy into are
statically allocated so default to zero meaning that if we walk beyond the
end of what we copied we'll encounter what looks like a context with magic
and length both 0 which is a valid terminator record.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 tools/testing/selftests/arm64/signal/test_signals_utils.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.c b/tools/testing/selftests/arm64/signal/test_signals_utils.c
index 308e229e58ab..746a4f70f082 100644
--- a/tools/testing/selftests/arm64/signal/test_signals_utils.c
+++ b/tools/testing/selftests/arm64/signal/test_signals_utils.c
@@ -192,8 +192,10 @@ static bool handle_signal_copyctx(struct tdescr *td,
 		 * in the copy, this was previously validated in
 		 * ASSERT_GOOD_CONTEXT().
 		 */
-		to_copy = offset + sizeof(struct extra_context) + 16 +
-			extra->size;
+		to_copy = __builtin_offsetof(ucontext_t,
+					     uc_mcontext.__reserved);
+		to_copy += offset + sizeof(struct extra_context) + 16;
+		to_copy += extra->size;
 		copied_extra = (struct extra_context *)&(td->live_uc->uc_mcontext.__reserved[offset]);
 	} else {
 		copied_extra = NULL;

---
base-commit: b7bfaa761d760e72a969d116517eaa12e404c262
change-id: 20230201-arm64-kselftest-full-extra-164baae78412

Best regards,
-- 
Mark Brown <broonie@kernel.org>


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

* [PATCH] kselftest/arm64: Copy whole EXTRA context
@ 2023-02-02 17:30 ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2023-02-02 17:30 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Shuah Khan
  Cc: linux-arm-kernel, linux-kselftest, Mark Brown

When copying the EXTRA context our calculation of the amount of data we
need to copy is incorrect, we only calculate the amount of data needed
within uc_mcontext.__reserved, not taking account of the fixed portion
of the context. Add in the offset of the reserved data so that we copy
everything we should.

This will only cause test failures in cases where the last context in the
EXTRA context is smaller than the missing data since we don't currently
validate any of the register data and all the buffers we copy into are
statically allocated so default to zero meaning that if we walk beyond the
end of what we copied we'll encounter what looks like a context with magic
and length both 0 which is a valid terminator record.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 tools/testing/selftests/arm64/signal/test_signals_utils.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.c b/tools/testing/selftests/arm64/signal/test_signals_utils.c
index 308e229e58ab..746a4f70f082 100644
--- a/tools/testing/selftests/arm64/signal/test_signals_utils.c
+++ b/tools/testing/selftests/arm64/signal/test_signals_utils.c
@@ -192,8 +192,10 @@ static bool handle_signal_copyctx(struct tdescr *td,
 		 * in the copy, this was previously validated in
 		 * ASSERT_GOOD_CONTEXT().
 		 */
-		to_copy = offset + sizeof(struct extra_context) + 16 +
-			extra->size;
+		to_copy = __builtin_offsetof(ucontext_t,
+					     uc_mcontext.__reserved);
+		to_copy += offset + sizeof(struct extra_context) + 16;
+		to_copy += extra->size;
 		copied_extra = (struct extra_context *)&(td->live_uc->uc_mcontext.__reserved[offset]);
 	} else {
 		copied_extra = NULL;

---
base-commit: b7bfaa761d760e72a969d116517eaa12e404c262
change-id: 20230201-arm64-kselftest-full-extra-164baae78412

Best regards,
-- 
Mark Brown <broonie@kernel.org>


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

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

* Re: [PATCH] kselftest/arm64: Copy whole EXTRA context
  2023-02-02 17:30 ` Mark Brown
@ 2023-02-07 18:54   ` Catalin Marinas
  -1 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2023-02-07 18:54 UTC (permalink / raw)
  To: Will Deacon, Shuah Khan, Mark Brown; +Cc: linux-arm-kernel, linux-kselftest

On Thu, 02 Feb 2023 17:30:44 +0000, Mark Brown wrote:
> When copying the EXTRA context our calculation of the amount of data we
> need to copy is incorrect, we only calculate the amount of data needed
> within uc_mcontext.__reserved, not taking account of the fixed portion
> of the context. Add in the offset of the reserved data so that we copy
> everything we should.
> 
> This will only cause test failures in cases where the last context in the
> EXTRA context is smaller than the missing data since we don't currently
> validate any of the register data and all the buffers we copy into are
> statically allocated so default to zero meaning that if we walk beyond the
> end of what we copied we'll encounter what looks like a context with magic
> and length both 0 which is a valid terminator record.
> 
> [...]

Applied to arm64 (for-next/kselftest), thanks!

[1/1] kselftest/arm64: Copy whole EXTRA context
      https://git.kernel.org/arm64/c/6012b8202022

-- 
Catalin


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

* Re: [PATCH] kselftest/arm64: Copy whole EXTRA context
@ 2023-02-07 18:54   ` Catalin Marinas
  0 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2023-02-07 18:54 UTC (permalink / raw)
  To: Will Deacon, Shuah Khan, Mark Brown; +Cc: linux-arm-kernel, linux-kselftest

On Thu, 02 Feb 2023 17:30:44 +0000, Mark Brown wrote:
> When copying the EXTRA context our calculation of the amount of data we
> need to copy is incorrect, we only calculate the amount of data needed
> within uc_mcontext.__reserved, not taking account of the fixed portion
> of the context. Add in the offset of the reserved data so that we copy
> everything we should.
> 
> This will only cause test failures in cases where the last context in the
> EXTRA context is smaller than the missing data since we don't currently
> validate any of the register data and all the buffers we copy into are
> statically allocated so default to zero meaning that if we walk beyond the
> end of what we copied we'll encounter what looks like a context with magic
> and length both 0 which is a valid terminator record.
> 
> [...]

Applied to arm64 (for-next/kselftest), thanks!

[1/1] kselftest/arm64: Copy whole EXTRA context
      https://git.kernel.org/arm64/c/6012b8202022

-- 
Catalin


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

end of thread, other threads:[~2023-02-07 18:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 17:30 [PATCH] kselftest/arm64: Copy whole EXTRA context Mark Brown
2023-02-02 17:30 ` Mark Brown
2023-02-07 18:54 ` Catalin Marinas
2023-02-07 18:54   ` Catalin Marinas

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.