From nobody Thu Oct 10 10:00:07 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XPQGv5kpkz5YmPW; Thu, 10 Oct 2024 10:00:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XPQGv5C9sz4s5y; Thu, 10 Oct 2024 10:00:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728554407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=t1AFXqUYk8MLNVJsbmb3c1Ft7IWELiVVRz4j6iA5pi0=; b=aO8f/Q0dFW0BTdjmAQj4G9MB/VpzYPJBmSQWW83XMHVAupImRG+0Zg46DXEdC4tEKk72SC QK8fupYX70If55ytdtLLiY/z7e9C7iqHJShsIeUXy4E2UqTlt0A1/O/7AlIX06LQkdadtT c5ZDDpAOF9BfVROoubjSpOQOwjaAEeLjipVRQyip4H4yJ403QkXVkDKicR9J8r9XYuP9Aw c2MJZd7SB5FSfHYvFzNexTWQXe7G0jtqFV06shMdLakI4NPBwJ6vJUB0sNyF20VCrYzqxk SqQPXC7YIirzjDsoMXudyUccKL3ht8bboRfKlwXMAPcoYv/6WBTNEfv03w6byg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728554407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=t1AFXqUYk8MLNVJsbmb3c1Ft7IWELiVVRz4j6iA5pi0=; b=NRFSzRktiy0IZF/skytdOK1tGY5k1YB2Le6bNd6fGz5n6crEHIaSt4MUXXz80yUCLzHyuc Znr+3bwUu3rmcfyXwThWxY9KAmic4MPrHYLrB8J1knVqX9nRJoJW2xGH9i3PfD9cb3q2j8 ITdcf2ZS9TqEodPG5v/iIOxyhbocTjyPY4Anl57OVpwD62ouAYbQHuLVh/xwLGx6Br3vpC eTl6EVeUW2W0R43JnUyNggCYiBmQwv3vkqeo+qC577Ne+sWQxBM7FzB4xa8Jyb44FBL7qo EAC3Mlnr1KNtLyzmGyISpckVhCCqV3irT31/NN/P91gusuzfSbVDUyTJAp8Qyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728554407; a=rsa-sha256; cv=none; b=UZ8yikqNHg/1+seIDOC+jGWS3UMa1Wi6Q1OLo7xWlM37uJB5fEmJ+bXPwxz+sqyf6FZLAQ lz1gYYcxsyCAVhHbUR7fUJuyYhzQy0XXO8rz5jkRHMIgBeO7fWltONqf5cDb3wjyCLQY6M HpFJCH93CqXLizIhg8Kio9StOPE27DyFFxkm/7h/rTZJy09RTsNMPzgqPs6glIn2Q8Bkep zlMFS3htIt7ExDE2WtLnQGr0EE9A8SLajbg3i5jozw4BBw0KsTuuYvhrzT8M7VGXkwpjif WAVTy71bslPY6uU9SFf6/aliTlaMIRnE9vg73Xj5Dn09oKSDXtdcoh5Tum3m+w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XPQGv4mGrzsdJ; Thu, 10 Oct 2024 10:00:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49AA07Mx039877; Thu, 10 Oct 2024 10:00:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49AA07wh039872; Thu, 10 Oct 2024 10:00:07 GMT (envelope-from git) Date: Thu, 10 Oct 2024 10:00:07 GMT Message-Id: <202410101000.49AA07wh039872@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 2851aafe96c1 - main - mlx5 ipsec_offload: ensure that driver does not dereference dead sahindex List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2851aafe96c1e357971f2b331fff837ead20522b Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=2851aafe96c1e357971f2b331fff837ead20522b commit 2851aafe96c1e357971f2b331fff837ead20522b Author: Konstantin Belousov AuthorDate: 2024-09-28 23:17:05 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-10 09:55:45 +0000 mlx5 ipsec_offload: ensure that driver does not dereference dead sahindex Take the sahtree rlock and check for the DEAD SA state before validating and filling the SA xfrm attributes. Sponsored by: NVidia networking --- sys/dev/mlx5/mlx5_accel/mlx5_ipsec.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/dev/mlx5/mlx5_accel/mlx5_ipsec.c b/sys/dev/mlx5/mlx5_accel/mlx5_ipsec.c index a25ed4c1c51f..95afec40d4f6 100644 --- a/sys/dev/mlx5/mlx5_accel/mlx5_ipsec.c +++ b/sys/dev/mlx5/mlx5_accel/mlx5_ipsec.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -257,6 +258,8 @@ static int mlx5e_xfrm_validate_state(struct mlx5_core_dev *mdev, mlx5_core_err(mdev, "FULL offload is not supported\n"); return (EINVAL); } + if (savp->state == SADB_SASTATE_DEAD) + return (EINVAL); if (savp->alg_enc == SADB_EALG_NONE) { mlx5_core_err(mdev, "Cannot offload authenticated xfrm states\n"); return (EINVAL); @@ -325,6 +328,7 @@ mlx5e_if_sa_newkey_onedir(struct ifnet *ifp, void *sav, int dir, u_int drv_spi, struct mlx5e_ipsec_sa_entry **privp, struct mlx5e_ipsec_priv_bothdir *pb, struct ifnet *ifpo) { + struct rm_priotracker tracker; struct mlx5e_ipsec_sa_entry *sa_entry = NULL; struct mlx5e_priv *priv = if_getsoftc(ifp); struct mlx5_core_dev *mdev = priv->mdev; @@ -338,7 +342,9 @@ mlx5e_if_sa_newkey_onedir(struct ifnet *ifp, void *sav, int dir, u_int drv_spi, if (if_gettype(ifpo) == IFT_L2VLAN) VLAN_TAG(ifpo, &vid); + ipsec_sahtree_rlock(&tracker); err = mlx5e_xfrm_validate_state(mdev, sav); + ipsec_sahtree_runlock(&tracker); if (err) return err; @@ -353,7 +359,14 @@ mlx5e_if_sa_newkey_onedir(struct ifnet *ifp, void *sav, int dir, u_int drv_spi, sa_entry->ipsec = ipsec; sa_entry->vid = vid; + ipsec_sahtree_rlock(&tracker); + err = mlx5e_xfrm_validate_state(mdev, sav); + if (err != 0) { + ipsec_sahtree_runlock(&tracker); + goto err_xfrm; + } mlx5e_ipsec_build_accel_xfrm_attrs(sa_entry, &sa_entry->attrs, dir); + ipsec_sahtree_runlock(&tracker); err = mlx5e_ipsec_create_dwork(sa_entry, pb); if (err)