From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 587C8198A1A for ; Wed, 2 Oct 2024 11:35:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727868960; cv=none; b=P+gcX/oAIlErDLY4PSU2P+4r0AbYlZK0x5aU5Km24o97W5sAXKY+tQeRyHch62LN9cxruAEF7LUVngVjsDxJdt17TvokD/zvrQZJo9AWj51nr0hGe+f5tPuolrLoreU0WY60YZsJeLP6KbnYEKF3ckbVz17MTtoMuF6xobQgSZ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727868960; c=relaxed/simple; bh=GLHCxMbDhNwnLbwNNcGoZhpghGpsFmO9mgNc3YH+BMg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FTbhtaTN/1HbbvQlqxQy1+InwVL2lPsM0+dLG5f9BKfjFuhvXN7H1Qdkjqq/NNCVOB3x5BiBLiHSY31APKtA52C7Pti9FOt+MaIiaBNhgmpMo3cxJxHBvN9eAl0HhigpwwvT+XZ+QDyHc6+FTGkwdyVXxXs7icpkx5L4AhUlQFM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=yRxljwAV; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=sSS+LRzG; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=yRxljwAV; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=sSS+LRzG; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="yRxljwAV"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="sSS+LRzG"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="yRxljwAV"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="sSS+LRzG" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6E46021B13; Wed, 2 Oct 2024 11:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1727868956; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=ibiVcJ1MjH/yx3nJbhHosPofjLwkaKuy3WkYX14gRR0=; b=yRxljwAVxBrd8vTSPWqfMWFO7sXX1f0BXae24L681tU0jv/hpmHgt58cviu8sMgTauBkLe olfHbCsN8bBNsQHvIqPWHOfunbDZMU8uxpljecrWOeBWHM8FZgs7gL/gDUzqbMDJuwUEN1 VkuLy9B6dSeubyfa13JkZ3AJZvU03bE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1727868956; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=ibiVcJ1MjH/yx3nJbhHosPofjLwkaKuy3WkYX14gRR0=; b=sSS+LRzGPTYK9w+EffDa/d47zEtgVkYzqIWZ3e0TJ6fK7Q977nu+pmqw1R4mc7LEbJXwam HjbKcqVuNCJN/fAQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=yRxljwAV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=sSS+LRzG DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1727868956; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=ibiVcJ1MjH/yx3nJbhHosPofjLwkaKuy3WkYX14gRR0=; b=yRxljwAVxBrd8vTSPWqfMWFO7sXX1f0BXae24L681tU0jv/hpmHgt58cviu8sMgTauBkLe olfHbCsN8bBNsQHvIqPWHOfunbDZMU8uxpljecrWOeBWHM8FZgs7gL/gDUzqbMDJuwUEN1 VkuLy9B6dSeubyfa13JkZ3AJZvU03bE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1727868956; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=ibiVcJ1MjH/yx3nJbhHosPofjLwkaKuy3WkYX14gRR0=; b=sSS+LRzGPTYK9w+EffDa/d47zEtgVkYzqIWZ3e0TJ6fK7Q977nu+pmqw1R4mc7LEbJXwam HjbKcqVuNCJN/fAQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 52F3013974; Wed, 2 Oct 2024 11:35:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wgPjExww/WYveAAAD6G6ig (envelope-from ); Wed, 02 Oct 2024 11:35:56 +0000 Message-ID: <7707ff34-16e1-4f8c-9af6-8b5b6591c77e@suse.cz> Date: Wed, 2 Oct 2024 13:35:55 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 3/3] mm/slub: Fix memory leak of kobj->name in sysfs_slab_add() Content-Language: en-US To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Jinjie Ruan , Liu Shixin , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Linux Memory Management List , LKML References: <20221112114602.1268989-1-liushixin2@huawei.com> <20221112114602.1268989-4-liushixin2@huawei.com> <3780a622-03f2-4cfe-5705-0e9d0be61d57@huawei.com> <68b86f66-cd00-bb7d-b8bb-5a94e8dd1ea2@huawei.com> <02820eb8-0b8f-4aa8-9315-85368e9c331e@suse.cz> <0F94364A-F0C8-4C0A-B38D-3DDEA653B6B7@gmail.com> From: Vlastimil Babka Autocrypt: addr=vbabka@suse.cz; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0eoAcfPIP2OZ+ 9oe9IF/R28zmh0ifLXyJQQz5ofdj4bPf8ecEW0rhcq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ZGPrAeFNiHPdOT7DaXKeHpW9homgtBxj 8aX/UkSvEGJKUEbFL9cVa5tzyialGkSiZJNkWgeHe+jEcfRT6pJZOJidSCdzvJpbdJmm+eED w9XOLH1IIWh7RURU7G1iOfEfmImFeC3cbbS73LQEFGe1urxvIH5K/7vX+FkNcr9ujwWuPE9b 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: <0F94364A-F0C8-4C0A-B38D-3DDEA653B6B7@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 6E46021B13 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FREEMAIL_TO(0.00)[gmail.com]; RCPT_COUNT_SEVEN(0.00)[11]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.cz:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO On 9/13/24 17:00, Hyeonggon Yoo wrote: > > >> On Sep 13, 2024, at 11:10 PM, Vlastimil Babka 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 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 > >