mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gregory Price <gourry.memverge@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: linux-doc@vger.kernel.org, linux-arch@vger.kernel.org,
	oleg@redhat.com, avagin@gmail.com, peterz@infradead.org,
	luto@kernel.org, krisman@collabora.com, tglx@linutronix.de,
	corbet@lwn.net, shuah@kernel.org, catalin.marinas@arm.com,
	arnd@arndb.de, Gregory Price <gregory.price@memverge.com>
Subject: [PATCH v16 2/4] syscall user dispatch: untag selector addresses before access_ok
Date: Fri,  7 Apr 2023 13:18:32 -0400	[thread overview]
Message-ID: <20230407171834.3558-3-gregory.price@memverge.com> (raw)
In-Reply-To: <20230407171834.3558-1-gregory.price@memverge.com>

This is a preparatory patch for enabling checkpoint/restart of tasks
utilizing syscall user dispatch via ptrace.

To support checkpoint/restart, ptrace must be able to set the selector
of the tracee.  The selector is a user pointer that may be subject to
memory tagging extensions on some architectures (namely ARM MTE).

access_ok will clear memory tags for tagged addresses on tasks where
memory tagging is enabled.  However, to allow ptrace to set a task's
selector when tracer and tracee are not both tagged or untagged,
the selector address must be untagged when calling access_ok.

Since access_ok utilizes current to determine whether or not to untag
an address, an untagged tracer will always fail to restore a tagged
address in a tagged tracee.  This patch will resolve this issue.

The result of this is that a tagged tracer may be capable of setting
an invalid address, which will cause the tracee to SIGSEGV on next
syscall.  This is equivalent to the tracee setting a bad selector
address (such as selector=0x1).  This is preferable to the alternative
of creating a task_access_ok variant, and is consistent with other
operations which change tracee pointers via ptrace.

For more information, see:
https://lore.kernel.org/all/ZCWXE04nLZ4pXEtM@arm.com/

Signed-off-by: Gregory Price <gregory.price@memverge.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 kernel/entry/syscall_user_dispatch.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/entry/syscall_user_dispatch.c b/kernel/entry/syscall_user_dispatch.c
index 22396b234854..424f24350f8b 100644
--- a/kernel/entry/syscall_user_dispatch.c
+++ b/kernel/entry/syscall_user_dispatch.c
@@ -87,7 +87,14 @@ static int task_set_syscall_user_dispatch(struct task_struct *task, unsigned lon
 		if (offset && offset + len <= offset)
 			return -EINVAL;
 
-		if (selector && !access_ok(selector, sizeof(*selector)))
+		/*
+		 * access_ok will clear memory tags for tagged addresses on tasks where
+		 * memory tagging is enabled.  To enable a tracer to set a tracee's
+		 * selector not in the same tagging state, the selector address must be
+		 * untagged for access_ok, otherwise an untagged tracer will always fail
+		 * to set a tagged tracee's selector.
+		 */
+		if (selector && !access_ok(untagged_addr(selector), sizeof(*selector)))
 			return -EFAULT;
 
 		break;
-- 
2.39.1


  parent reply	other threads:[~2023-04-07 17:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-07 17:18 [PATCH v16 0/4] Checkpoint Support for Syscall User Dispatch Gregory Price
2023-04-07 17:18 ` [PATCH v16 1/4] syscall_user_dispatch: helper function to operate on given task Gregory Price
2023-04-18  8:47   ` [tip: core/entry] syscall_user_dispatch: Split up set_syscall_user_dispatch() tip-bot2 for Gregory Price
2023-04-07 17:18 ` Gregory Price [this message]
2023-04-18  8:47   ` [tip: core/entry] syscall_user_dispatch: Untag selector address before access_ok() tip-bot2 for Gregory Price
2023-04-07 17:18 ` [PATCH v16 3/4] ptrace,syscall_user_dispatch: checkpoint/restore support for SUD Gregory Price
2023-04-18  8:47   ` [tip: core/entry] ptrace: Provide set/get interface for syscall user dispatch tip-bot2 for Gregory Price
2023-04-07 17:18 ` [PATCH v16 4/4] selftest,ptrace: Add selftest for syscall user dispatch config api Gregory Price
2023-04-18  8:47   ` [tip: core/entry] selftest, ptrace: " tip-bot2 for Gregory Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230407171834.3558-3-gregory.price@memverge.com \
    --to=gourry.memverge@gmail.com \
    --cc=arnd@arndb.de \
    --cc=avagin@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=corbet@lwn.net \
    --cc=gregory.price@memverge.com \
    --cc=krisman@collabora.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®