Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4023655rwj; Tue, 20 Dec 2022 05:14:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf4X37BVYJENcgsLjAFHVt2OSj4vZgeH2tz3tgK4NfgsfDcHhnSF+MhTSyLvvGW3Tpgc72am X-Received: by 2002:a05:6a20:441e:b0:ac:16ae:1082 with SMTP id ce30-20020a056a20441e00b000ac16ae1082mr80219748pzb.32.1671542093151; Tue, 20 Dec 2022 05:14:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671542093; cv=none; d=google.com; s=arc-20160816; b=uXXXM6dIeFxrWGp5LiFT4RTgxxqCb2af5HpGXam0n7d9G65+i1MWv2Bx2x4TDdVr8U 1IVYKUkoyC8KuoleA5EZLdW1bvk/ICNeGQ3DAhcd4mqN8TtlgEbpCje+vB6tgWFxSI15 PZKe02+TWr4UK6T1gzlZvd7YP9d3M+S3COi7qULkUE2s/CToj3xHKRC4GlHLM57F4JRA VPHuUeVTS3Nj8oZbHYCwlQl/Wp6/0IxEW5DHC36aHjbB9hWFOM5+Z1e/QQ1JUV8ZTfCr xlNz46DVw5NERv9AbXpCUOo2rPe6YTInUoAUejLGlmYH5QBb26ltXHprbckti/tgKwWi jH8Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=vFwXBebNUlstJNleJj/+YwuX9WYFUWsusCZsNeUI/tI=; b=ExZZ1pz9bTIojnpt1X8D70f+ALiEr3nP3L7LbHUukUo/P9DjzVOLN0GTZcQcqVQmss gCYGfLPem63FEcCyt+3C5mjh2/1r2b57jS15CwyjS1ba5hQMI0wM6cBSQWeJp4fZovlL iiWemPXffKsGLokeeLtz16sKgsEs1VqCKuvu4nJTzoOlGFggtJ+bTLUmFwGVa3IiBFxm 2ETuY5rm7+u60obnb8XtyjCkSCDbDvn5VT8gcFh/RstXc7MKiPRkr9y9Nk4yIC/QU9Ph n4LMivWLzcDBonXCEMqV/amz3i3UpU6X5iQb3u5DF8Bz7dcDQ9TbLWsgO5ADstG5EUwR +asQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=P26cwXMr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a636b04000000b004782dc93af4si13037565pgc.307.2022.12.20.05.14.43; Tue, 20 Dec 2022 05:14:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=P26cwXMr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230146AbiLTM5H (ORCPT + 71 others); Tue, 20 Dec 2022 07:57:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiLTM5D (ORCPT ); Tue, 20 Dec 2022 07:57:03 -0500 Received: from forwardcorp1a.mail.yandex.net (forwardcorp1a.mail.yandex.net [178.154.239.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D24BBC29; Tue, 20 Dec 2022 04:57:01 -0800 (PST) Received: from vla5-b2806cb321eb.qloud-c.yandex.net (vla5-b2806cb321eb.qloud-c.yandex.net [IPv6:2a02:6b8:c18:3e0d:0:640:b280:6cb3]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTP id A85675FEA8; Tue, 20 Dec 2022 15:56:59 +0300 (MSK) Received: from d-tatianin-nix.yandex-team.ru (unknown [2a02:6b8:b081:b519::1:14]) by vla5-b2806cb321eb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id pukBv71RZ8c1-9pi6xWIM; Tue, 20 Dec 2022 15:56:59 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1671541019; bh=vFwXBebNUlstJNleJj/+YwuX9WYFUWsusCZsNeUI/tI=; h=Message-Id:Date:Cc:Subject:To:From; b=P26cwXMrMC1AmK/pAG1ea6we/Fx114ISiscz/reQIKWtSQMQRAfe4T1GEVXhwF2Ve PgT8lrWrjGhs/gL5rWPxSieC8+eM8TuwEgh0jtlCVmf2Cys2Zi1DdpjqSF/mJUjW66 HXc7Jdh8mGWdgHesa59oAalESOX1si+/mUpgtJtA= Authentication-Results: vla5-b2806cb321eb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Daniil Tatianin To: Shahed Shaikh Cc: Daniil Tatianin , Manish Chopra , GR-Linux-NIC-Dev@marvell.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] qlcnic: prevent ->dcb use-after-free on qlcnic_dcb_enable() failure Date: Tue, 20 Dec 2022 15:56:49 +0300 Message-Id: <20221220125649.1637829-1-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org adapter->dcb would get silently freed inside qlcnic_dcb_enable() in case qlcnic_dcb_attach() would return an error, which always happens under OOM conditions. This would lead to use-after-free because both of the existing callers invoke qlcnic_dcb_get_info() on the obtained pointer, which is potentially freed at that point. Propagate errors from qlcnic_dcb_enable(), and instead free the dcb pointer at callsite. Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. Signed-off-by: Daniil Tatianin --- drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c | 9 ++++++++- drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h | 5 ++--- drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 9 ++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c index dbb800769cb6..465f149d94d4 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c @@ -2505,7 +2505,14 @@ int qlcnic_83xx_init(struct qlcnic_adapter *adapter) goto disable_mbx_intr; qlcnic_83xx_clear_function_resources(adapter); - qlcnic_dcb_enable(adapter->dcb); + + err = qlcnic_dcb_enable(adapter->dcb); + if (err) { + qlcnic_clear_dcb_ops(adapter->dcb); + adapter->dcb = NULL; + goto disable_mbx_intr; + } + qlcnic_83xx_initialize_nic(adapter, 1); qlcnic_dcb_get_info(adapter->dcb); diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h index 7519773eaca6..e1460f9c38bf 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h @@ -112,9 +112,8 @@ static inline void qlcnic_dcb_init_dcbnl_ops(struct qlcnic_dcb *dcb) dcb->ops->init_dcbnl_ops(dcb); } -static inline void qlcnic_dcb_enable(struct qlcnic_dcb *dcb) +static inline int qlcnic_dcb_enable(struct qlcnic_dcb *dcb) { - if (dcb && qlcnic_dcb_attach(dcb)) - qlcnic_clear_dcb_ops(dcb); + return dcb ? qlcnic_dcb_attach(dcb) : 0; } #endif diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c index 28476b982bab..36ba15fc9776 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c @@ -2599,7 +2599,14 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) "Device does not support MSI interrupts\n"); if (qlcnic_82xx_check(adapter)) { - qlcnic_dcb_enable(adapter->dcb); + err = qlcnic_dcb_enable(adapter->dcb); + if (err) { + qlcnic_clear_dcb_ops(adapter->dcb); + adapter->dcb = NULL; + dev_err(&pdev->dev, "Failed to enable DCB\n"); + goto err_out_free_hw; + } + qlcnic_dcb_get_info(adapter->dcb); err = qlcnic_setup_intr(adapter); -- 2.25.1