Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3707384pxb; Mon, 24 Jan 2022 15:57:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxN3r/d9pJVsk8mTZpm0aUmwD+Yv7N2aasZldHj09sckGDtyHogfg1+ZBF3tCgchR97mCP2 X-Received: by 2002:a17:90b:4a47:: with SMTP id lb7mr758657pjb.58.1643068668431; Mon, 24 Jan 2022 15:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068668; cv=none; d=google.com; s=arc-20160816; b=N9/XWVqRKo/FXqRK3lGJoe5v8nnHZ/KuaKpsRGE3ZmW7SpH/h0WSgqehn6IQcukCyf hmYOCDhJzecSEYurbF7wJysOHaUGDFtJQMgtyDjzmjP1Q0vxjvvThvGnSzHiGdLZXRD2 SS8nRWRz56TQYMZ4RPSKey/iBU+W/oJNAX56di/xRcGiFq81+kBmDjT7g3PavFLHcTv9 Y9PliJ4TLgG371Y1ZxjZZSOuGZcLPkriajaP9ThfXA4BuA6KrhOTDBF1fxPuKvo49+gx kC0WD2YB9gpjW6tci37MqYA4TGxMHLdkMjxuU3KZXlMTCarcz6z8ojxAst8EiFHX7jqZ Kuog== 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=VgVJJXwn1apXaW1TCN3yKOLxYjjMmfBPZooi+TyRfNE=; b=D7T/BJGHhrh5Cj0ErbGvCjRRvnZ10e6WhO68E8eEhiWfXd2p7v9psFz/nKuE+QOAVp ZxbIAS8bZwjsDwLyAcBwyN8EqyF7HyCLurFZpE87DfSqcfuqfC3X4795JbiusspXVXSr dCkOE6WncVdSkwmcIHSEIGDQDRmz3rQwYw/a37YyEnQ/sh5x2iBrPE922LOhbrIahWgg P+B1athlb1/OY++si/gsAYozLdBtNmnp6kQ54EsMqyUJJrcFryuV+kKBM2vkyfVWnlNf 8CcZz3OYQsPFWRPp4NP666kA59GK9ug/UlRVsZzv3m/HhqL3a7cPi1YSQyuUkvOS/EJp 1ynw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rehNUeHj; 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 p13si643944pjg.100.2022.01.24.15.57.36; Mon, 24 Jan 2022 15:57:48 -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=rehNUeHj; 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 S2365788AbiAXXvm (ORCPT + 99 others); Mon, 24 Jan 2022 18:51:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1843476AbiAXXED (ORCPT ); Mon, 24 Jan 2022 18:04:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CF6DC06C5AE; Mon, 24 Jan 2022 13:15:18 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2C82861484; Mon, 24 Jan 2022 21:15:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AF4EC340E5; Mon, 24 Jan 2022 21:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058917; bh=StLZvHkPPjNWX2Zkf87Xunam5bpuvhcD5gKxOAP1LCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rehNUeHjYOlq1lAUKykXTH8FHqjZ0OCIUNPHm0gv/zAgQ/KM1ZqCU2kBxv0LrgLnn /8oPjocxA2z4xyszo4zeKh8wPbihbPzRoyZMkylovZsrewFwz+Tn/Awwer3LFRkg8I s8bNsWxp3PdGoQ2DiIssM/80iO+3cuZ0jXXFmCus= 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.16 0412/1039] net/mlx5: Fix access to sf_dev_table on allocation failure Date: Mon, 24 Jan 2022 19:36:41 +0100 Message-Id: <20220124184139.165179659@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 f37db7cc32a65..7da012ff0d419 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c @@ -30,10 +30,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