From nobody Sat Apr 11 04:00:14 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E64ECC25B0E for ; Tue, 16 Aug 2022 19:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237246AbiHPTkO (ORCPT ); Tue, 16 Aug 2022 15:40:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237239AbiHPTkL (ORCPT ); Tue, 16 Aug 2022 15:40:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85AC88671F for ; Tue, 16 Aug 2022 12:40:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660678809; 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=YJVt87I+RkFO3jUAhHrJxKBqiCZ7HeO0w2k1yZLam5o=; b=OCEKUEo5ip1C5eA+AkKjcJtL3dvsaa2Oi+dhRHRQtlp2DnJXeCa0LCef3RkiAYZZTRh3DX EZLkyZ5DrQmgyU1TamfVBvo5lOMSaZKV5M+5+f+qtKvySJYVuEmcPeZovZMSmYNzhaJ1sh cKt5yV2icvfgio5+ffrqwPS9Ps1+NzY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-275-uFEVRtW1MFW4FV7_cbTngg-1; Tue, 16 Aug 2022 15:40:05 -0400 X-MC-Unique: uFEVRtW1MFW4FV7_cbTngg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CDFBD18A6524; Tue, 16 Aug 2022 19:40:04 +0000 (UTC) Received: from [172.30.41.16] (unknown [10.22.18.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84E761415128; Tue, 16 Aug 2022 19:40:04 +0000 (UTC) Subject: [PATCH 1/3] PCI: Fix double-free in resource attribute error path From: Alex Williamson To: linux-pci@vger.kernel.org, bhelgaas@google.com Cc: linux-kernel@vger.kernel.org Date: Tue, 16 Aug 2022 13:40:04 -0600 Message-ID: <166067879638.1885802.1955389738707186135.stgit@omen> In-Reply-To: <166067824399.1885802.12557332818208187324.stgit@omen> References: <166067824399.1885802.12557332818208187324.stgit@omen> User-Agent: StGit/1.5.dev2+g9ce680a52bd9 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If pci_create_attr() fails the remaining resource bin attributes are removed and freed based on the pointer entries which are not cleared in the case that creation of the bin attribute fails. Signed-off-by: Alex Williamson --- drivers/pci/pci-sysfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index fc804e08e3cb..9ac92e6a2397 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1196,8 +1196,14 @@ static int pci_create_attr(struct pci_dev *pdev, int= num, int write_combine) res_attr->size =3D pci_resource_len(pdev, num); res_attr->private =3D (void *)(unsigned long)num; retval =3D sysfs_create_bin_file(&pdev->dev.kobj, res_attr); - if (retval) + if (retval) { + if (write_combine) + pdev->res_attr_wc[num] =3D NULL; + else + pdev->res_attr[num] =3D NULL; + kfree(res_attr); + } =20 return retval; }