From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B6C63546C9 for ; Mon, 13 Jul 2026 07:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783926698; cv=none; b=tMdUcT/yUASRh4Q6VwhMlKrJGZAws3aO3+aYpDOIW9waqMPdVHpfXMUn+Ab3QFT1SzzYoBoF7PXLmI2iS64psJY4CTRJiOSQlqfWfL5bv8npdZAbPh05WJ8DllGQUw+BdxIovWosm/S4JJCCu0OjRjoyn69SDBfd2JvBsSr0SYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783926698; c=relaxed/simple; bh=oJQMro69OsHgnf3aizGXqBFdaMh3nsU7T0MboextFs8=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type; b=hTtsxIqjqcywiIXSVQ1E11GaXrxm+br6jlNt3le2JSsxpnX9KjkZNhJ6n+pGCXr38lRf+1mECAOBfaE9ZygQ3oXN0NS+yn1MKvUU/57SesT9GipxziuR95ywhxi/2bAJ/eJ+KmrawGe++DceFxj4nerb7rB5ESWiQmt3abv5TSs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b=p8hAFoYl; arc=none smtp.client-ip=220.197.31.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b="p8hAFoYl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Message-ID:Date:From:MIME-Version:To:Subject: Content-Type; bh=UvZfSiXg/aWlGMDrq0CQO4IHt7cZbR24Kxgf0OwSvCc=; b=p8hAFoYlLnc0dp0ifPJrUBEJp6BMytpbFdnacsBfKb4oCndxfWj56Gp03c3jcY D8BPPuzQYuATekWZoYulu+SgIGUWk21JfENSOLSiYzKJ8Z1nzhfWduWXZWtpLy6B qvk1jTwxz4ZCkpOSfupRJSaeVN6eQKGiG+R/DlaPiTTvY= Received: from localhost.localdomain (unknown []) by gzsmtp1 (Coremail) with SMTP id PCkvCgDH72o2j1RqfOJeCA--.8775S2; Mon, 13 Jul 2026 15:09:43 +0800 (CST) Message-ID: <6A548F23.4040800@126.com> Date: Mon, 13 Jul 2026 15:09:23 +0800 From: Hongling Zeng User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: Harry Yoo , vbabka@kernel.org, akpm@linux-foundation.org, hao.li@linux.dev, cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev, vdavydov.dev@gmail.com, davej@fedoraproject.org CC: Hongling Zeng , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/slub: fix kobject leak in sysfs_slab_add error path References: <20260713055829.127864-1-zenghongling@kylinos.cn> <6A548241.8080802@126.com> <40902df6-373c-4e87-9ec7-4e72f9f0efa2@kernel.org> In-Reply-To: <40902df6-373c-4e87-9ec7-4e72f9f0efa2@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:PCkvCgDH72o2j1RqfOJeCA--.8775S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kw1xXrWDWFW7tF13XF18Xwb_yoW8Kw4fpr y3Jay7KFWDGF4IkwsIq3W8Ww1F9rZ5Ar45Zr4Fvw10kwn3uF18tF4xKr98uFyDCF48Ga17 ZF4jy3sagF1UCF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j4Hq7UUUUU= X-CM-SenderInfo: x2kr0wpolqwiqxrzqiyswou0bp/xtbBoRegcWpUjzc9qgAA32 在 2026年07月13日 14:27, Harry Yoo 写道: > > On 7/13/26 3:14 PM, Hongling Zeng wrote: >> 在 2026年07月13日 14:07, Harry Yoo 写道: >>> On 7/13/26 2:58 PM, Hongling Zeng wrote: >>>> When kobject_init_and_add() fails in sysfs_slab_add(), the kobject >>>> is not properly cleaned up, causing a memory leak. >>>> >>>> According to the kobject API documentation, when kobject_init_and_add() >>>> returns an error, the caller must call kobject_put() to properly clean >>>> up the memory associated with the object. The current code only frees >>>> the 'name' string but forgets to release the kobject reference. >>> This was intentional, please see commit 2420baa8e046 ("mm/slab: Allow >>> cache creation to proceed even if sysfs registration fails"). >> Thank you for the clarification. I see now that this was an intentional >> design choice to allow cache creation to proceed even when sysfs >> registration fails. >> >>>> Fix this by calling kobject_put() before jumping to the error label. >>>> >>>> Fixes: 54b6a731025f ("slub: fix leak of 'name' in sysfs_slab_add") >>>> Signed-off-by: Hongling Zeng >>>> --- >>> Uh, there was a similar attempt recently... >>> >>> https://lore.kernel.org/linux-mm/ >>> gimwkjjpvwu2sg5625b3eeatw2vhv7rs6enm3vepdduhcefbf5@xen5iec7sn3z >>> >>> Sounds like we need a comment saying it is intentional! >>> >> Good idea. Would a patch adding a comment like this be useful? >> >> err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", >> name); >> + /* >> + * Note: Intentionally not calling kobject_put() on error. >> + * >> + * The kobject release callback (slab_kmem_cache_release) would >> + * free the entire kmem_cache structure. However, sysfs >> + * registration failures are treated as non-fatal - the cache >> + * continues to be used. See commit 2420baa8e046 ("mm/slab: Allow >> + * cache creation to proceed even if sysfs registration fails"). >> + */ > Could we make it bit more concise please? > > Something like > > "Intentionally skip kobject_put(). See commit 2420baa8e046 ("mm/slab: > Allow cache creation to proceed even if sysfs registration fails")" > >> if (err) >> goto out; >> Thank you for the suggestion. Here's the simplified version: [PATCH v1] mm/slub: add comment explaining intentional kobject handling in sysfs_slab_add Please review. Thanks! Best regards, Hongling Zeng