Thread (11 messages) 11 messages, 1 author, 2026-01-07

Re: [PATCH net-next v09 2/9] hinic3: Add PF management interfaces

From: Fan Gong <gongfan1@huawei.com>
Date: 2026-01-07 03:14:23
Also in: linux-doc, lkml

quoted
+static void hinic3_init_mgmt_msg_work(struct hinic3_msg_pf_to_mgmt *pf_to_mgmt,
+				      struct hinic3_recv_msg *recv_msg)
+{
+	struct mgmt_msg_handle_work *mgmt_work;
+
+	mgmt_work = kmalloc(sizeof(*mgmt_work), GFP_KERNEL);
+	if (!mgmt_work)
+		return;
+
+	if (recv_msg->msg_len) {
+		mgmt_work->msg = kmalloc(recv_msg->msg_len, GFP_KERNEL);
+		if (!mgmt_work->msg) {
+			kfree(mgmt_work);
+			return;
+		}
+	}
When recv_msg->msg_len is zero, the above conditional is not taken, leaving
mgmt_work->msg uninitialized. The work handler later calls kfree() on this
uninitialized pointer at the "out" label in hinic3_recv_mgmt_msg_work_handler().

A zero-length message can arrive when seg_len is 0 in hinic3_recv_msg_add_seg(),
which only validates seg_len > MGMT_SEG_LEN_MAX but does not reject seg_len == 0.

Should mgmt_work->msg be initialized to NULL before the conditional, or should
an else clause set it to NULL?
We will address the AI review comments in patch 2/5/8 sooner.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help