Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3663290pxb; Mon, 24 Jan 2022 14:47:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcZsiiEBxLLDXC0NMa0sJbrzxPx9hbwZV8wNj3KcH4K0dbNwx9r+PEwZHFBuW8sHbFA1wK X-Received: by 2002:a17:902:74c7:b0:14a:e071:8ce3 with SMTP id f7-20020a17090274c700b0014ae0718ce3mr16149152plt.108.1643064446724; Mon, 24 Jan 2022 14:47:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064446; cv=none; d=google.com; s=arc-20160816; b=JEVomG+Fs5w9Lwbj8imuKmR7mdZ4cOixRBMbNv48yz587eVABLHaW8kLwHhYDMje2z 6Lb32xwwdl+ODlBK1uwXU4lC7JHC6BvPAE874X9DDZZdxF20aKiGwpP05lulS81BEdQc w8UfHulDyKSF+p41txPaPK23Uc5bMPHTP0Ggl9pBXdasfGqsw26sSg/u6f8EIKqPI1rn qqgee/Xcl9xCR+L9JohFuD8P34MHir+4vudbEyVyT7zINnZDNJLJo6TUO067DdhyWu9p rWjUYeJIJp8QUZac6YuiI2u5uU2ZrYRefhWwweR3ltP9bTFXBd4AAc+MjQmiGnAMBU90 5roQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2cKDkYBTBqyIc3FdNpLO3R3LPF/FShNOkmyPPHCs5Bc=; b=n6adIC6tLVZiZHbfWhMAtoW1X/ZuuZkH/YF+C0/ZMzp2XdX65Jxvnxrbqyh9Z69kFQ jq6RuGiKRPk3Pxn6m5f96FloTWbKfSb9qxzjMGFLc6D5JGaCbsotWKwvNZWgRHQHyjD9 ZK+S7WntBojCoFjWJQ5rRHHl6OuCkKNkay1l/ktxkMzVEZMHvpWYKKFQ3WcOMp0qDQ3/ S4+lnzXyX2sH8E7yrVolf6OvZOjKP2vXMkUZ5aCFniXqHUeSZe2sz1Gy0BME30Mgk03q XzDqPsRiFXDyQwC2y2PpAkBn9AZs567TxNfQQzK3i6YK4ViDCr6RahmMADmZY49yQqjx DQQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lqZhcvMM; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f22si15330863pgn.441.2022.01.24.14.47.14; Mon, 24 Jan 2022 14:47:26 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=lqZhcvMM; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1837566AbiAXWot (ORCPT + 99 others); Mon, 24 Jan 2022 17:44:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1456715AbiAXVjy (ORCPT ); Mon, 24 Jan 2022 16:39:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 828F6C0419CD; Mon, 24 Jan 2022 12:26:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 27D8BB8122F; Mon, 24 Jan 2022 20:26:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40336C340E5; Mon, 24 Jan 2022 20:26:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056016; bh=1PybLUB2+DcUQg1vl2n3BluKdz3jaZoo+BtLc1Ze5oI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lqZhcvMMpJGxfMdpbaI6fcunk2PE+/D3GmDu+BJPtZ3fHZL06ceLGlRQrCHh4ILcj dTL2JKyUPmGWyP06Q02esZux7I0bCAs1Qyum8lpFfZpcQ9z4b627SbG/CYXYMZDZgk HcXTFa4pjHZK+F+vUGy08Sg/Jtb8VvfhflW747Kg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shay Drory , Parav Pandit , Saeed Mahameed , Sasha Levin Subject: [PATCH 5.15 343/846] net/mlx5: Fix access to sf_dev_table on allocation failure Date: Mon, 24 Jan 2022 19:37:40 +0100 Message-Id: <20220124184112.755779053@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shay Drory [ Upstream commit a1c7c49c2091926962f8c1c866d386febffec5d8 ] Even when SF devices are supported, the SF device table allocation can still fail. In such case mlx5_sf_dev_supported still reports true, but SF device table is invalid. This can result in NULL table access. Hence, fix it by adding NULL table check. Fixes: 1958fc2f0712 ("net/mlx5: SF, Add auxiliary device driver") Signed-off-by: Shay Drory Reviewed-by: Parav Pandit Signed-off-by: Saeed Mahameed Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c index 871c2fbe18d39..64bbc18332d56 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c @@ -28,10 +28,7 @@ bool mlx5_sf_dev_allocated(const struct mlx5_core_dev *dev) { struct mlx5_sf_dev_table *table = dev->priv.sf_dev_table; - if (!mlx5_sf_dev_supported(dev)) - return false; - - return !xa_empty(&table->devices); + return table && !xa_empty(&table->devices); } static ssize_t sfnum_show(struct device *dev, struct device_attribute *attr, char *buf) -- 2.34.1