mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Maciej Wieczor-Retman <m.wieczorretman@pm.me>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
	Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
	linux-kernel@vger.kernel.org,
	"Kirill A. Shutemov" <kirill@shutemov.name>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>
Subject: Re: [PATCH v10 09/13] x86/mm: Reset tags in a canonical address helper call
Date: Thu, 26 Feb 2026 11:39:02 -0800	[thread overview]
Message-ID: <e7dd9c32-d90d-4b90-900d-e3590eb10493@intel.com> (raw)
In-Reply-To: <aZ1mSCFt09yefkW4@wieczorr-mobl1.localdomain>

On 2/24/26 00:57, Maciej Wieczor-Retman wrote:
> On 2026-02-23 at 12:39:22 -0800, Dave Hansen wrote:
>> On 2/4/26 11:20, Maciej Wieczor-Retman wrote:
>>> -	return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
>>> +	return __is_canonical_address(__tag_reset(vaddr), boot_cpu_data.x86_virt_bits);
>>>  }
>> I think we should just do this in __canonical_address() itself instead
>> of changing its callers. There are a whole host of ways to get in there.
> Cc: Sean Christopherson <seanjc@google.com>
> 
> I tried doing that before and Sean said it'd be wrong from KVM perspective [1].
> Not sure if there is some other way to do it so that it makes sense in KVM?

Looking at this some more, I think it's fine to leave
__is_canonical_address() alone. There are several kinds of canonical
checks and __is_canonical_address() should help with all of them.

That said, this patch is still buggy. copy_from_kernel_nofault_allowed()
does:

        if (is_vsyscall_vaddr(vaddr))
                return false;

which is a plain equality check:

	static inline bool is_vsyscall_vaddr(unsigned long vaddr)
	{
	        return unlikely((vaddr & PAGE_MASK) == VSYSCALL_ADDR);
	}

So a tagged 'vaddr' is not going to ever be is_vsyscall_vaddr(). The
untagging needs to happen before this check. Further, I do wonder if we
want checks in things like is_vsyscall_vaddr() for tagged addresses. If
they get into there, it's always a bug I think.

Aside: I think copy_from_kernel_nofault_allowed() is buggy. It's using
'boot_cpu_data.x86_virt_bits' which I think is the "CPU canonical" bits,
not the "paging canonical" bits. So a 5-level hardware system running in
4-level mode can pass non-paging-canonical address through
copy_from_kernel_nofault_allowed(). So I think the
'boot_cpu_data.x86_virt_bits' use in here became a buglet when
5-level-paging got enabled.

In a perfect world, we'd stop using EX_TYPE_UACCESS for kernel accesses.
But the uaccess.h macros are enough of a mess that  I understand why
nobody wanted to plumb a new exception type into them and wanted to
reuse them as-is.

  reply	other threads:[~2026-02-26 19:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-04 19:18 [PATCH v10 00/13] kasan: x86: arm64: KASAN tag-based mode for x86 Maciej Wieczor-Retman
2026-02-04 19:19 ` [PATCH v10 01/13] kasan: sw_tags: Use arithmetic shift for shadow computation Maciej Wieczor-Retman
2026-03-05 19:05   ` Andrey Ryabinin
2026-03-05 20:18     ` Maciej Wieczor-Retman
2026-03-05 21:22       ` Andrey Ryabinin
2026-03-05 21:25         ` Maciej Wieczor-Retman
2026-02-04 19:19 ` [PATCH v10 02/13] kasan: arm64: x86: Make special tags arch specific Maciej Wieczor-Retman
2026-02-04 19:19 ` [PATCH v10 03/13] kasan: Fix inline mode for x86 tag-based mode Maciej Wieczor-Retman
2026-02-04 19:19 ` [PATCH v10 04/13] x86/kasan: Add arch specific kasan functions Maciej Wieczor-Retman
2026-02-04 19:19 ` [PATCH v10 05/13] x86/mm: Reset tag for virtual to physical address conversions Maciej Wieczor-Retman
2026-02-04 19:20 ` [PATCH v10 06/13] mm/execmem: Untag addresses in EXECMEM_ROX related pointer arithmetic Maciej Wieczor-Retman
2026-02-04 19:20 ` [PATCH v10 07/13] x86/mm: Use physical address comparisons in fill_p*d/pte Maciej Wieczor-Retman
2026-02-23 20:36   ` Dave Hansen
2026-02-04 19:20 ` [PATCH v10 08/13] x86/kasan: Initialize KASAN raw shadow memory Maciej Wieczor-Retman
2026-02-04 19:20 ` [PATCH v10 09/13] x86/mm: Reset tags in a canonical address helper call Maciej Wieczor-Retman
2026-02-23 20:39   ` Dave Hansen
2026-02-24  8:57     ` Maciej Wieczor-Retman
2026-02-26 19:39       ` Dave Hansen [this message]
2026-02-27  8:24         ` Maciej Wieczor-Retman
2026-02-04 19:20 ` [PATCH v10 10/13] x86/mm: Initialize LAM_SUP Maciej Wieczor-Retman
2026-02-23 20:43   ` Dave Hansen
2026-02-24  9:05     ` Maciej Wieczor-Retman
2026-02-04 19:20 ` [PATCH v10 11/13] x86: Increase minimal SLAB alignment for KASAN Maciej Wieczor-Retman
2026-02-04 19:20 ` [PATCH v10 12/13] x86/kasan: Use a logical bit shift for kasan_mem_to_shadow Maciej Wieczor-Retman
2026-02-04 19:20 ` [PATCH v10 13/13] x86/kasan: Make software tag-based kasan available Maciej Wieczor-Retman
2026-02-23 20:52   ` Dave Hansen
2026-02-24  9:10     ` Maciej Wieczor-Retman
2026-02-26 23:29       ` Dave Hansen
2026-02-27  8:27         ` Maciej Wieczor-Retman

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=e7dd9c32-d90d-4b90-900d-e3590eb10493@intel.com \
    --to=dave.hansen@intel.com \
    --cc=ast@kernel.org \
    --cc=bp@alien8.de \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=m.wieczorretman@pm.me \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@kernel.org \
    --cc=x86@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 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®