From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 7219138552F for ; Sat, 11 Apr 2026 14:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775917765; cv=none; b=Z8SCfDRdtPuH5X57VSDuOtZyTdnkAbGJr2DP4I6gpMI8L8L6yKhEILLgkphc5gsJB+3+mEEV2b5R1rfWOgWHMsfK23Dea+MDx6Emfzir7gvnoXuwum2k7bDlnFdd77ZqrFCfOx9LHJx4f9Yj+R0Sxb0ojeyPRRfvx1I+bHJRn9Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775917765; c=relaxed/simple; bh=KrHFq7r4Xovyi5P7utoDg9Lma3g9Qp+emCY4VkvO3AA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=TbFxFU9ZWIsj240Q+AhZv3BQMbOwgnq/iLfvoDzXe3UnhCzxR5i/VUzHTLOJDf6ECf7PonwMJPAP7vE9/V1wvT9QTQrvia75J44tM5wgMEjpwMUz2T0Auba/dWla3DOkJkAx7Ji6nFFpFzJkYwRxPB+yyHgn4jasjRH+pODS22s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ue5+mMr2; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ue5+mMr2" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1775917759; h=from:from: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; bh=hAPo+F3jMH2I7xItiYLcaM+9S3+H5Eq1ikmT0n242L8=; b=ue5+mMr2JI6l0KzmB7iHuu/GYGrv20M/Byg9l+U66V9qTHBKJtg8HUDt8OBOibX0NXZp3X ep+l6RAyk7GaqNgsYrfe7SFqpn1CY9DvitpBQGYgg7hCn01OlXHsZYfzR7qWqyfFPtZCuE L1CSnGQir9/U6g7ZWPXgFyhlHUqTkcc= From: Lance Yang To: lgs201920130244@gmail.com Cc: akpm@linux-foundation.org, david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] mm: thp: Fix refcount leak in thpsize_create() error path Date: Sat, 11 Apr 2026 22:28:58 +0800 Message-Id: <20260411142858.85496-1-lance.yang@linux.dev> In-Reply-To: <20260411062152.2092967-1-lgs201920130244@gmail.com> References: <20260411062152.2092967-1-lgs201920130244@gmail.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On Sat, Apr 11, 2026 at 02:21:52PM +0800, 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 Right. As documented for kobject_init_and_add(), once it has been called, the error path should go through kobject_put(): /** * kobject_init_and_add() - Initialize a kobject structure and add it to * the kobject hierarchy. ... * * This function combines the call to kobject_init() and kobject_add(). * * If this function returns an error, kobject_put() must be called to * properly clean up the memory associated with the object. This is the ... */ int kobject_init_and_add(struct kobject *kobj, const struct kobj_type *ktype, struct kobject *parent, const char *fmt, ...) >kobject unbalanced, resulting in a refcount leak and potentially leading >to a use-after-free. IIUC, this looks more like wrong kobject lifetime handling and likely a leak, not a clear UAF :) >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 >--- Apart from that, LGTM. Reviewed-by: Lance Yang