[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260105173916.4a0b29bc@kernel.org>
Date: Mon, 5 Jan 2026 17:39:16 -0800
From: Jakub Kicinski <kuba@...nel.org>
To: Fan Gong <gongfan1@...wei.com>
Cc: Zhu Yikai <zhuyikai1@...artners.com>, <netdev@...r.kernel.org>, "David
S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, Paolo
Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>, Andrew Lunn
<andrew+netdev@...n.ch>, Markus Elfring <Markus.Elfring@....de>, Pavan
Chebbi <pavan.chebbi@...adcom.com>, ALOK TIWARI <alok.a.tiwari@...cle.com>,
<linux-kernel@...r.kernel.org>, <linux-doc@...r.kernel.org>, luosifu
<luosifu@...wei.com>, Xin Guo <guoxin09@...wei.com>, Shen Chenyang
<shenchenyang1@...ilicon.com>, Zhou Shuai <zhoushuai28@...wei.com>, Wu Like
<wulike1@...wei.com>, Shi Jing <shijing34@...wei.com>, Luo Yang
<luoyang82@...artners.com>
Subject: Re: [PATCH net-next v08 1/9] hinic3: Add PF framework
AI code review points out the following.
Please address or add a relevant comment explaining why the code
is fine.
> diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c b/drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c
> index cf67e26acece..1cb0d88911a2 100644
> --- a/drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c
> +++ b/drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c
> @@ -82,10 +82,19 @@ static struct hinic3_msg_desc *get_mbox_msg_desc(struct hinic3_mbox *mbox,
> enum mbox_msg_direction_type dir,
> u16 src_func_id)
> {
> + struct hinic3_hwdev *hwdev = mbox->hwdev;
> struct hinic3_msg_channel *msg_ch;
>
> - msg_ch = (src_func_id == MBOX_MGMT_FUNC_ID) ?
> - &mbox->mgmt_msg : mbox->func_msg;
> + if (src_func_id == MBOX_MGMT_FUNC_ID) {
> + msg_ch = &mbox->mgmt_msg;
> + } else if (HINIC3_IS_VF(hwdev)) {
> + /* message from pf */
> + msg_ch = mbox->func_msg;
> + if (src_func_id != hinic3_pf_id_of_vf(hwdev) || !msg_ch)
> + return NULL;
> + } else {
> + return NULL;
> + }
Can this return NULL for PF when src_func_id is not MBOX_MGMT_FUNC_ID?
Looking at hinic3_mbox_func_aeqe_handler(), the caller of get_mbox_msg_desc():
msg_desc = get_mbox_msg_desc(mbox, dir, src_func_id);
recv_mbox_handler(mbox, header, msg_desc);
The return value is passed directly to recv_mbox_handler() without a
NULL check. Inside recv_mbox_handler():
if (!mbox_segment_valid(mbox, msg_desc, mbox_header)) {
msg_desc->seq_id = MBOX_SEQ_ID_MAX_VAL;
And mbox_segment_valid() dereferences msg_desc unconditionally:
msg_desc->seq_id = seq_id;
If a PF receives a mailbox message from any source other than management
(for example, from a VF), get_mbox_msg_desc() returns NULL, and then
mbox_segment_valid() will dereference the NULL pointer causing a kernel
crash.
Should hinic3_mbox_func_aeqe_handler() check for NULL before calling
recv_mbox_handler()?
Powered by blists - more mailing lists