Skip to contentSkip to conversation

net/enic: fix possible null dereference in notify set

PATCH In review Alexey Simakov 2 participants 2 messages Jul 7 – Jul 9 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/enic: fix possible null dereference in notify set

The memset of notify_addr in vnic_dev_notify_setcmd() was performed unconditionally before the device reset check. When the device is in reset, vnic_dev_notify_set() skips the notification buffer allocation, leaving notify_addr as NULL. The subsequent call to vnic_dev_notify_setcmd() would then dereference the NULL pointer via memset.

Move the memset inside the existing !vnic_dev_in_reset() guard where notify_addr is guaranteed to be valid.

Fixes 9913fbb91df0 ("enic/base: common code")
---
 drivers/net/enic/base/vnic_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/enic/base/vnic_dev.c +1 -1
index ba8ecc16f2..e6d34622af 100644
@@ -964,8 +964,8 @@ int vnic_dev_notify_setcmd(struct vnic_dev *vdev,
 	int wait = 1000;
 	int r;
 
-	memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify));
 	if (!vnic_dev_in_reset(vdev)) {
+		memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify));
 		vdev->notify = notify_addr;
 		vdev->notify_pa = notify_pa;
 	}
Signature · 1 line
2.34.1
#1 lore raw
Quoted 32 lines

-----Original Message-----
From: Alexey Simakov <[email protected]>
Sent: Tuesday, July 7, 2026 8:20 PM
To: John Daley (johndale) <[email protected]>; Hyong Youb Kim (hyonkim) <[email protected]>; Sujith Sankar <[email protected]>; David Marchand <[email protected]>; Neil Horman <[email protected]>
Cc: [email protected]; [email protected]; Alexey Simakov <[email protected]>
Subject: [PATCH] net/enic: fix possible null dereference in notify set

The memset of notify_addr in vnic_dev_notify_setcmd() was performed unconditionally before the device reset check. When the device is in reset, vnic_dev_notify_set() skips the notification buffer allocation, leaving notify_addr as NULL. The subsequent call to vnic_dev_notify_setcmd() would then dereference the NULL pointer via memset.

Move the memset inside the existing !vnic_dev_in_reset() guard where notify_addr is guaranteed to be valid.

Fixes 9913fbb91df0 ("enic/base: common code")
---
 drivers/net/enic/base/vnic_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/enic/base/vnic_dev.c +0 -0
index ba8ecc16f2..e6d34622af 100644

drivers/net/enic/base/vnic_dev.c int vnic_dev_notify_setcmd(struct vnic_dev *vdev, · line 970

Quoted 8 lines
drivers/net/enic/base/vnic_dev.c +1 -1
@@ -964,8 +964,8 @@ int vnic_dev_notify_setcmd(struct vnic_dev *vdev,
 	int wait = 1000;
 	int r;
 
-	memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify));
 	if (!vnic_dev_in_reset(vdev)) {
+		memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify));
 		vdev->notify = notify_addr;
 		vdev->notify_pa = notify_pa;

notify_addr == NULL (or bogus notify_pa) is a hard program error in this function. Debug assertion might be more appropriate to make the intention clear.

During init, the driver allocates the notify buffer while in_reset == 0. enic_dev_init() does not check the return code from vnic_dev_notify_set(). I think that needs to be fixed.

Thanks.
-Hyong

Quoted 3 lines
drivers/net/enic/base/vnic_dev.c +0 -1
 	}
--

2.34.1