Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1691301pxj; Wed, 19 May 2021 11:33:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN92nZSE21iVz+V/3grJ8M7dDQeG2Sjw3tmz5tQftpxEKBBwStp2jM6LWzaA/KgCIL/t3W X-Received: by 2002:aa7:c9cf:: with SMTP id i15mr478702edt.4.1621449239625; Wed, 19 May 2021 11:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621449239; cv=none; d=google.com; s=arc-20160816; b=KJnkHdvj/6rbcBTzqRO0BBA8lm1TvuqxgGjvlEhcdnyqCNunhUJVP4SFcErsL+4zeQ +KEBnvqeq/ztxdqKeJJ6Zrl0mSl+pPJ7gOT4hw4kphBOjBtr1xEBqWjQjnabFsZUyp0N dIb2AX5u7W2x9WffNFoqnzinQzhVwx2XgIcXbeASYSjdxIZECuwNV9cczEnCrk2/3zpP yPElrRDEPZGOXzEDdh4FDMlnjLZv5SSjoPL/wD6+KPMaKlqeYLLfUnPPcp4BQkwbE/pB 9/o7hN2oa4Y67rBUlOncT9/oWRMoDlnnYQaePb2cW+xwKCXbpBSP0FcYtO+HUhFAxloV g7Og== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Rsvs60aN2Tn4zdMpprOFok80g2REFGU9zS+Btntv1Ps=; b=iMLdfM+C5P3hCmonuCVQsbQ2Pnugh0Kxcakco/JtbgnBFAcUAzlXSbTNFzKw0jJND9 rtupp1YYFD7i54vofkr1SqKIqWPdavq/VFtuFaC9AJKTHX8dIYbJM2IupDPbsSIwsHfN b244mYxbf4yMXPVH9uvFx4hDntwniyHgit2OIJb/T3MAV3OmIgwAe7QtpmeJ2saVboys 1DD5pEfs6hrPWs7If+oAMMe9WfMWrN+INRvId5WQCCQjiFrsjON2FEaJeG7zLogUvHwI q7MUJR/l9g119/wniX7JlfFTTFDqnkqxhTKSXRI5mFpD0F5S4awAEn2yk+Ygpc9A5VFB Lxvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=masGlSlS; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qh17si341069ejb.127.2021.05.19.11.33.35; Wed, 19 May 2021 11:33:59 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=masGlSlS; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351776AbhERTaH (ORCPT + 99 others); Tue, 18 May 2021 15:30:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232056AbhERTaG (ORCPT ); Tue, 18 May 2021 15:30:06 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6352AC061573 for ; Tue, 18 May 2021 12:28:47 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id g24so6052155pji.4 for ; Tue, 18 May 2021 12:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rsvs60aN2Tn4zdMpprOFok80g2REFGU9zS+Btntv1Ps=; b=masGlSlSWJ0TJs2SaAcTU0IGJlrLidnaTsVPqVpcnKVXQerKu+8jiJLAbkYcPRmFKl 58KvTFEL4r1cudFwviocinQq/lQyiSvzBWLO0xd3b9+PYWhokcVzQWcNpqzjpdcBK9jx pYqRCMesiksTohv867v7qQjuj/4dfNbRQZetz76Z9brfIiIXKA3EO2NNpdfgRD43kCQZ GrcSJmEtmu26E/S6EeDlCEGyypoDzrsQ7PB5IAanYF9woMp40Tc3+YISv6ssj33ZyVwX /mOeAlwpauZWuAd96KildXdwpoQqWpRwPfGVDIlI0iZVTIdiihIDeLKzQsTShuuzYGUT KOyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rsvs60aN2Tn4zdMpprOFok80g2REFGU9zS+Btntv1Ps=; b=QJ6cgo1Vbrsb72990VUwWq7RcHaVEhVbfnJjd4ATmcQnedthuFCEBOtJ3kKFdesCoj 3Pn4YWaFvTPYR2KomAG6uqpQa9YN7CNTuOsDO5Y8xWiAlFp4wcHoGqSQM15ZEQ+BjkyF MaXPHbjhzYPUO0Gh4QKwQqE9JPkPdIUdSE3rHVhP84kbsoTwy9UavZVMWdKGEsJCNWm4 SPJ61H/ebMJzY5hmQm5FahaArDKBpSrWu76/zZh4ajRt2AzWpHXGw/JvOJgyT22/E2Qp MReAk0imSsfQh24SQhcDoVA56TSZuKTlG6BfFFoM4VcyLE/qmQGlubN4Hh7Q4/uhIn1B hw3w== X-Gm-Message-State: AOAM531NkvenvyfQKj1OumqGe4p11+Oa2nq+ho5SUKRNCPwEy24lOspo 8VPB0a51JSMFFFaF0SS9Uy6odBLjw3pmHhyS X-Received: by 2002:a17:902:b68c:b029:e6:bb9f:7577 with SMTP id c12-20020a170902b68cb02900e6bb9f7577mr6318048pls.0.1621366126750; Tue, 18 May 2021 12:28:46 -0700 (PDT) Received: from tong-desktop.local ([2601:647:4200:13:45d1:3e2e:2ae6:a74]) by smtp.googlemail.com with ESMTPSA id t15sm1814970pjh.0.2021.05.18.12.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 12:28:46 -0700 (PDT) From: Tong Zhang To: Arnd Bergmann , Greg Kroah-Hartman , Tong Zhang , linux-kernel@vger.kernel.org Cc: Colin Ian King Subject: [PATCH v4] misc: alcor_pci: fix null-ptr-deref when there is no PCI bridge Date: Tue, 18 May 2021 15:28:18 -0400 Message-Id: <20210518192820.181500-1-ztong0001@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is an issue with the ASPM(optional) capability checking function. A device might be attached to root complex directly, in this case, bus->self(bridge) will be NULL, thus priv->parent_pdev is NULL. Since alcor_pci_init_check_aspm(priv->parent_pdev) checks the PCI link's ASPM capability and populate parent_cap_off, which will be used later by alcor_pci_aspm_ctrl() to dynamically turn on/off device, what we can do here is to avoid checking the capability if we are on the root complex. This will make pdev_cap_off 0 and alcor_pci_aspm_ctrl() will simply return when bring called, effectively disable ASPM for the device. [ 1.246492] BUG: kernel NULL pointer dereference, address: 00000000000000c0 [ 1.248731] RIP: 0010:pci_read_config_byte+0x5/0x40 [ 1.253998] Call Trace: [ 1.254131] ? alcor_pci_find_cap_offset.isra.0+0x3a/0x100 [alcor_pci] [ 1.254476] alcor_pci_probe+0x169/0x2d5 [alcor_pci] Signed-off-by: Tong Zhang Co-developed-by: Greg Kroah-Hartman Co-developed-by: Colin Ian King --- v2: check before calling alcor_pci_find_cap_offset() v3: Add comment. Enable the dev_dbg() output when priv->parent_pdev is NULL. v4: fix inverted if statement, thanks to Colin drivers/misc/cardreader/alcor_pci.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/misc/cardreader/alcor_pci.c b/drivers/misc/cardreader/alcor_pci.c index cd402c89189e..de6d44a158bb 100644 --- a/drivers/misc/cardreader/alcor_pci.c +++ b/drivers/misc/cardreader/alcor_pci.c @@ -139,7 +139,13 @@ static void alcor_pci_init_check_aspm(struct alcor_pci_priv *priv) u32 val32; priv->pdev_cap_off = alcor_pci_find_cap_offset(priv, priv->pdev); - priv->parent_cap_off = alcor_pci_find_cap_offset(priv, + /* + * A device might be attached to root complex directly and + * priv->parent_pdev will be NULL. In this case we don't check its + * capability and disable ASPM completely. + */ + if (priv->parent_pdev) + priv->parent_cap_off = alcor_pci_find_cap_offset(priv, priv->parent_pdev); if ((priv->pdev_cap_off == 0) || (priv->parent_cap_off == 0)) { -- 2.25.1