Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9218924pxu; Mon, 28 Dec 2020 09:35:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxV8ypEz2PZsoCDPhUUewcD/Vr+kJriGyn1tXxNb1jlTDUXbVqgxZ6M7XQwEeNiVg1ITYNP X-Received: by 2002:a17:906:6d14:: with SMTP id m20mr41800193ejr.3.1609176947518; Mon, 28 Dec 2020 09:35:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609176947; cv=none; d=google.com; s=arc-20160816; b=LotOSEvwa2fKj2NnaRMFJdD4suLkfRxOIdLuRIsYyw9+GaKe854Pv9eLbg3IxeAy8t PPu6sZbaGM1mVZkIVcMIITI2xA0yU2Pa6mhC6bRZicUhuY6vJsHGoKQ1ceRkZxcwlPQ8 B+DBc+c52dUWHIiu/wniwt+wX3HZkPWCaAGEhPkkFEiRu75HQ9kpBfb95gvq4/QPAZLi Jz4vMmSi6jRTDbCnOAbvmehzszswCQOocKOhq2G+pTH9IBO0ch8+sgQa+YefAginEHP5 kU2o7nu86rd0skec4HpM/PKMQHGqIRTHQ6Gw4vX0fIOJVoZnOw6dQz+nDbiVVTrV741U 16aA== 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=MIa3nNClisK+UWkHwLxgSE3vlUnxnzANo5dWLZhtQ982qy6ic1B3eEE9k2cr1ATsCP 9hJQMA7pf7nd+ovFTjuUlm1ml/JWVSicSlRLv2md4bdYcfijMrQU1Lxbe/s1XPRd6LPR he7FI+X6sDBt63igwpTN2rVX5hX86SMA3gURgrnIKdes1d3IDcHWul2PGs8uT4f/IMXY n3kzMsDaOEUJt0bF2OzUQfX9pn1qVeE9PtIXu74JjoBsYgQSvNFk2yrYXhdyd+rGk4GJ 0tPDGEw0wyLu+OMCydkoI9OboDO+LJU69V29OJoHdwzuYq622oorlBfh1k+SPqU00wcU oykA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=18dLkgS8; 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 s20si12494378eji.387.2020.12.28.09.35.25; Mon, 28 Dec 2020 09:35:47 -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=18dLkgS8; 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 S1730763AbgL1NH5 (ORCPT + 99 others); Mon, 28 Dec 2020 08:07:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:35020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730771AbgL1NHV (ORCPT ); Mon, 28 Dec 2020 08:07:21 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C692E208BA; Mon, 28 Dec 2020 13:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160800; bh=0aLngOLlZjpxpVbTroKiMfMr9Wb/XUWSAoNOcIe9ss8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=18dLkgS81hIT+6U0IIm5wmfHe3uTzA8oWhkmyfU6l40AP1GW4YuPWHFa/qtltQlpn 6CQ4fgJuHrpALuib3Dw/HYFQ6Of3fz+s7YpMvdjSddhQCAdauIqWqdf8VEgjL6We+3 EK/goyd72TZnpmI/lFRmr5xigVwrV4cyuoAVeMYc= 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.9 175/175] PCI: Fix pci_slot_release() NULL pointer dereference Date: Mon, 28 Dec 2020 13:50:28 +0100 Message-Id: <20201228124901.716690755@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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)