Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4067837rwj; Tue, 20 Dec 2022 05:49:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Dp1LRQHcBeqzlpuA+/ds+SgmMXfPC0nfiIHA7RA7woT6iQzJp1DVi44J8cbchqMU19Mcj X-Received: by 2002:a05:6402:268a:b0:46f:7453:b183 with SMTP id w10-20020a056402268a00b0046f7453b183mr46750527edd.13.1671544154210; Tue, 20 Dec 2022 05:49:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671544154; cv=none; d=google.com; s=arc-20160816; b=uBDUsSJ6HJzNeJaxNLYmdGFW2W7iVnDhohs4rLNbNkRL4HGcZo6/TaAR0asHZ1YCYg sAc9ScYq6fBYGuhDicOuLBMrVCuU2bXOD3FBwV3Mo8wBjwcsdwrYM/OJDQfkrPVeUsDP Qfwmf46QnS5v0FZEUFg264DEypTccBQh2XGjY9s1R0jhlKX1dCw5BdqEDDZdG6/WNa1c FALfGbpVherCgmQWYopxi7x0XE+bQbzi+wzKOM13WUPYFg6Zm+51q+KEi2i8UJg7//xV DgDrBkavOk2qGYcwdt3qqlOF22OkRKrcuuBT7bdvtXsbGq6hlqg3AWjnS9ILRlG48FJb zWxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1dqubes93mm8cxhRnYO7kClupZMx1xw79t95vabVOIA=; b=q44h5sdd/Sufkt418fkCNboamRX25crlvA7i+7eRGB0cLaJ++fDFTAJS68jYesERoV lnCbugPQho5aqgQWB7yVSRHo8G4F6rfeKCVR4hS52FKIAPCt88yBhRqY0E9ed0xyG512 BBxmd+YpgGZ8WAPVsdz1RhLqYzMLtdOGZpnbgZCJ7xAl9xDNWs8jD8UuD2JzZ8bS5IZ4 Kqqz4aldDVvIBqqrx6SzSuQhBfUZKWH0BbrX4GibwWkENOJd28Hzz/7nmGAxgyUMsIgc pKNp6jYnRiZ6t4uka4FJAaNe9NHcxECJTeQ+1BMDLXrrc16S+1HJN0LmtLcBeFnjwVdN 8zxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EBqswi5X; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a056402094800b0046125ddf5easi538349edz.185.2022.12.20.05.48.57; Tue, 20 Dec 2022 05:49:14 -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=@intel.com header.s=Intel header.b=EBqswi5X; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233462AbiLTNdA (ORCPT + 70 others); Tue, 20 Dec 2022 08:33:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbiLTNcy (ORCPT ); Tue, 20 Dec 2022 08:32:54 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D745A1BE; Tue, 20 Dec 2022 05:32:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671543173; x=1703079173; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=NoDHutZfIDRsf0ub0AOWtZ9DL1dRnfTbWJbUb3LNtiE=; b=EBqswi5XBW/bRJ/cGj2HhjTFVRW2BM54GOCAOsSuF6434HKynOJ02jR9 bvjPe7JSNDNTIzH4M6F0M+m/GtTGlWkJT386jUmdXlux2Yg3lSnH0UkBh UHHHzWBb/h2dWeJrp9iZaQebcx7qh3h4bMf60ALqWaNnBhdPEuuQjbtOO e+6/avtlH7DOrZ/+Lf5iCGy51DeW9aWP2BQGXZAuvtdUuRu094Ag9ZyIF 3tlrih0qlALD7X5+u2KoHtcjRYVBAHdWfrtzIIOP5py3rBX4iShCMhFMr uKcwX0ydTTRESs4wFeiLxM+6BuY8miXgFf8x7AdR0CekEzwQPLdmG1vSI Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="321515420" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="321515420" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 05:32:51 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="644426367" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="644426367" Received: from unknown (HELO localhost.localdomain) ([10.237.112.144]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 05:32:49 -0800 Date: Tue, 20 Dec 2022 14:32:41 +0100 From: Michal Swiatkowski To: Daniil Tatianin Cc: Shahed Shaikh , 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: Re: [PATCH v1] qlcnic: prevent ->dcb use-after-free on qlcnic_dcb_enable() failure Message-ID: References: <20221220125649.1637829-1-d-tatianin@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221220125649.1637829-1-d-tatianin@yandex-team.ru> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 On Tue, Dec 20, 2022 at 03:56:49PM +0300, Daniil Tatianin wrote: > 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 Please add Fix tag and net as target (net-next is close till the end of this year) > --- > 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; > + } Maybe I miss sth but it looks like there can be memory leak. For example if error in attach happen after allocating of dcb->cfg. Isn't it better to call qlcnic_dcb_free instead of qlcnic_clear_dcb_ops? > + > 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 >