From: Zhu Yanjun <yanjun.zhu@linux.dev>
To: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>,
Ayush Sawal <ayush.sawal@chelsio.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Leon Romanovsky <leon@kernel.org>,
Steffen Klassert <steffen.klassert@secunet.com>,
Cosmin Ratiu <cratiu@nvidia.com>, Harsh Jain <harsh@chelsio.com>,
Atul Gupta <atul.gupta@chelsio.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Ganesh Goudar <ganeshgr@chelsio.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
lvc-project@linuxtesting.org
Subject: Re: [PATCH] net: fix potential use-after-free in ch_ipsec_xfrm_add_state() callback
Date: Fri, 3 Oct 2025 21:28:51 -0700 [thread overview]
Message-ID: <f0cef998-0d49-4a52-b1b8-2f89b81d4b07@linux.dev> (raw)
In-Reply-To: <20251001111646.806130-1-Pavel.Zhigulin@kaspersky.com>
在 2025/10/1 4:16, Pavel Zhigulin 写道:
> In ch_ipsec_xfrm_add_state() there is not check of try_module_get
> return value. It is very unlikely, but try_module_get() could return
> false value, which could cause use-after-free error.
>
> This fix adds checking the result of try_module_get call
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 6dad4e8ab3ec ("chcr: Add support for Inline IPSec")
> Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>
> ---
> .../net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c b/drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c
> index ecd9a0bd5e18..3a5277630afa 100644
> --- a/drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c
> +++ b/drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c
> @@ -35,6 +35,8 @@
> * Atul Gupta (atul.gupta@chelsio.com)
> */
>
> +#include "asm-generic/errno-base.h"
> +#include "linux/compiler.h"
> #define pr_fmt(fmt) "ch_ipsec: " fmt
>
> #include <linux/kernel.h>
> @@ -301,7 +303,8 @@ static int ch_ipsec_xfrm_add_state(struct net_device *dev,
> sa_entry->esn = 1;
> ch_ipsec_setkey(x, sa_entry);
> x->xso.offload_handle = (unsigned long)sa_entry;
> - try_module_get(THIS_MODULE);
> + if (unlikely(!try_module_get(THIS_MODULE)))
The function try_module_get() fails (returns false) only if the module
is in the process of being
unloaded (i.e., module_refcount can’t be increased because the state is
GOING
or UNFORMED). Otherwise, it succeeds and increments the refcount.
When the function ch_ipsec_xfrm_add_state is called, the kernel module
cannot be in the GOING
or UNFORMED state. In other words, within this function, it is not
possible for try_module_get to fail.
I am not sure if this check is strictly necessary, but as a defensive
programming measure, it still makes sense.
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Zhu Yanjun
> + res = -ENODEV;
> out:
> return res;
> }
> --
> 2.43.0
>
--
Best Regards,
Yanjun.Zhu
next prev parent reply other threads:[~2025-10-04 4:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-01 11:16 [PATCH] net: fix potential use-after-free in ch_ipsec_xfrm_add_state() callback Pavel Zhigulin
2025-10-04 4:28 ` Zhu Yanjun [this message]
2025-10-06 18:03 ` Jakub Kicinski
2025-10-06 18:27 ` Yanjun.Zhu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f0cef998-0d49-4a52-b1b8-2f89b81d4b07@linux.dev \
--to=yanjun.zhu@linux.dev \
--cc=Pavel.Zhigulin@kaspersky.com \
--cc=andrew+netdev@lunn.ch \
--cc=atul.gupta@chelsio.com \
--cc=ayush.sawal@chelsio.com \
--cc=cratiu@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=ganeshgr@chelsio.com \
--cc=harsh@chelsio.com \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).