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]
Date: Tue, 30 Apr 2024 11:19:59 +0200
From: Nicolas Bouchinet <nicolas.bouchinet@...p-os.org>
To: Vlastimil Babka <vbabka@...e.cz>,
 Chengming Zhou <chengming.zhou@...ux.dev>, linux-mm@...ck.org,
 linux-kernel@...r.kernel.org
Cc: cl@...ux.com, penberg@...nel.org, rientjes@...gle.com,
 iamjoonsoo.kim@....com, akpm@...ux-foundation.org, roman.gushchin@...ux.dev,
 42.hyeyoo@...il.com, Xiongwei Song <xiongwei.song@...driver.com>
Subject: Re: [PATCH] slub: Fixes freepointer encoding for single free


On 4/29/24 22:22, Vlastimil Babka wrote:
> On 4/29/24 6:16 PM, Nicolas Bouchinet wrote:
>> On 4/29/24 16:52, Chengming Zhou wrote:
>>> On 2024/4/29 22:32, Nicolas Bouchinet wrote:
>>>> On 4/29/24 15:35, Chengming Zhou wrote:
>>>>> On 2024/4/29 20:59, Nicolas Bouchinet wrote:
>>>>>>> I help maintaining the Linux-Hardened patchset in which we have a slab object canary feature that helps detecting overflows. It is located just after the object freepointer.
>>>>>> I've tried a patch where the freepointer is avoided but it results in the same bug. It seems that the commit 0f181f9fbea8bc7ea ("mm/slub.c: init_on_free=1 should wipe freelist ptr for bulk allocations") inits the freepointer on allocation if init_on_free is set in order to return a clean initialized object to the caller.
>>>>>>
>>>>> Good catch! You may need to change maybe_wipe_obj_freeptr() too,
>>>>> I haven't tested this, not sure whether it works for you. :)
>>>>>
>>>>> diff --git a/mm/slub.c b/mm/slub.c
>>>>> index 3e33ff900d35..3f250a167cb5 100644
>>>>> --- a/mm/slub.c
>>>>> +++ b/mm/slub.c
>>>>> @@ -3796,7 +3796,8 @@ static void *__slab_alloc_node(struct kmem_cache *s,
>>>>>     static __always_inline void maybe_wipe_obj_freeptr(struct kmem_cache *s,
>>>>>                                                       void *obj)
>>>>>     {
>>>>> -       if (unlikely(slab_want_init_on_free(s)) && obj)
>>>>> +       if (unlikely(slab_want_init_on_free(s)) && obj &&
>>>>> +           !freeptr_outside_object(s))
>>>>>                    memset((void *)((char *)kasan_reset_tag(obj) + s->offset),
>>>>>                            0, sizeof(void *));
>>>>>     }
>>>>>
>>>>> Thanks!
>>>> Indeed since check_object() avoids objects for which freepointer is in the object and since val is equal to SLUB_RED_ACTIVE in our specific case it should work. Do you want me to add you as Co-authored ?
>>>>
>>> Ok, it's great. Thanks!
>> Now I think of it, doesn't it seems a bit odd to only properly
>> init_on_free object's freepointer only if it's inside the object ? IMHO
>> it is equally necessary to avoid information leaking about the
>> freepointer whether it is inside or outside the object.
>> I think it break the semantic of the commit 0f181f9fbea8bc7ea
>> ("mm/slub.c: init_on_free=1 should wipe freelist ptr for bulk
>> allocations") ?
> Hm, AFAIU, wiping inside object prevents misuse of some buggy kernel code
> that would allocate and accidentally leak prior content (including the
> in-object freepointer) somewhere the attacker can read. Now for wiping the
> freepointer outside the object to be useful it would have assume said
> leak-prone code to additionally be reading past the allocated object size,
> i.e. a read buffer overflow. That to me seems to be a much more rare
> combination, and also in that case such code could also likely read even
> further past the object, i.e. leak the next object's data? IOW I don't think
> it buys us much additional security protection in practice?
>
Moreover, with CONFIG_SLAB_FREELIST_HARDENED activated, freepointers are 
encoded and harder to exploit.


>> Thanks.
>>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ