Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1688299pxj; Wed, 19 May 2021 11:30:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxT4GFzdcPF9J7lXXUnwoSGchFM3hjLXPllDb217U1QZIrsuTbFcT/FUe2lUGU6/xgISX2H X-Received: by 2002:aa7:da8e:: with SMTP id q14mr419637eds.13.1621449003761; Wed, 19 May 2021 11:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621449003; cv=none; d=google.com; s=arc-20160816; b=vdjsqo0xtrSD6ISRUkg8ZYI1nXPkHVAThIhenmuhxrLBAqE/YL28Q+ZydmpWg9uNI6 3exet4zM4WofvIKdOSjfDCHACqmro2YN+Jp5m/TVphR3L7CFJMY+udzS6Vg7nFYCVKel raTwPfqi66/KZbKIgo99luW8kzRWUevH8G14K1ssNZvJSaKOWifAfMgEiKfB9JGg3FEq OllP/WD24wX0FPeOjyrRmK0eAt8Lxd+ibH1MJMy6kbTR8z4aTpj8OIHwDiforSU7ftOy ytspk2GAQ4FUq7KQrQIUb1dZzqE1llkTydEVm7PuSxn0Y3gPnSlKN0Pcxihw8SNZBnL4 J8OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:cc:subject:from:to; bh=3VF5z8EOO0eSYGI/86FHJLM7L9DXcfwP8T/8+xJp2N8=; b=QauNY+OijXDclYQVaF/vtCq1zgxxa+JKjGccKf7VwBHgsdiyX+x5LFMjHomReNbB5r alz7bENpf3/woqfiKThOak8wrH/wsbEqVErJZoHulq0O8ewVQNgH+hm1EQubQ07OsNIt KP/7VYyctDNSBxu62nonmVIs4ObV5XhUuIl7VToVh0ApPrFf4P7xou3EFEVeQ798PJ8g qouo24w/kx9JCz1bDNLg5ruI2AAGfJtOf77ikK7mGEh6bNNHFXN+HLCM9eLzawWL9ona BWbeYWfjroJww2OWeyrDNQjykx0AGF3wB33hoqm2jtSg9LOR6o5k7ktyv3nGGWiIymYc 4bYQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si392667ejl.393.2021.05.19.11.29.39; Wed, 19 May 2021 11:30:03 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347178AbhERSdb (ORCPT + 99 others); Tue, 18 May 2021 14:33:31 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58911 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234536AbhERSdb (ORCPT ); Tue, 18 May 2021 14:33:31 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lj4Vo-0006zx-1L; Tue, 18 May 2021 18:32:12 +0000 To: Tong Zhang , Greg Kroah-Hartman From: Colin Ian King Subject: re: misc: alcor_pci: fix null-ptr-deref when there is no PCI bridge Cc: Arnd Bergmann , "linux-kernel@vger.kernel.org" Message-ID: Date: Tue, 18 May 2021 19:32:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Static analysis on linux-next with Coverity has detected an issue in drivers/misc/cardreader/alcor_pci.c in function alcor_pci_init_check_aspm with the following commit: commit 3ce3e45cc333da707d4d6eb433574b990bcc26f5 Author: Tong Zhang Date: Thu May 13 00:07:33 2021 -0400 misc: alcor_pci: fix null-ptr-deref when there is no PCI bridge The analysis is as follows: 135 static void alcor_pci_init_check_aspm(struct alcor_pci_priv *priv) 136 { 137 struct pci_dev *pci; 138 int where; 139 u32 val32; 140 141 priv->pdev_cap_off = alcor_pci_find_cap_offset(priv, priv->pdev); 142 /* 143 * A device might be attached to root complex directly and 144 * priv->parent_pdev will be NULL. In this case we don't check its 145 * capability and disable ASPM completely. 146 */ 1. Condition !priv->parent_pdev, taking true branch. 2. var_compare_op: Comparing priv->parent_pdev to null implies that priv->parent_pdev might be null. 147 if (!priv->parent_pdev) Dereference after null check (FORWARD_NULL) 3. var_deref_model: Passing null pointer priv->parent_pdev to alcor_pci_find_cap_offset, which dereferences it. 148 priv->parent_cap_off = alcor_pci_find_cap_offset(priv, 149 priv->parent_pdev); When !priv->parent_pdev is true, then priv->parent_pdev is NULL and hence the call to alcor_pci_find_cap_offset() is dereferencing a null pointer in the priv->parent_pdev argument. I suspect the logic in the if statement is inverted, the ! should be removed. This seems too trivial to be wrong. Maybe I'm missing something deeper. Colin