From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (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 C67E0233721; Sat, 11 Apr 2026 07:45:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775893545; cv=none; b=AOhxRCQZt+YUXd0duyNLPXOIgEkbcV9T1xCObddTUSz9DQI2AyhJj1ibFg29CF16+D4J/oxKML3yqv6UnoorwWfiy3tI3g0+fd14vhOidFu5/+ry7c5iiVcTrzj2DSIIYwhDOA+vXAvarW4UTYjKp/fLZN0vgMgmK8wYB2qk3qE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775893545; c=relaxed/simple; bh=Ej7LzUcRvr4ApgnQCwGuzU/4NScEbxECLa+kaE75f1o=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=itW3yjx5zjogZJyzHIBQbd2f48r4ol04mmw0OVRX8Fg3DZQhtBrUPzT3+mnOHA7W3Izu5S7QA0cluJ+u5f3dUwo+gedWF63o42wbVdrmlre68srKGxBHln6oQcJoEdYUr6h59ZiL7ScgPimxM8IEzfUsyIpykHICe/+NCpwdGWI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=A4uGXCWo; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="A4uGXCWo" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1775893533; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=GB+JlqaisJkQAW2pvwxx66NbFm/L/SQFwt5rdeDTOMQ=; b=A4uGXCWo0Zy12G6QSSb1JDY86dgM28fWtkzKYnrS3n9uhTlGDMjLFpiToFg8e2LAMEw4uMConvjxR86U2WJJKFzu00rLWI+LPDa8y5NahhZA3H6s+ciczyI28xqeId6lrVX/F983bnQ2LSl3bxsh837Vn32txU0PeqUTdtp8Vxo= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R971e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0X0nG2sP_1775893530; Received: from 30.74.144.103(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X0nG2sP_1775893530 cluster:ay36) by smtp.aliyun-inc.com; Sat, 11 Apr 2026 15:45:31 +0800 Message-ID: Date: Sat, 11 Apr 2026 15:45:30 +0800 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: thp: Fix refcount leak in thpsize_create() error path To: Guangshuo Li , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org References: <20260411062152.2092967-1-lgs201920130244@gmail.com> From: Baolin Wang In-Reply-To: <20260411062152.2092967-1-lgs201920130244@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/11/26 2:21 PM, Guangshuo Li wrote: > After kobject_init_and_add(), the lifetime of the embedded struct > kobject is expected to be managed through the kobject core reference > counting. > > In thpsize_create(), if kobject_init_and_add() fails, thpsize is freed > directly with kfree() rather than releasing the kobject reference with > kobject_put(). This may leave the reference count of the embedded struct > kobject unbalanced, resulting in a refcount leak and potentially leading > to a use-after-free. > > Fix this by using kobject_put(&thpsize->kobj) in the failure path and > letting thpsize_release() handle the final cleanup. > > Fixes: 3485b88390b0 ("mm: thp: introduce multi-size THP sysfs interface") > Cc: stable@vger.kernel.org > Signed-off-by: Guangshuo Li > --- Make sense to me. Reviewed-by: Baolin Wang