Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp407557pxb; Wed, 3 Mar 2021 06:23:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJy971g9PNC4bcLbI8at0E49h0kG4xlj32ke5QfMWyPmsjwK5tI4g/PNMx72Ps0XoqPSgoRC X-Received: by 2002:a17:906:29c3:: with SMTP id y3mr24919708eje.430.1614781422302; Wed, 03 Mar 2021 06:23:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614781422; cv=none; d=google.com; s=arc-20160816; b=aQwgQZmBmK/qu3eCCN+9HSrkMPRF8YlSZOlJG6N9TReew+uFXBCaYWZkRsy6xGT6Gf a7Tqmafry7aeU2YMUaLkmUbdBxh4gRlT0R64i6U9nZmCBxfciUAKu6tPVL1EJTTtbBHy YWQJ45uAYveNIVr2r1hGHBUQogwXQ73ee1Mcwt/dTcsFWNxgrZGGXC888U3g/9lJfcuj IRTnBFYyLQRYGqMBHVQ8JwpHLqp79esFZ89r2gPQH/eCG4fWiIBjU53Z0QlhoXBaopR+ EHQFnU5qr+Sz2F7YyHN8oyio5UErAxeDACPngJZ1fk66UAar2rAdE0D3nUN8lMr+01S8 xXxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s1Jl8mBWc7Qs0KfBeRgV+i/LaXoX9ZZMIqnSADRI/pY=; b=FRMt6HBxLZPx2vTTnNn2QCIVanuVxR/hMWRKsMhH8dOaaBiElrIMZHU7+RFU7M/F1L MmI/KMIyahMttUAGt94A+cSBfHaU5OL3y91Iw9X0690ZE4sP3BYlD7q7lvoGPHBsRoQI SG6aCSDb+A0W2s0nMHY0xNBFicPQePN7lU0xzepqYPRvf8E7RQzhB8K6etuMF74QJiPx xF/M9245vSHTxPNJggfdYmiE53F1sO2nG5b8BoJbT2G3I1RFrIYAH63yNoaIL5EPVO06 6Dwx5PXZQFW5pPhnLwZfZBTGpYZUVnRtjBLZCDmHT5wmzFdZLIFjjroYLzKp8Ug5iyG6 mobA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OJPsteWn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb37si743471ejc.81.2021.03.03.06.22.29; Wed, 03 Mar 2021 06:23:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OJPsteWn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238343AbhCAVFG (ORCPT + 99 others); Mon, 1 Mar 2021 16:05:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:50436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234078AbhCARM2 (ORCPT ); Mon, 1 Mar 2021 12:12:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3DC5E65027; Mon, 1 Mar 2021 16:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617012; bh=24kXXKyApNYODSa9cdqrJoUuMYbG+m3njvPZciOiabg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OJPsteWnWPJaDhnPQxIJoouBXTrkgU+hUjDehU0oiVwRT3jstCrgAZ4Uo66/L2EKp Owp/FonX6m6M94OsoZmUxqPnL/X0qm2OR1W2Cb+iAEHIYJyiXLgTJSc6GCijseM82W 81enYjFTLma5JM0LNUQx1ONbHB4299oXY864f01Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaohe Lin , Mike Kravetz , Muchun Song , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 172/247] mm/hugetlb: fix potential double free in hugetlb_register_node() error path Date: Mon, 1 Mar 2021 17:13:12 +0100 Message-Id: <20210301161040.083153667@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin [ Upstream commit cc2205a67dec5a700227a693fc113441e73e4641 ] In hugetlb_sysfs_add_hstate(), we would do kobject_put() on hstate_kobjs when failed to create sysfs group but forget to set hstate_kobjs to NULL. Then in hugetlb_register_node() error path, we may free it again via hugetlb_unregister_node(). Link: https://lkml.kernel.org/r/20210107123249.36964-1-linmiaohe@huawei.com Fixes: a3437870160c ("hugetlb: new sysfs interface") Signed-off-by: Miaohe Lin Reviewed-by: Mike Kravetz Reviewed-by: Muchun Song Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/hugetlb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index df89aed023029..9eb5c25fabc9e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2648,8 +2648,10 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent, return -ENOMEM; retval = sysfs_create_group(hstate_kobjs[hi], hstate_attr_group); - if (retval) + if (retval) { kobject_put(hstate_kobjs[hi]); + hstate_kobjs[hi] = NULL; + } return retval; } -- 2.27.0