lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <44d4cf82-982c-455b-85c1-138e8c37cc8f@kylinos.cn>
Date: Mon, 22 Dec 2025 17:37:19 +0800
From: Enze Li <lienze@...inos.cn>
To: yuanlinyu <yuanlinyu@...or.com>, Huacai Chen <chenhuacai@...nel.org>
Cc: Alexander Potapenko <glider@...gle.com>, Marco Elver <elver@...gle.com>,
 Dmitry Vyukov <dvyukov@...gle.com>, Andrew Morton
 <akpm@...ux-foundation.org>, WANG Xuerui <kernel@...0n.name>,
 "kasan-dev@...glegroups.com" <kasan-dev@...glegroups.com>,
 "linux-mm@...ck.org" <linux-mm@...ck.org>,
 "loongarch@...ts.linux.dev" <loongarch@...ts.linux.dev>,
 "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
 "enze.li@....com" <enze.li@....com>
Subject: Re: [PATCH v2 1/2] LoongArch: kfence: avoid use
 CONFIG_KFENCE_NUM_OBJECTS

On 12/22/25 5:16 PM, yuanlinyu wrote:
>> From: Enze Li <lienze@...inos.cn>
>> Sent: Saturday, December 20, 2025 1:44 PM
>> To: Huacai Chen <chenhuacai@...nel.org>; yuanlinyu <yuanlinyu@...or.com>
>> Cc: Alexander Potapenko <glider@...gle.com>; Marco Elver
>> <elver@...gle.com>; Dmitry Vyukov <dvyukov@...gle.com>; Andrew Morton
>> <akpm@...ux-foundation.org>; WANG Xuerui <kernel@...0n.name>;
>> kasan-dev@...glegroups.com; linux-mm@...ck.org; loongarch@...ts.linux.dev;
>> linux-kernel@...r.kernel.org; enze.li@....com
>> Subject: Re: [PATCH v2 1/2] LoongArch: kfence: avoid use
>> CONFIG_KFENCE_NUM_OBJECTS
>>
>> On 2025/12/19 10:13, Huacai Chen wrote:
>>> Hi, Enze,
>>>
>>> On Thu, Dec 18, 2025 at 2:39 PM yuan linyu <yuanlinyu@...or.com> wrote:
>>>>
>>>> use common kfence macro KFENCE_POOL_SIZE for KFENCE_AREA_SIZE
>>>> definition
>>>>
>>>> Signed-off-by: yuan linyu <yuanlinyu@...or.com>
>>>> ---
>>>>  arch/loongarch/include/asm/pgtable.h | 3 ++-
>>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/arch/loongarch/include/asm/pgtable.h
>>>> b/arch/loongarch/include/asm/pgtable.h
>>>> index f41a648a3d9e..e9966c9f844f 100644
>>>> --- a/arch/loongarch/include/asm/pgtable.h
>>>> +++ b/arch/loongarch/include/asm/pgtable.h
>>>> @@ -10,6 +10,7 @@
>>>>  #define _ASM_PGTABLE_H
>>>>
>>>>  #include <linux/compiler.h>
>>>> +#include <linux/kfence.h>
>>>>  #include <asm/addrspace.h>
>>>>  #include <asm/asm.h>
>>>>  #include <asm/page.h>
>>>> @@ -96,7 +97,7 @@ extern unsigned long empty_zero_page[PAGE_SIZE /
>> sizeof(unsigned long)];
>>>>  #define MODULES_END    (MODULES_VADDR + SZ_256M)
>>>>
>>>>  #ifdef CONFIG_KFENCE
>>>> -#define KFENCE_AREA_SIZE       (((CONFIG_KFENCE_NUM_OBJECTS + 1)
>> * 2 + 2) * PAGE_SIZE)
>>>> +#define KFENCE_AREA_SIZE       (KFENCE_POOL_SIZE + (2 *
>> PAGE_SIZE))
>>> Can you remember why you didn't use KFENCE_POOL_SIZE at the first place?
>>
>> I don't recall the exact reason off the top of my head, but I believe it was due to
>> complex dependency issues with the header files where KFENCE_POOL_SIZE is
>> defined.  To avoid those complications, we likely opted to use
>> KFENCE_NUM_OBJECTS directly.
>>
>> I checked out the code at commit
>> (6ad3df56bb199134800933df2afcd7df3b03ef33 "LoongArch: Add KFENCE
>> (Kernel
>> Electric-Fence) support") and encountered the following errors when compiling
>> with this patch applied.
>>
>> 8<------------------------------------------------------
>>   CC      arch/loongarch/kernel/asm-offsets.s
>> In file included from ./arch/loongarch/include/asm/pgtable.h:13,
>>                  from ./include/linux/pgtable.h:6,
>>                  from ./include/linux/mm.h:29,
>>                  from arch/loongarch/kernel/asm-offsets.c:9:
>> ./include/linux/kfence.h:93:35: warning: 'struct kmem_cache' declared inside
>> parameter list will n ot be visible outside of this definition or declaration
>>    93 | void kfence_shutdown_cache(struct kmem_cache *s);
>>       |                                   ^~~~~~~~~~
>> ./include/linux/kfence.h:99:29: warning: 'struct kmem_cache' declared inside
>> parameter list will n ot be visible outside of this definition or declaration
>>    99 | void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags);
>>       |                             ^~~~~~~~~~
>> ./include/linux/kfence.h:117:50: warning: 'struct kmem_cache' declared inside
>> parameter list will not be visible outside of this definition or declaration
>>   117 | static __always_inline void *kfence_alloc(struct kmem_cache *s, size_t
>> size, gfp_t flags)
>>       |
>> ^~~~~~~~~~
>> ./include/linux/kfence.h: In function 'kfence_alloc':
>> ./include/linux/kfence.h:128:31: error: passing argument 1 of '__kfence_alloc'
>> from incompatible p ointer type [-Wincompatible-pointer-types]
>>   128 |         return __kfence_alloc(s, size, flags);
>>       |                               ^
>>       |                               |
>>       |                               struct kmem_cache *
>> ./include/linux/kfence.h:99:41: note: expected 'struct kmem_cache *' but
>> argument is of type 'stru ct kmem_cache *'
>>    99 | void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags);
>>       |                      ~~~~~~~~~~~~~~~~~~~^
>> ------------------------------------------------------>8
>>
>> Similarly, after applying this patch to the latest code
>> (dd9b004b7ff3289fb7bae35130c0a5c0537266af "Merge tag 'trace-v6.19-rc1'")
>> from the master branch of the Linux repository and enabling KFENCE, I
>> encountered the following compilation errors.
>>
>> 8<------------------------------------------------------
>>   CC      arch/loongarch/kernel/asm-offsets.s
>> In file included from ./arch/loongarch/include/asm/pgtable.h:13,
>>                  from ./include/linux/pgtable.h:6,
>>                  from ./include/linux/mm.h:31,
>>                  from arch/loongarch/kernel/asm-offsets.c:11:
>> ./include/linux/kfence.h:97:35: warning: 'struct kmem_cache' declared inside
>> parameter list will n ot be visible outside of this definition or declaration
>>    97 | void kfence_shutdown_cache(struct kmem_cache *s);
>>       |                                   ^~~~~~~~~~
>> ./include/linux/kfence.h:103:29: warning: 'struct kmem_cache' declared inside
>> parameter list will not be visible outside of this definition or declaration
>>   103 | void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags);
>>       |                             ^~~~~~~~~~
>> ./include/linux/kfence.h:121:50: warning: 'struct kmem_cache' declared inside
>> parameter list will not be visible outside of this definition or declaration
>>   121 | static __always_inline void *kfence_alloc(struct kmem_cache *s, size_t
>> size, gfp_t flags)
>>       |
>> ^~~~~~~~~~
>> ./include/linux/kfence.h: In function 'kfence_alloc':
>> ./include/linux/kfence.h:132:31: error: passing argument 1 of '__kfence_alloc'
>> from incompatible p ointer type [-Wincompatible-pointer-types]
>>   132 |         return __kfence_alloc(s, size, flags);
>>       |                               ^
>>       |                               |
>>       |                               struct kmem_cache *
>> ./include/linux/kfence.h:103:41: note: expected 'struct kmem_cache *'
>> but argument is of type 'str
>> uct kmem_cache *'
>>   103 | void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags);
>>       |                      ~~~~~~~~~~~~~~~~~~~^
>> ------------------------------------------------------>8
>>
>> So, this patch currently runs into compilation issues.  linyu probably didn't have
>> KFENCE enabled when compiling locally, which is why this error was missed.
>> You can enable it as follows:
>>
>>   Kernel hacking
>>     Memory Debugging
>>       [*] KFENCE: low-overhead sampling-based memory safety
> 
> Hi Enze,
> 
> Sorry only test on arm64.
> 
> Could you help fix the compile issue and provide a correct change ?
> 
> Or I need sometime to resolve the issue.
> 

Thanks for pointing out this issue.  I've taken a look at the
compilation problem you mentioned.  Based on my current understanding,
the header dependencies are quite complex, and I couldn't find a
straightforward fix without potentially affecting other parts of the
codebase.

Given the risk of introducing broader compilation errors, I think it
might be safer to hold off on using the KFENCE_POOL_SIZE macro for now,
unless there's a clear and safe path forward that I might have missed.
I'm happy to discuss this further if you have any insights or suggestions.

Thanks,
Enze




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ