Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9232034pxu; Mon, 28 Dec 2020 09:59:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUaLButT+IcmV8CtNT4ra0DfQZg/eTKdLjXWPlYt7kstpXdEuPYjV9Bv/kyei5IVqLi2tu X-Received: by 2002:a17:906:2755:: with SMTP id a21mr37222057ejd.374.1609178347116; Mon, 28 Dec 2020 09:59:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609178347; cv=none; d=google.com; s=arc-20160816; b=hKf9KHxUDH698gk0//9xO/zXuOSMJrAVdH+I2q2CYOKschvL7aeqlnai1X2aV9qWu8 4buQWNbhNXL31ygR7mwXdAq9t8rAuisXyinFNzIHIM/kYihVZOEEMYlDrn6R+n/g1HSN q8fg101dUgd1rGz6GDt5qy8k32Uq8Aj7a5oV5shsi3BoE1sVNpwlr+lmQRT+j1reJXFG tAJxjUKBbjMkQoh3kaAiH1F44Y8aC3418s+UH7/PCWPYbwF1TstXE0GmD/29Tja3WoEG IBOQgxcM1bAdthulkxi0lmTxm03snIWQd74VeN47kpQZZvPps3uCUyaMjgbV6DBn5G3r La2g== 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=ac0VXVmVM3kkshbfOZSoqA/80LOFEdbPDF+/pqkjPy4=; b=KOTe660T3AlmzsJpr0ENPoZZE2Ujvf76C7nz6B79zwkbPYKdDs86You1DoNe1Q8Lxo 2bbWlYS0o29rL+TXJHxuKRSCSJV4Ttxs7UcTDipY2QNGBYjXGjcyw1H5w3Vo5MJQ1H7T 7kJ59FWL4wkLFbNR4zS37E0s2QWGVNPGBAKtr0lnR2xoYfDHLPMXG1bTBa2knWtuv6iE VHPmOSMb7EUpxsVwCwNisrFfwYz0xmXST+oWZrY8SohT8zQNLXYSrPao5CjRPt6uo18y IwLl1TMYZj78nG9QvL0OsOg80PPUWDIBAHN9Bv9+bHM0JhN5AfjRD/D3AefFGjPINUF+ 5xoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zaf/EMlj"; 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 jo25si19354472ejb.575.2020.12.28.09.58.44; Mon, 28 Dec 2020 09:59:07 -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="zaf/EMlj"; 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 S1732983AbgL1NTv (ORCPT + 99 others); Mon, 28 Dec 2020 08:19:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:48382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728256AbgL1NTr (ORCPT ); Mon, 28 Dec 2020 08:19:47 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E0B34207F7; Mon, 28 Dec 2020 13:19:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161546; bh=0aLngOLlZjpxpVbTroKiMfMr9Wb/XUWSAoNOcIe9ss8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zaf/EMljKigwOEqpiykrasLTQtyUd/uTnTdRy2mtSG29pYpzvGgUFbxdJ7su+JwDE XTFP3Q/0t0lmLvM8CVLV8WTjkg2PpctgP/4N5vUKHRJkb5mxB0sKMOzPy5oQDKL/Ov qy0HxiEiIzoCbI4usJRttCVJkmVoXXe+fX8Vwyj8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jubin Zhong , Bjorn Helgaas Subject: [PATCH 4.14 242/242] PCI: Fix pci_slot_release() NULL pointer dereference Date: Mon, 28 Dec 2020 13:50:47 +0100 Message-Id: <20201228124916.602815383@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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: Jubin Zhong commit 4684709bf81a2d98152ed6b610e3d5c403f9bced upstream. If kobject_init_and_add() fails, pci_slot_release() is called to delete slot->list from parent->slots. But slot->list hasn't been initialized yet, so we dereference a NULL pointer: Unable to handle kernel NULL pointer dereference at virtual address 00000000 ... CPU: 10 PID: 1 Comm: swapper/0 Not tainted 4.4.240 #197 task: ffffeb398a45ef10 task.stack: ffffeb398a470000 PC is at __list_del_entry_valid+0x5c/0xb0 LR is at pci_slot_release+0x84/0xe4 ... __list_del_entry_valid+0x5c/0xb0 pci_slot_release+0x84/0xe4 kobject_put+0x184/0x1c4 pci_create_slot+0x17c/0x1b4 __pci_hp_initialize+0x68/0xa4 pciehp_probe+0x1a4/0x2fc pcie_port_probe_service+0x58/0x84 driver_probe_device+0x320/0x470 Initialize slot->list before calling kobject_init_and_add() to avoid this. Fixes: 8a94644b440e ("PCI: Fix pci_create_slot() reference count leak") Link: https://lore.kernel.org/r/1606876422-117457-1-git-send-email-zhongjubin@huawei.com Signed-off-by: Jubin Zhong Signed-off-by: Bjorn Helgaas Cc: stable@vger.kernel.org # v5.9+ Signed-off-by: Greg Kroah-Hartman --- drivers/pci/slot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/pci/slot.c +++ b/drivers/pci/slot.c @@ -307,6 +307,9 @@ placeholder: goto err; } + INIT_LIST_HEAD(&slot->list); + list_add(&slot->list, &parent->slots); + err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL, "%s", slot_name); if (err) { @@ -314,9 +317,6 @@ placeholder: goto err; } - INIT_LIST_HEAD(&slot->list); - list_add(&slot->list, &parent->slots); - down_read(&pci_bus_sem); list_for_each_entry(dev, &parent->devices, bus_list) if (PCI_SLOT(dev->devfn) == slot_nr)