From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 671C0D116E0 for ; Fri, 25 Oct 2024 03:13:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C91426B0085; Thu, 24 Oct 2024 23:12:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C19F86B0096; Thu, 24 Oct 2024 23:12:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6D5B6B0099; Thu, 24 Oct 2024 23:12:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 849AE6B0085 for ; Thu, 24 Oct 2024 23:12:59 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9A5D6803B6 for ; Fri, 25 Oct 2024 03:12:42 +0000 (UTC) X-FDA: 82710652500.11.412A8FD Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by imf29.hostedemail.com (Postfix) with ESMTP id 6447E120008 for ; Fri, 25 Oct 2024 03:12:31 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AYMAnOqu; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.167.42 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729825863; a=rsa-sha256; cv=none; b=AIKSe4v/nnX1PJu9d/MFpyASuRjlIYiu4WWNDFQfBrJN61zyhP+rgYfedfeWVJ8J4lXRjG Is7lR/DvP4W7FPfrV24SKUs6DitlDPtukprPB7F3cHQ2RXL7PcT49+VJhEYJhrNZurx+nq 3eY6FzSiEtBi1etFF/CHL47DWhmIwfs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AYMAnOqu; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.167.42 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729825863; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=J57jc6caP7dneGqTVVmCu4gt6t7MlPQxrlJAMM0H5nY=; b=BCGd5BKh26SsBnIopeNTy4T4AWdwKd+j1MdLaoajpoy7qKDlNZzeHk+q4mx4F4KYyQ3FMB IHxUI2MWr8x+cDLXe8pNKn40a95j/OEjlB2KrpSjHxGkfsTrtW/sCLS8IO1I61L2TpmTUZ v8bNC6lZA7OosviDidUE7lmEYYMDXzQ= Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-539e8607c2aso1854494e87.3 for ; Thu, 24 Oct 2024 20:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729825975; x=1730430775; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=J57jc6caP7dneGqTVVmCu4gt6t7MlPQxrlJAMM0H5nY=; b=AYMAnOquJEHGciDmNkBkSXRwSaMPanYkqmgiDvmCqdGA/QRDKO7znH1mNRarAD/Aha 630Dbv/SLs8KVkB0hUp1dhXmRZyPa3uPLDwrP8pR75ZRGOCwV4/4X4hE6V7oRMzQwMSJ x6IVqmB1ssyckpOcQ+s2PiKLkmqj276CTP/Fed7xI984rZCl0VaoO/q06WoWUqSTMEmC exupZUDTI7y0l//yBj60isRn+UizOGE03pJCmnUg9IiPOviX690rAL48of9Y46NAQFJH pQGlPShP+J/KiVTORXPYfm4R2zUpQJPaGR4uRT253nW+pdGjpvMIVQrmUkuqasPrOAe5 LUtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729825975; x=1730430775; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J57jc6caP7dneGqTVVmCu4gt6t7MlPQxrlJAMM0H5nY=; b=cF43EfAhpPHlxdlybD1Lx5AEmWfZp/wrRlM/4CdLE+/LiEyOBx8XZfPWFCX8p/9OOn ShG3IGjm9l9mJGkXVHCdyDSGkJxtjNGWy5TM9SEmm9+TgAI2NKGUaqXi/bIFXW2dWlXQ o5DGRKeLiVhkvyvflmqpIxovnv3vY5RcmG7etg2YnkAIc51+hXh4J+iYofCD6Lkw+eX/ GKpV3c9yQa8rdOXau44W8t8VkW4StzhyqJeuhjq1r+yVx/9Nr+0HYSH71/lNTRYNk2u7 PNnlqVFTkLx63n1nSZioZF0rIvv/4m/350056tuBi4SiKiwZ4/3UrDO3ph6FmnoV3psc 09DQ== X-Forwarded-Encrypted: i=1; AJvYcCVcGhNu/HOfS81cABKwtPpZ+xlgz/3CsOvtN1PX8S/EznRU7rMFIh19/+4h4umvNBV52gmSHzb7nQ==@kvack.org X-Gm-Message-State: AOJu0Yx5zDW5aLDe7IvEOFcNKbjwXd8VnfqsxutDlhMTLUPU2Zl8rxAR eUXX3kwGSpKjSkw9cTrTjpJdrEaOX6z+bWuJm4TIsFWV3SsbQd2J7N+5+I8BHguGQ/3QwHDjz4T qRB5x3R6MFFMV5+UpEGQQPklL+nc= X-Google-Smtp-Source: AGHT+IHGZoM4BzjsepQKCRxZadMrSN1riS94M2w7dDDfpmR7a3YGSEZoI7pzq+qK5MpPoCrynFj7HcqXbCuLU/yu0gc= X-Received: by 2002:a05:6512:3a91:b0:53b:2041:e78c with SMTP id 2adb3069b0e04-53b23e8dd14mr2457674e87.56.1729825974772; Thu, 24 Oct 2024 20:12:54 -0700 (PDT) MIME-Version: 1.0 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> <7707ff34-16e1-4f8c-9af6-8b5b6591c77e@suse.cz> <511392f2-8e94-d2fc-63a6-ac3b4cac10e1@huawei.com> In-Reply-To: <511392f2-8e94-d2fc-63a6-ac3b4cac10e1@huawei.com> From: Hyeonggon Yoo <42.hyeyoo@gmail.com> Date: Fri, 25 Oct 2024 12:12:42 +0900 Message-ID: Subject: Re: [PATCH v4 3/3] mm/slub: Fix memory leak of kobj->name in sysfs_slab_add() To: Jinjie Ruan Cc: Vlastimil Babka , Liu Shixin , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 6447E120008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: oehyt9htmpxwpcq4dm8n5tbtbmb4dq3k X-HE-Tag: 1729825951-799898 X-HE-Meta: U2FsdGVkX19450FKRo9SlkRIN34RhyTuE/KGfQDmTGizp7gEIvcRYinIGa6yVxbojPqeLctaHtkbXg6z0oLksoaVgsQNdaCJm8SAN76f6Da9Sk8TiafCoQhVSs5RGgCYtbJ3iENn7gTELAMV2t5yamPas7Ho0m2oszfI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lSpu4iCyLRpYnJ6NuAGzdirBbZQGtn5ufw0G3VVJrH0y3Ctz+jQL5onsxpIa5oYoVlcq3RvFOjKon32gez6Peg5VjYhv6rbpYENZYI+KTESxDoUSMRXtu2tXJR3hv/dgCzUSBcEyqJ/vu3GlLQMW6H/4v1te+2eT15NC7NWN8f6pyw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Oct 25, 2024 at 11:10=E2=80=AFAM Jinjie Ruan wrote: > > > > On 2024/10/2 19:35, Vlastimil Babka wrote: > > On 9/13/24 17:00, Hyeonggon Yoo wrote: > >> > >> > >>> On Sep 13, 2024, at 11:10=E2=80=AFPM, 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=E2=80=AFPM 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=EF=BC=8Cevery 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 serie= s which > >>> was not answered and then it got forgotten. Feel free to take over an= d 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 fu= nction) 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 r= elease() method, > >>> and the kobject must persist (in a consistent state) until that metho= d 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 modprob= e > >>>> 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 sugg= ests, > >>> 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-rc= 1. 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 faile= d 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=3Dslab/for-6.12-rc1/fixes&id=3D77ced98f0f03fdc196561d1afbe652899c318073 > > > > So once that's mainline, we can see if anything remains > > Using the newest 6.12.0-rc4, the issue still exists in slab: > > unreferenced object 0xffffff80ce6da9c0 (size 16): > comm "modprobe", pid 12782, jiffies 4299073226 > hex dump (first 16 bytes): > 6f 76 6c 5f 69 6e 6f 64 65 00 6d ce 80 ff ff ff ovl_inode.m..... > backtrace (crc 1a460899): > [<00000000edf3be8b>] kmemleak_alloc+0x34/0x40 > [<0000000004121c8d>] __kmalloc_node_track_caller_noprof+0x304/0x3e8 > [<00000000515e9eda>] kstrdup+0x48/0x84 > [<000000005d2d0c1a>] kstrdup_const+0x34/0x40 > [<00000000d14076ce>] kvasprintf_const+0x170/0x1e0 > [<0000000060f79972>] kobject_set_name_vargs+0x5c/0x12c > [<00000000299f544a>] kobject_init_and_add+0xd4/0x168 > [<000000008ceb40f4>] sysfs_slab_add+0x190/0x21c > [<00000000027371b9>] do_kmem_cache_create+0x354/0x5cc > [<00000000cc9eb2aa>] __kmem_cache_create_args+0x1b8/0x2c8 > [<000000006a3e21cc>] 0xffffffea545a409c > [<0000000002f945b3>] do_one_initcall+0x110/0x77c > [<0000000024f23211>] do_init_module+0x1dc/0x5c8 > [<00000000a16337d6>] load_module+0x4acc/0x4e90 > [<00000000be447e77>] init_module_from_file+0xd4/0x128 > [<0000000048065de1>] idempotent_init_module+0x2d4/0x57c Hi Jinjie, Oh, I should've Cc'd you... https://lore.kernel.org/linux-mm/20241021091413.154775-1-42.hyeyoo@gmail.co= m/ I wrote a fix for this and I'm adjusting feedback from Christoph and Vlasti= mil. Thanks, Hyeonggon