From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384747; b=T6IM+SDpvAbf4RiSiwgUoqjGHBwzMMZ9TbXE3eNeWFhCDhlfpMLwoacGDVOV/G2SfS88 PkeC74Nem6gGgDhGq0XMwO9WFlznPw+0HjOBypMG/GKMXnONDIiFRaoxdCA2a/vDPQdaX G/5sXuumA6XwPEH8CZ5zKF0glAqV5wJCRcM2bje4YRHnVA4Wxzo6uSeJRlJTwJr1m/IeY +wkuXodXx1tjGj8TPj+bTT99s/odtYoGgvweT6vh19voCwnZC18VhjZuBgh5FAukf/yap uoG7N4aH0RR59vCzx3gzkQCkZtZbMTKLWw+19E3VA4HZ6JcQAuM6KpX1l6izKWURnxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384747; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=i5p7zO9UID+gaA7kkKFPdfcWAb3Kcu1g+NYJj5YJ0EY=; b=w29TDosOyeGFwEoHvkx/7B5zReLWfFdDcxvbtzpS8G1MnMBI6lzQCFAJbsOAkGueN/QS lvTND9SnTTcfczr6eKkUcGSWQQwa9QVHc3m1clBSerUYYpGWaGM9iT5iPnZHEgeEaJp0A pXd29iEGR11nlCuOuKyzccMwUZl+wMPs9Zethi6mtGQ4kTy5LFjmL6hFxuwFHadJUFQNM XOth225iKSRVOZ+0ORFVRSTBtTe9rWcUgN05lMGf3KAnFN1CIp/cg0NBk70YagTs0R38p a0scOOqLBdWTSfm7BVjrFn5zN0R8cBJd/M0xuq/xM/DUIDkRvwNSZnfN7e3vaOr/idA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=MfkA+Z1i; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDDEF606A32D; Fri, 4 Dec 2026 11:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=MfkA+Z1i Received: by smtp.kernel.org (Postfix) with ESMTPSA id 666A21F000CE; Fri, 4 Dec 2026 11:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384746; bh=i5p7zO9UID+gaA7kkKFPdfcWAb3Kcu1g+NYJj5YJ0EY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MfkA+Z1i/gz4aFk7vyKLAt5Lh//PYSx+q+CX6LiYt3t2MPIFNN3bLS6PQ4chRCObt InDlhxIvPOJPZsSMkyBOBY5OIrfyJ28bY/kgzlCimZHZVGSW7KGv92k8sTnxoVbA/6 kWy/lSze8JwMbjvsIoNKgA5WL6GbToZC2FFlyqU4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Changyul Lee , Tariq Toukan , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0239/1167] net/mlx5: macsec: Dont remove fs_id when adding a rule fails Date: Fri, 4 Dec 2026 18:54:26 +0900 Message-ID: <20261204100708.296156831@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Changyul Lee [ Upstream commit 5175da73dd128520ad6d704d7fe54926ee5f658b ] macsec_fs_tx_add_rule() and macsec_fs_rx_add_rule() clean up a failed rule with macsec_fs_{tx,rx}_del_rule(), which also calls macsec_fs_id_del(). The fs_id is never in the xarray at that point: macsec_fs_id_add() is the last step of adding a rule and removes its own entry when it fails. macsec_fs_id_del() then dereferences NULL, through macsec_device for the first SA of a MACsec netdev and through fs_id_found otherwise. On RX, the SAs of one SC share an fs_id, so a failure while adding another SA drops the reference that an existing SA holds. Split the rule teardown from the fs_id removal and do only the teardown on the error paths. Fixes: d4ece08f4b1d ("net/mlx5: Maintain fs_id xarray per MACsec device inside macsec steering") Signed-off-by: Changyul Lee Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20261105003419.4016283-1-lcy8047@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- .../mellanox/mlx5/core/lib/macsec_fs.c | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c index 3d2473d9f3eac..41cf27867fa85 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c @@ -768,13 +768,9 @@ static int macsec_fs_id_add(struct list_head *macsec_devices_list, u32 fs_id, return err; } -static void macsec_fs_tx_del_rule(struct mlx5_macsec_fs *macsec_fs, - struct mlx5_macsec_tx_rule *tx_rule, - void *macdev) +static void macsec_fs_tx_free_rule(struct mlx5_macsec_fs *macsec_fs, + struct mlx5_macsec_tx_rule *tx_rule) { - macsec_fs_id_del(&macsec_fs->macsec_devices_list, tx_rule->fs_id, macdev, - &macsec_fs->sci_hash, true); - if (tx_rule->rule) { mlx5_del_flow_rules(tx_rule->rule); tx_rule->rule = NULL; @@ -795,6 +791,15 @@ static void macsec_fs_tx_del_rule(struct mlx5_macsec_fs *macsec_fs, macsec_fs_tx_ft_put(macsec_fs); } +static void macsec_fs_tx_del_rule(struct mlx5_macsec_fs *macsec_fs, + struct mlx5_macsec_tx_rule *tx_rule, + void *macdev) +{ + macsec_fs_id_del(&macsec_fs->macsec_devices_list, tx_rule->fs_id, macdev, + &macsec_fs->sci_hash, true); + macsec_fs_tx_free_rule(macsec_fs, tx_rule); +} + #define MLX5_REFORMAT_PARAM_ADD_MACSEC_OFFSET_4_BYTES 1 static union mlx5_macsec_rule * @@ -887,7 +892,7 @@ macsec_fs_tx_add_rule(struct mlx5_macsec_fs *macsec_fs, goto out_spec; err: - macsec_fs_tx_del_rule(macsec_fs, tx_rule, macsec_ctx->secy->netdev); + macsec_fs_tx_free_rule(macsec_fs, tx_rule); macsec_rule = NULL; out_spec: kvfree(spec); @@ -1652,15 +1657,11 @@ static void macsec_fs_rx_ft_put(struct mlx5_macsec_fs *macsec_fs) macsec_fs_rx_destroy(macsec_fs); } -static void macsec_fs_rx_del_rule(struct mlx5_macsec_fs *macsec_fs, - struct mlx5_macsec_rx_rule *rx_rule, - void *macdev, u32 fs_id) +static void macsec_fs_rx_free_rule(struct mlx5_macsec_fs *macsec_fs, + struct mlx5_macsec_rx_rule *rx_rule) { int i; - macsec_fs_id_del(&macsec_fs->macsec_devices_list, fs_id, macdev, - &macsec_fs->fs_id_hash, false); - for (i = 0; i < RX_NUM_OF_RULES_PER_SA; ++i) { if (rx_rule->rule[i]) { mlx5_del_flow_rules(rx_rule->rule[i]); @@ -1678,6 +1679,15 @@ static void macsec_fs_rx_del_rule(struct mlx5_macsec_fs *macsec_fs, macsec_fs_rx_ft_put(macsec_fs); } +static void macsec_fs_rx_del_rule(struct mlx5_macsec_fs *macsec_fs, + struct mlx5_macsec_rx_rule *rx_rule, + void *macdev, u32 fs_id) +{ + macsec_fs_id_del(&macsec_fs->macsec_devices_list, fs_id, macdev, + &macsec_fs->fs_id_hash, false); + macsec_fs_rx_free_rule(macsec_fs, rx_rule); +} + static void macsec_fs_rx_setup_fte(struct mlx5_flow_spec *spec, struct mlx5_flow_act *flow_act, struct mlx5_macsec_rule_attrs *attrs, @@ -1837,7 +1847,7 @@ macsec_fs_rx_add_rule(struct mlx5_macsec_fs *macsec_fs, return macsec_rule; err: - macsec_fs_rx_del_rule(macsec_fs, rx_rule, macsec_ctx->secy->netdev, fs_id); + macsec_fs_rx_free_rule(macsec_fs, rx_rule); macsec_rule = NULL; out_spec: kvfree(spec); -- 2.53.0