Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1045224AbdDWMIN (ORCPT ); Sun, 23 Apr 2017 08:08:13 -0400 Received: from m50-132.163.com ([123.125.50.132]:60823 "EHLO m50-132.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1044932AbdDWMID (ORCPT ); Sun, 23 Apr 2017 08:08:03 -0400 From: Pan Bian To: Harish Patil , Manish Chopra , Dept-GELinuxNICDev@cavium.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] qlcnic: fix unchecked return value Date: Sun, 23 Apr 2017 20:04:04 +0800 Message-Id: <1492949044-23580-1-git-send-email-bianpan201602@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DNGowAAX0+LlmPxYojklAA--.896S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xr4xWFyDCr4DWrW5Kr17KFg_yoWkXwc_KF 15ZFyfJw45Cr98Kw43tw43X34F93WDZ3Z5Aay0gay5Jw1DAa1jyr1vqF92qr9rWayxur9r Ww1aya43Cw12yjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUnWKZPUUUUU== X-Originating-IP: [123.118.194.153] X-CM-SenderInfo: held01tdqsiiqwqsqiywtou0bp/xtbBlwrC4FSIUCmOpQAAsx Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1047 Lines: 28 From: Pan Bian Function pci_find_ext_capability() may return 0, which is an invalid address. In function qlcnic_sriov_virtid_fn(), its return value is used without validation. This may result in invalid memory access bugs. This patch fixes the bug. Signed-off-by: Pan Bian --- drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c index d710705..2f656f3 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c @@ -128,6 +128,8 @@ static int qlcnic_sriov_virtid_fn(struct qlcnic_adapter *adapter, int vf_id) return 0; pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV); + if (!pos) + return 0; pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &offset); pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &stride); -- 1.9.1