From: Simon Horman <horms@kernel.org>
To: Charles Han <hanchunchao@inspur.com>
Cc: ayush.sawal@chelsio.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, atul.gupta@chelsio.com, werner@chelsio.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: chtls: Add check alloc_skb() returned value
Date: Fri, 17 Jan 2025 13:29:14 +0000 [thread overview]
Message-ID: <20250117132914.GM6206@kernel.org> (raw)
In-Reply-To: <20250117031328.13908-1-hanchunchao@inspur.com>
On Fri, Jan 17, 2025 at 11:13:28AM +0800, Charles Han wrote:
> alloc_skb() can return a NULL pointer on failure.But these returned
> value in send_defer_abort_rpl() and chtls_close_conn() not checked.
>
> Fixes: cc35c88ae4db ("crypto : chtls - CPL handler definition")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
> .../net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
> index 6f6525983130..725cce34f25a 100644
> --- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
> +++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
> @@ -306,6 +306,10 @@ static void chtls_close_conn(struct sock *sk)
> tid = csk->tid;
>
> skb = alloc_skb(len, GFP_KERNEL | __GFP_NOFAIL);
> + if (!skb) {
> + pr_warn("%s: cannot allocate skb!\n", __func__);
> + return;
> + }
> req = (struct cpl_close_con_req *)__skb_put(skb, len);
> memset(req, 0, len);
> req->wr.wr_hi = htonl(FW_WR_OP_V(FW_TP_WR) |
> @@ -1991,6 +1995,11 @@ static void send_defer_abort_rpl(struct chtls_dev *cdev, struct sk_buff *skb)
>
> reply_skb = alloc_skb(sizeof(struct cpl_abort_rpl),
> GFP_KERNEL | __GFP_NOFAIL);
> + if (!reply_skb) {
> + pr_warn("%s: cannot allocate skb!\n", __func__);
> + return;
> + }
> +
> __skb_put(reply_skb, sizeof(struct cpl_abort_rpl));
> set_abort_rpl_wr(reply_skb, GET_TID(req),
> (req->status & CPL_ABORT_NO_RST));
Hi Charles,
I agree that not checking for NULL skbs will very soon lead
to a NULL pointer dereference. But I wonder if this patch leads
us to a better place. Because by returning on skb allocation
failure in each of the above cases, don't we end up with
an inconsistent state?
Also, the above notwithstanding, I do wonder if:
a) the warnings should be errors
b) they should be rate limited
prev parent reply other threads:[~2025-01-17 13:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-17 3:13 [PATCH] crypto: chtls: Add check alloc_skb() returned value Charles Han
2025-01-17 13:29 ` Simon Horman [this message]
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=20250117132914.GM6206@kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=atul.gupta@chelsio.com \
--cc=ayush.sawal@chelsio.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hanchunchao@inspur.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=werner@chelsio.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).