From: Mark Rutland <mark.rutland@arm.com>
To: Lukas Wunner <lukas@wunner.de>
Cc: Ard Biesheuvel <ardb@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
Zorro Lang <zlang@redhat.com>,
Vegard Nossum <vegard.nossum@oracle.com>,
Joey Gouly <joey.gouly@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH for-next/fixes] arm64/mm: Fix false-positive !virt_addr_valid() for kernel image
Date: Mon, 25 Nov 2024 15:18:57 +0000 [thread overview]
Message-ID: <Z0SVYSew0gIgSdAe@J2N7QTR9R3> (raw)
In-Reply-To: <Z0SOZhtJohCNxX6_@wunner.de>
On Mon, Nov 25, 2024 at 03:49:10PM +0100, Lukas Wunner wrote:
> On Mon, Nov 25, 2024 at 10:50:48AM +0000, Mark Rutland wrote:
> > On Mon, Nov 25, 2024 at 10:54:49AM +0100, Lukas Wunner wrote:
> > > Other arches do not seem to be concerned about this and
> > > let virt_addr_valid() return true for the kernel image.
> > > It's not clear why arm64 is special and needs to return false.
> > >
> > > However, I agree there's hardly ever a reason to DMA from/to the
> > > .text section. From a security perspective, constraining this to
> > > .rodata seems reasonable to me and I'll be happy to amend the patch
> > > to that effect if that's the consensus.
> >
> > Instead, can we update the test to use lm_alias() on the symbols in
> > question? That'll convert a kernel image address to its linear map
> > alias, and then that'll work with virt_addr_valid(), virt_to_phys(),
> > etc.
>
> Do you mean that sg_set_buf() should pass the address to lm_alias()
> if it points into the kernel image?
No; I meant that the test could use lm_alias() on the test vectors
before passing those to sg_set_buf(), when the test code knows by
construction that those vectors happen to be part of the kernel image.
That'll work on all architectures.
That said, looking at the code it appears that testmgr.c can be built as
a module, so the test vectors could be module/vmalloc addresses rather
than virt/linear or image addresses. Given that, I don't think the
changes suggested here are sufficient, as module addresses should still
be rejected.
Can we kmemdup() the test vector data first? That'd give us a legitimate
virt/linear address that we can use.
> That would require a helper to determine whether it's a kernel image
> address or not. It seems we do not have such a cross-architecture
> helper (but maybe I'm missing something). (I am adding an arm64-specific
> one in the proposed patch.)
>
> So this doesn't look like a viable approach.
>
> Also, I'd expect pushback against an sg_set_buf() change which is
> only necessary to accommodate arm64. I'd expect the obvious question
> to be asked, which is why arm64's virt_addr_valid() can't behave like
> any other architecture's. And honestly I wouldn't know what to answer.
I don't think arm64 is doing anything wrong here; an image address is
*not* a virt/linear address, and we only fix that up in virt_to_*() as a
best-effort thing. I think other architectures which accept that are
signing themselves up for subtle bugs that we're trying to prevent
early.
Mark.
prev parent reply other threads:[~2024-11-25 15:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-24 16:15 [PATCH for-next/fixes] arm64/mm: Fix false-positive !virt_addr_valid() for kernel image Lukas Wunner
2024-11-24 16:38 ` Ard Biesheuvel
2024-11-24 17:13 ` Ard Biesheuvel
[not found] ` <Z0RJaU4wjU5WeQb4@wunner.de>
2024-11-25 10:50 ` Mark Rutland
[not found] ` <Z0SOZhtJohCNxX6_@wunner.de>
2024-11-25 15:18 ` Mark Rutland [this message]
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=Z0SVYSew0gIgSdAe@J2N7QTR9R3 \
--to=mark.rutland@arm.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=herbert@gondor.apana.org.au \
--cc=joey.gouly@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=vegard.nossum@oracle.com \
--cc=will@kernel.org \
--cc=zlang@redhat.com \
/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