From: Gregory Price <gregory.price@memverge.com>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Gregory Price <gourry.memverge@gmail.com>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
linux-arm-kernel@lists.infradead.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, arnd@arndb.de, will@kernel.org,
mark.rutland@arm.com, tongtiangen@huawei.com,
robin.murphy@arm.com
Subject: Re: [PATCH v14 1/4] asm-generic,arm64: create task variant of access_ok
Date: Thu, 30 Mar 2023 00:18:36 -0400 [thread overview]
Message-ID: <ZCUNnBsVA0A+PgPT@memverge.com> (raw)
In-Reply-To: <ZCWXE04nLZ4pXEtM@arm.com>
On Thu, Mar 30, 2023 at 03:05:07PM +0100, Catalin Marinas wrote:
>
> Ah, thanks for the pointer.
>
> For ptrace(), we live with this relaxation as there's no easy way to
> check. Take __access_remote_vm() for example, it ends up in
> get_user_pages_remote() -> ... -> __get_user_pages() which just untags
> the address. Even if it would want to do this conditionally, the tag
> pointer is enabled per thread (and inherited) but the GUP API only takes
> the mm.
>
> While we could improve it as ptrace() can tell which thread it is
> tracing, I don't think it's worth the effort. On arm64, top-byte-ignore
> was enabled from the start for in-user accesses but not at the syscall
> level. We wanted to avoid breaking some use-cases with untagging all
> user pointers, hence the explicit opt-in to catch some issues (glibc did
> have a problem with brk() ignoring the top byte -
> https://bugzilla.redhat.com/show_bug.cgi?id=1797052).
>
> So yeah, this access_ok() in a few places is a best effort to catch some
> potential ABI regressions like the one above and also as a way to force
> the old ABI (mostly) via sysctl. But we do have places like GUP where we
> don't have the thread information (only the mm), so we just
> indiscriminately untag the pointer.
>
> Note that there is no security risk for the access itself. The Arm
> architecture selects the user vs kernel address spaces based on bit 55
> rather than 63. Untagging a pointer sign-extends bit 55.
>
> > I did not have a sufficient answer for this so I went down this path.
> >
> > It does seem simpler to simply untag the address, however it didn't seem
> > like a good solution to simply leave an identified bad edge case.
> >
> > with access_ok(untagged_addr(addr), ...) it breaks down like this:
> >
> > (tracer,tracee) : result
> >
> > tag,tag : untagged - (correct)
> > tag,untag : untagged - incorrect as this would have been an impossible
> > state to reach through the standard prctl interface. Will
> > lead to a SIGSEGV in the tracee upon next syscall
>
> Well, even without untagging the pointer, the tracer can set a random
> address that passes access_ok() but still faults in the tracee. It's the
> tracer that should ensure the pointer is valid in the context of the
> tracee.
>
> Now, even if the selector pointer is tagged, the accesses still work
> fine (top-byte-ignore) unless MTE is enabled in the tracee and the tag
> should match the region's colour. But, again, that's no different from a
> debugger changing pointer variables in the debugged process, they should
> be valid and it's not for the kernel to sanitise them.
>
> > untag,tag : untagged - (correct)
> > untag,untag : no-op - (correct), tagged address will fail to set
> >
> > Basically if the tracer is a tagged process while the tracee is not, it
> > would become possible to set the tracee's selector to a tagged pointer.
>
> Yes, but does it matter? You'd trust the tracer to work correctly. There
> are multiple ways it can break the tracee here even if access_ok()
> worked as intended.
>
> > It's beyond me to say whether or not this situation is "ok" and "the
> > user's fault", but it does feel like an addressable problem.
>
> To me, the situation looks fine. While it's addressable, we have other
> places where the tag is ignored on the ptrace() path, so I don't think
> it's worth the effort.
>
> --
> Catalin
Thank you for the extensive breakdown. Given this, it seems like I
should just revert to untagging the pointer and drop the access_ok
extensions.
I'll add a comment at the untag site that discusses this interaction.
Thanks!
Gregory
WARNING: multiple messages have this Message-ID (diff)
From: Gregory Price <gregory.price@memverge.com>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Gregory Price <gourry.memverge@gmail.com>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
linux-arm-kernel@lists.infradead.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, arnd@arndb.de, will@kernel.org,
mark.rutland@arm.com, tongtiangen@huawei.com,
robin.murphy@arm.com
Subject: Re: [PATCH v14 1/4] asm-generic,arm64: create task variant of access_ok
Date: Thu, 30 Mar 2023 00:18:36 -0400 [thread overview]
Message-ID: <ZCUNnBsVA0A+PgPT@memverge.com> (raw)
In-Reply-To: <ZCWXE04nLZ4pXEtM@arm.com>
On Thu, Mar 30, 2023 at 03:05:07PM +0100, Catalin Marinas wrote:
>
> Ah, thanks for the pointer.
>
> For ptrace(), we live with this relaxation as there's no easy way to
> check. Take __access_remote_vm() for example, it ends up in
> get_user_pages_remote() -> ... -> __get_user_pages() which just untags
> the address. Even if it would want to do this conditionally, the tag
> pointer is enabled per thread (and inherited) but the GUP API only takes
> the mm.
>
> While we could improve it as ptrace() can tell which thread it is
> tracing, I don't think it's worth the effort. On arm64, top-byte-ignore
> was enabled from the start for in-user accesses but not at the syscall
> level. We wanted to avoid breaking some use-cases with untagging all
> user pointers, hence the explicit opt-in to catch some issues (glibc did
> have a problem with brk() ignoring the top byte -
> https://bugzilla.redhat.com/show_bug.cgi?id=1797052).
>
> So yeah, this access_ok() in a few places is a best effort to catch some
> potential ABI regressions like the one above and also as a way to force
> the old ABI (mostly) via sysctl. But we do have places like GUP where we
> don't have the thread information (only the mm), so we just
> indiscriminately untag the pointer.
>
> Note that there is no security risk for the access itself. The Arm
> architecture selects the user vs kernel address spaces based on bit 55
> rather than 63. Untagging a pointer sign-extends bit 55.
>
> > I did not have a sufficient answer for this so I went down this path.
> >
> > It does seem simpler to simply untag the address, however it didn't seem
> > like a good solution to simply leave an identified bad edge case.
> >
> > with access_ok(untagged_addr(addr), ...) it breaks down like this:
> >
> > (tracer,tracee) : result
> >
> > tag,tag : untagged - (correct)
> > tag,untag : untagged - incorrect as this would have been an impossible
> > state to reach through the standard prctl interface. Will
> > lead to a SIGSEGV in the tracee upon next syscall
>
> Well, even without untagging the pointer, the tracer can set a random
> address that passes access_ok() but still faults in the tracee. It's the
> tracer that should ensure the pointer is valid in the context of the
> tracee.
>
> Now, even if the selector pointer is tagged, the accesses still work
> fine (top-byte-ignore) unless MTE is enabled in the tracee and the tag
> should match the region's colour. But, again, that's no different from a
> debugger changing pointer variables in the debugged process, they should
> be valid and it's not for the kernel to sanitise them.
>
> > untag,tag : untagged - (correct)
> > untag,untag : no-op - (correct), tagged address will fail to set
> >
> > Basically if the tracer is a tagged process while the tracee is not, it
> > would become possible to set the tracee's selector to a tagged pointer.
>
> Yes, but does it matter? You'd trust the tracer to work correctly. There
> are multiple ways it can break the tracee here even if access_ok()
> worked as intended.
>
> > It's beyond me to say whether or not this situation is "ok" and "the
> > user's fault", but it does feel like an addressable problem.
>
> To me, the situation looks fine. While it's addressable, we have other
> places where the tag is ignored on the ptrace() path, so I don't think
> it's worth the effort.
>
> --
> Catalin
Thank you for the extensive breakdown. Given this, it seems like I
should just revert to untagging the pointer and drop the access_ok
extensions.
I'll add a comment at the untag site that discusses this interaction.
Thanks!
Gregory
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-03-30 14:43 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 16:48 [PATCH v14 0/4] Checkpoint Support for Syscall User Dispatch Gregory Price
2023-03-28 16:48 ` Gregory Price
2023-03-28 16:48 ` [PATCH v14 1/4] asm-generic,arm64: create task variant of access_ok Gregory Price
2023-03-28 16:48 ` Gregory Price
2023-03-28 18:46 ` Arnd Bergmann
2023-03-28 18:46 ` Arnd Bergmann
2023-03-29 15:15 ` Oleg Nesterov
2023-03-29 15:15 ` Oleg Nesterov
2023-03-29 15:41 ` Arnd Bergmann
2023-03-29 15:41 ` Arnd Bergmann
2023-03-29 16:03 ` Oleg Nesterov
2023-03-29 16:03 ` Oleg Nesterov
2023-03-29 3:56 ` Gregory Price
2023-03-29 3:56 ` Gregory Price
2023-03-29 17:13 ` Oleg Nesterov
2023-03-29 17:13 ` Oleg Nesterov
2023-03-29 5:37 ` Gregory Price
2023-03-29 5:37 ` Gregory Price
2023-03-29 17:58 ` Oleg Nesterov
2023-03-29 17:58 ` Oleg Nesterov
2023-03-29 5:54 ` Gregory Price
2023-03-29 5:54 ` Gregory Price
2023-03-29 18:13 ` Oleg Nesterov
2023-03-29 18:13 ` Oleg Nesterov
2023-03-29 10:02 ` Gregory Price
2023-03-29 10:02 ` Gregory Price
2023-03-29 23:54 ` Oleg Nesterov
2023-03-29 23:54 ` Oleg Nesterov
2023-03-29 18:29 ` Arnd Bergmann
2023-03-29 18:29 ` Arnd Bergmann
2023-03-29 16:22 ` Catalin Marinas
2023-03-29 16:22 ` Catalin Marinas
2023-03-29 4:34 ` Gregory Price
2023-03-29 4:34 ` Gregory Price
2023-03-30 14:05 ` Catalin Marinas
2023-03-30 14:05 ` Catalin Marinas
2023-03-30 4:18 ` Gregory Price [this message]
2023-03-30 4:18 ` Gregory Price
2023-03-28 16:48 ` [PATCH v14 2/4] syscall_user_dispatch: helper function to operate on given task Gregory Price
2023-03-28 16:48 ` Gregory Price
2023-03-28 16:48 ` [PATCH v14 3/4] ptrace,syscall_user_dispatch: checkpoint/restore support for SUD Gregory Price
2023-03-28 16:48 ` Gregory Price
2023-03-28 16:48 ` [PATCH v14 4/4] selftest,ptrace: Add selftest for syscall user dispatch config api Gregory Price
2023-03-28 16:48 ` 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=ZCUNnBsVA0A+PgPT@memverge.com \
--to=gregory.price@memverge.com \
--cc=arnd@arndb.de \
--cc=avagin@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=gourry.memverge@gmail.com \
--cc=krisman@collabora.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mark.rutland@arm.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=robin.murphy@arm.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=tongtiangen@huawei.com \
--cc=will@kernel.org \
/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 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.