linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Jinjie Ruan <ruanjinjie@huawei.com>,
	Liu Shixin <liushixin2@huawei.com>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Linux Memory Management List <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 3/3] mm/slub: Fix memory leak of kobj->name in sysfs_slab_add()
Date: Wed, 2 Oct 2024 13:35:55 +0200	[thread overview]
Message-ID: <7707ff34-16e1-4f8c-9af6-8b5b6591c77e@suse.cz> (raw)
In-Reply-To: <0F94364A-F0C8-4C0A-B38D-3DDEA653B6B7@gmail.com>

On 9/13/24 17:00, Hyeonggon Yoo wrote:
> 
> 
>> On Sep 13, 2024, at 11:10 PM, Vlastimil Babka <vbabka@suse.cz> wrote:
>> 
>> On 9/6/24 10:10, Jinjie Ruan wrote:
>>> 
>>> 
>>> On 2024/9/5 21:59, Hyeonggon Yoo wrote:
>>>> On Thu, Sep 5, 2024 at 12:41 PM Jinjie Ruan <ruanjinjie@huawei.com> wrote:
>>>>> 
>>>>> 
>>>>> 
>>>>> On 2022/11/12 19:46, Liu Shixin wrote:
>>>>>> There is a memory leak of kobj->name in sysfs_slab_add():
>>>>>> 
>>>>>> unreferenced object 0xffff88817e446440 (size 32):
>>>>>>   comm "insmod", pid 4085, jiffies 4296564501 (age 126.272s)
>>>>>>   hex dump (first 32 bytes):
>>>>>>     75 62 69 66 73 5f 69 6e 6f 64 65 5f 73 6c 61 62  ubifs_inode_slab
>>>>>>     00 65 44 7e 81 88 ff ff 00 00 00 00 00 00 00 00  .eD~............
>>>>>>   backtrace:
>>>>>>     [<000000005b30fbbd>] __kmalloc_node_track_caller+0x4e/0x150
>>>>>>     [<000000002f70da0c>] kstrdup_const+0x4b/0x80
>>>>>>     [<00000000c6712c61>] kobject_set_name_vargs+0x2f/0xb0
>>>>>>     [<00000000b151218e>] kobject_init_and_add+0xb0/0x120
>>>>>>     [<00000000e56a4cf5>] sysfs_slab_add+0x17d/0x220
>>>>>>     [<000000009326fd57>] __kmem_cache_create+0x406/0x590
>>>>>>     [<00000000dde33cff>] kmem_cache_create_usercopy+0x1fc/0x300
>>>>>>     [<00000000fe90cedb>] kmem_cache_create+0x12/0x20
>>>>>>     [<000000007a6531c8>] 0xffffffffa02d802d
>>>>>>     [<000000000e3b13c7>] do_one_initcall+0x87/0x2a0
>>>>>>     [<00000000995ecdcf>] do_init_module+0xdf/0x320
>>>>>>     [<000000008821941f>] load_module+0x2f98/0x3330
>>>>>>     [<00000000ef51efa4>] __do_sys_finit_module+0x113/0x1b0
>>>>>>     [<000000009339fbce>] do_syscall_64+0x35/0x80
>>>>>>     [<000000006b7f2033>] entry_SYSCALL_64_after_hwframe+0x46/0xb0
>>>>> 
>>>>> 
>>>>> Hi,every one,
>>>> 
>>>> Hi.
>>>> 
>>>>> I found the same problem and it solve this problem with the patch, is
>>>>> there any plan to update the patch and solve it.
>> 
>> Hmm looks like back in 2022, Hyeonggon had some feedback to the series which
>> was not answered and then it got forgotten. Feel free to take over and send
>> an updated version.
> 
> 
> I was thinking of what the fix would be with my feedback,
> and I still think passing different kobj_type (with a dummy release function) for early kmem_caches
> will be a more appropriate approach.
> 
> However, there is one concern: people that wrote kobject.rst might not like it :(
> 
> in Documentation/core-api/kobject.rst:
>> One important point cannot be overstated: every kobject must have a release() method,
>> and the kobject must persist (in a consistent state) until that method is called. If these constraints are not met,
>> the code is flawed. Note that the kernel will warn you if you forget to provide a release() method.
>> Do not try to get rid of this warning by providing an "empty" release function.
> 
> But obviously we don't want to release caches just because the kernel failed to add it to sysfs.
> 
>>>> What kernel version do you use,
>>> 
>>> 6.11.0-rc6
>>> 
>>>> and when do you encounter it or how do you reproduce it?
>>> 
>>> Hi, Hyeonggon,
>>> 
>>> Thank you, I encounter it when doing inject fault test while modprobe
>>> amdgpu.ko.
>> 
>> So I wonder where's the problem that results in kobject_init_and_add()
>> failing. If it's genuinely duplicate name as commit 80da026a8e5d suggests,
>> 6.12-rc1 will have a warning to prevent that. Delayed destruction of
>> SLAB_TYPESAFE_BY_RCU caches should also no longer happen with 6.12-rc1. So
>> worth retrying with that and if it's still failing, we should look at the
>> root cause perhaps.
> 
> I thought it was because the memory allocation for a name string failed due to fault injection?

Well in any case 6.12-rc1 introduced a new one, fixed by:
https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git/commit/?h=slab/for-6.12-rc1/fixes&id=77ced98f0f03fdc196561d1afbe652899c318073

So once that's mainline, we can see if anything remains

>> 
>>>> 
>>>> --
>>>> Hyeonggon
> 
> 



  reply	other threads:[~2024-10-02 11:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12 11:45 [PATCH v4 0/3] Refactor __kmem_cache_create() and fix memory leak Liu Shixin
2022-11-12 11:46 ` [PATCH v4 1/3] mm/slab_common: Move cache_name to create_cache() Liu Shixin
2022-11-12 11:46 ` [PATCH v4 2/3] mm/slub: Refactor __kmem_cache_create() Liu Shixin
2022-11-12 11:46 ` [PATCH v4 3/3] mm/slub: Fix memory leak of kobj->name in sysfs_slab_add() Liu Shixin
2022-11-16 12:59   ` Hyeonggon Yoo
2024-09-05  3:41   ` Jinjie Ruan
2024-09-05 13:59     ` Hyeonggon Yoo
2024-09-06  8:10       ` Jinjie Ruan
2024-09-13 14:10         ` Vlastimil Babka
2024-09-13 15:00           ` Hyeonggon Yoo
2024-10-02 11:35             ` Vlastimil Babka [this message]
2024-10-25  2:10               ` Jinjie Ruan
2024-10-25  3:12                 ` Hyeonggon Yoo

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=7707ff34-16e1-4f8c-9af6-8b5b6591c77e@suse.cz \
    --to=vbabka@suse.cz \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liushixin2@huawei.com \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=ruanjinjie@huawei.com \
    /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