Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9098420pxu; Mon, 28 Dec 2020 06:35:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWPn3lhMXtcYP6zKbFpH+xECyzBg5zSr+vERbh5AIKVGaTNY25D/9pDwNUA/+HEn+a8zv/ X-Received: by 2002:aa7:d297:: with SMTP id w23mr42575266edq.374.1609166159268; Mon, 28 Dec 2020 06:35:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609166159; cv=none; d=google.com; s=arc-20160816; b=lapPaIv2ZkN+wW3ATbsNCr1RazPmv/hp/GsAXFXa+xB1FQeCBzAvRLz/pGvartoaBK 3nz0brDm6OPirenjYCrAVK/0NqSEIpl03SlLWcjRacdsdeMxx/LupkaBH9VNBwuBF/WK VBQwMmVm3RKOGHtFeLp0GG1uYhwcOLu6nNRknriHtEcbS3MG4QyXjJ2RrAZ6F0MzbpRv qUAdYEbDWoervjXS5uuknO0xJTeCv3gcdrfwSY+HGtkbjriCcS6JvHjEexIF0GbJOOiO SFEyNIPi/WXGKBcPYJJt7dnWRMlwlEKyknXHQPbyepYynrc2YPbgjI7aZRJj3ZEmtIAK 0ENg== 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=G+Da5kkY2TZgKf77C5F5x85SBiBEJ5fWdw2/k/+rFi4=; b=0V5heksUSeYoi00yrr0NxfxwhhXoNuv6BZX0yNH9jA94aSKkkHAiFsd/hGKp9Xgoci Jf5xk9QRTDh/DKbw0bGRVQkPMVkhXK5YVBQJiO0gU5aN6kpbmYpeWxnR1uk5/i8ZLSBw CeeV/ZaWMtd9xkQgA9T5dDlL3QmA0UZQwniSPSadvfIdFoDqx78rAokZwhwFiVpaHwlc Wzwn8mHcpXcdrLaV9uCKPFK/r1zMxI3CR1OY/eIpGKU1M99OX+LovcihfCuGTa4PXbBB tIh0gUr0mkXVUJfB9zPqIfSA2xpRcmqJ5URSMeDspjQiwlsq/sihw2lna/lYiwMuJmBP ewyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lhITvIED; 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 i24si19857299edg.295.2020.12.28.06.35.36; Mon, 28 Dec 2020 06:35:59 -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=lhITvIED; 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 S2505058AbgL1Odi (ORCPT + 99 others); Mon, 28 Dec 2020 09:33:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:40476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504854AbgL1Oc7 (ORCPT ); Mon, 28 Dec 2020 09:32:59 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8860F20739; Mon, 28 Dec 2020 14:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165964; bh=gRy94s2sbUg0C1X15+6rKhNBxvvc770rBBVwx5EyJ28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lhITvIEDAIu2cmrAVOjQbq7Tr80DHypZVZcavNbTaewIKiJEosKWpE9YvEL6kGd9n Lw7hSi7g2LVCNhiKDtzCx/apdQYcNe0jrpgsYjoKsLeCVEgN39+zA2m8Sk3VUyXIM0 yHrjU7RL24FELfzEaWmLpfTEXDLWIV1x56ZkkTPQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jubin Zhong , Bjorn Helgaas Subject: [PATCH 5.10 710/717] PCI: Fix pci_slot_release() NULL pointer dereference Date: Mon, 28 Dec 2020 13:51:48 +0100 Message-Id: <20201228125055.010697113@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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 @@ -272,6 +272,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) { @@ -279,9 +282,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)