Skip to content

Commit 1d65408

Browse files
mrutland-armOpenEmbedded
authored andcommitted
arm64: ptrace: fix partial SETREGSET for NT_ARM_TAGGED_ADDR_CTRL
commit ca62d90 upstream. Currently tagged_addr_ctrl_set() doesn't initialize the temporary 'ctrl' variable, and a SETREGSET call with a length of zero will leave this uninitialized. Consequently tagged_addr_ctrl_set() will consume an arbitrary value, potentially leaking up to 64 bits of memory from the kernel stack. The read is limited to a specific slot on the stack, and the issue does not provide a write mechanism. As set_tagged_addr_ctrl() only accepts values where bits [63:4] zero and rejects other values, a partial SETREGSET attempt will randomly succeed or fail depending on the value of the uninitialized value, and the exposure is significantly limited. Fix this by initializing the temporary value before copying the regset from userspace, as for other regsets (e.g. NT_PRSTATUS, NT_PRFPREG, NT_ARM_SYSTEM_CALL). In the case of a zero-length write, the existing value of the tagged address ctrl will be retained. The NT_ARM_TAGGED_ADDR_CTRL regset is only visible in the user_aarch64_view used by a native AArch64 task to manipulate another native AArch64 task. As get_tagged_addr_ctrl() only returns an error value when called for a compat task, tagged_addr_ctrl_get() and tagged_addr_ctrl_set() should never observe an error value from get_tagged_addr_ctrl(). Add a WARN_ON_ONCE() to both to indicate that such an error would be unexpected, and error handlnig is not missing in either case. Fixes: 2200aa7 ("arm64: mte: ptrace: Add NT_ARM_TAGGED_ADDR_CTRL regset") Cc: <[email protected]> # 5.10.x Signed-off-by: Mark Rutland <[email protected]> Cc: Will Deacon <[email protected]> Reviewed-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6036bcc commit 1d65408

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/arm64/kernel/ptrace.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ static int tagged_addr_ctrl_get(struct task_struct *target,
13871387
{
13881388
long ctrl = get_tagged_addr_ctrl(target);
13891389

1390-
if (IS_ERR_VALUE(ctrl))
1390+
if (WARN_ON_ONCE(IS_ERR_VALUE(ctrl)))
13911391
return ctrl;
13921392

13931393
return membuf_write(&to, &ctrl, sizeof(ctrl));
@@ -1401,6 +1401,10 @@ static int tagged_addr_ctrl_set(struct task_struct *target, const struct
14011401
int ret;
14021402
long ctrl;
14031403

1404+
ctrl = get_tagged_addr_ctrl(target);
1405+
if (WARN_ON_ONCE(IS_ERR_VALUE(ctrl)))
1406+
return ctrl;
1407+
14041408
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ctrl, 0, -1);
14051409
if (ret)
14061410
return ret;

0 commit comments

Comments
 (0)