From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>,
Nicholas Piggin <npiggin@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
Kees Cook <keescook@chromium.org>,
Laura Abbott <labbott@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
Mark Rutland <mark.rutland@arm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Paul Mackerras <paulus@samba.org>
Subject: Re: [PATCH v2 1/2] powerpc: Fix virt_addr_valid() check
Date: Wed, 19 Jan 2022 09:15:55 +0800 [thread overview]
Message-ID: <8a24ef1d-1c93-416d-cfbe-e63aacfb25cc@huawei.com> (raw)
In-Reply-To: <ca351bfc-3507-11ad-73f1-79ca772b55fd@csgroup.eu>
On 2022/1/11 14:04, Christophe Leroy wrote:
>
> Le 11/01/2022 à 05:37, Nicholas Piggin a écrit :
>> Excerpts from Kefeng Wang's message of January 8, 2022 9:58 pm:
>>> Hi PPC maintainers, ping..
>> Hmm. I might have confused myself about this. I'm going back and
>> trying to work out what I was thinking when I suggested it. This
>> works on 64e because vmalloc space is below the kernel linear map,
>> right?
>>
>> On 64s it is the other way around and it is still possible to enable
>> flatmem on 64s. Altough we might just not hit the problem there because
>> __pa() will not mask away the vmalloc offset for 64s so it will still
>> return something that's outside the pfn_valid range for flatmem. That's
>> very subtle though.
> That's the way it works on PPC32 at least, so for me it's not chocking
> to have it work the same way on PPC64s.
>
> The main issue here is the way __pa() works. On PPC32 __pa = va -
> PAGE_OFFSET, so it works correctly for any address.
> On PPC64, __pa() works by masking out the 2 top bits instead of
> substracting PAGE_OFFSET, so the test must add a verification that we
> really have the 2 top bits set at first. This is what (addr >=
> PAGE_OFFSET) does. Once this first test is done, we can perfectly rely
> on pfn_valid() just like PPC32, I see absolutely no point in an
> additionnal test checking the addr is below KERN_VIRT_START.
Hi Christophe and Nicholas, for ppc32, I think we need check the upper
limit,
eg, addr >= PAGE_OFFSET && addr < high_memory
arch/powerpc/mm/mem.c: high_memory = (void *) __va(max_low_pfn *
PAGE_SIZE);
for ppc32 max_low_pfn is the upper low memory pfn, and For ppc64,
high_memory is
the max memory pfn, it looks good too, correct me if I'm wrong, if the
above check
is ok, I will send a new v3, thanks.
>
>
>> The checks added to __pa actually don't prevent vmalloc memory from
>> being passed to it either on 64s, only a more basic test.
> That's correct. It is the role of pfn_valid() to check that.
>
> Christophe
>
>> I think 64s wants (addr >= PAGE_OFFSET && addr < KERN_VIRT_START) as
>> the condition. Could possibly add that check to __pa as well to
>> catch vmalloc addresses.
>>
>> Thanks,
>> Nick
>>
>>
next prev parent reply other threads:[~2022-01-19 1:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-25 12:06 [PATCH v2 0/2] mm: Fix kernel BUG in __check_heap_object() on PowerPC64 Kefeng Wang
2021-12-25 12:06 ` [PATCH v2 1/2] powerpc: Fix virt_addr_valid() check Kefeng Wang
2022-01-08 11:58 ` Kefeng Wang
2022-01-11 4:37 ` Nicholas Piggin
2022-01-11 6:04 ` Christophe Leroy
2022-01-19 1:15 ` Kefeng Wang [this message]
2022-01-20 7:31 ` Christophe Leroy
2022-01-20 11:09 ` Kefeng Wang
2022-01-10 8:01 ` Christophe Leroy
2021-12-25 12:06 ` [PATCH v2 2/2] mm: usercopy: Warn vmalloc/module address in check_heap_object() Kefeng Wang
2021-12-26 17:33 ` Christophe Leroy
2021-12-28 4:51 ` Kefeng Wang
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=8a24ef1d-1c93-416d-cfbe-e63aacfb25cc@huawei.com \
--to=wangkefeng.wang@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=christophe.leroy@csgroup.eu \
--cc=keescook@chromium.org \
--cc=labbott@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mark.rutland@arm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=paulus@samba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).