[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <kf7vx6xgyh3o72qy5uade5lxc2htwsr5yucs7yclm5atcrwppp@lvfqi7tupefn>
Date: Wed, 9 Apr 2025 09:16:44 +0200
From: Maciej Wieczor-Retman <maciej.wieczor-retman@...el.com>
To: Dave Hansen <dave.hansen@...el.com>
CC: <hpa@...or.com>, <hch@...radead.org>, <nick.desaulniers+lkml@...il.com>,
<kuan-ying.lee@...onical.com>, <masahiroy@...nel.org>,
<samuel.holland@...ive.com>, <mingo@...hat.com>, <corbet@....net>,
<ryabinin.a.a@...il.com>, <guoweikang.kernel@...il.com>,
<jpoimboe@...nel.org>, <ardb@...nel.org>, <vincenzo.frascino@....com>,
<glider@...gle.com>, <kirill.shutemov@...ux.intel.com>, <apopple@...dia.com>,
<samitolvanen@...gle.com>, <kaleshsingh@...gle.com>, <jgross@...e.com>,
<andreyknvl@...il.com>, <scott@...amperecomputing.com>,
<tony.luck@...el.com>, <dvyukov@...gle.com>, <pasha.tatashin@...een.com>,
<ziy@...dia.com>, <broonie@...nel.org>, <gatlin.newhouse@...il.com>,
<jackmanb@...gle.com>, <wangkefeng.wang@...wei.com>,
<thiago.bauermann@...aro.org>, <tglx@...utronix.de>, <kees@...nel.org>,
<akpm@...ux-foundation.org>, <jason.andryuk@....com>, <snovitoll@...il.com>,
<xin@...or.com>, <jan.kiszka@...mens.com>, <bp@...en8.de>, <rppt@...nel.org>,
<peterz@...radead.org>, <pankaj.gupta@....com>, <thuth@...hat.com>,
<andriy.shevchenko@...ux.intel.com>, <joel.granados@...nel.org>,
<kbingham@...nel.org>, <nicolas@...sle.eu>, <mark.rutland@....com>,
<surenb@...gle.com>, <catalin.marinas@....com>, <morbo@...gle.com>,
<justinstitt@...gle.com>, <ubizjak@...il.com>, <jhubbard@...dia.com>,
<urezki@...il.com>, <dave.hansen@...ux.intel.com>, <bhe@...hat.com>,
<luto@...nel.org>, <baohua@...nel.org>, <nathan@...nel.org>,
<will@...nel.org>, <brgerst@...il.com>, <llvm@...ts.linux.dev>,
<linux-mm@...ck.org>, <linux-doc@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>, <linux-kbuild@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <kasan-dev@...glegroups.com>,
<x86@...nel.org>
Subject: Re: [PATCH v3 03/14] x86: Add arch specific kasan functions
On 2025-04-04 at 09:06:51 -0700, Dave Hansen wrote:
>On 4/4/25 06:14, Maciej Wieczor-Retman wrote:
>> +static inline const void *__tag_set(const void *addr, u8 tag)
>> +{
>> + u64 __addr = (u64)addr & ~__tag_shifted(KASAN_TAG_KERNEL);
>> + return (const void *)(__addr | __tag_shifted(tag));
>> +}
>
>This becomes a lot clearer to read if you separate out the casting from
>the logical bit manipulation. For instance:
>
>static inline const void *__tag_set(const void *__addr, u8 tag)
>{
> u64 addr = (u64)__addr;
>
> addr &= ~__tag_shifted(KASAN_TAG_KERNEL);
> addr |= __tag_shifted(tag);
>
> return (const void *)addr;
>}
>
>Also, unless there's a good reason for it, you might as well limit the
>places you need to use "__".
Thanks, the above looks better :)
>
>Now that we can read this, I think it's potentially buggy. If someone
>went and changed:
>
>#define KASAN_TAG_KERNEL 0xFF
>
>to, say:
>
>#define KASAN_TAG_KERNEL 0xAB
>zo
>the '&' would miss clearing bits. It works fine in the arm64 implementation:
>
> u64 __addr = (u64)addr & ~__tag_shifted(0xff);
>
>because they've hard-coded 0xff. I _think_ that's what you actually want
>here. You don't want to mask out KASAN_TAG_KERNEL, you actually want to
>mask out *ANYTHING* in those bits.
>
>So the best thing is probably to define a KASAN_TAG_MASK that makes it
>clear which are the tag bits.
Okay, that makes more sense. KASAN_TAG_MASK already exist ((1 << TAG_WIDTH) - 1)
in include/linux/mmzone.h. I'll move it to include/linux/kasan-tags.h so it can
be included.
--
Kind regards
Maciej Wieczór-Retman
Powered by blists - more mailing lists