Skip to contentSkip to conversation

liquidio: check other_oct before dereferencing

PATCH In review Alexey V. Vissarionov 2 participants 3 messages Apr 29, 2025 – May 5, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 liquidio: check other_oct before dereferencing

get_other_octeon_device() may return NULL; avoid dereferencing the other_oct pointer in that case.

Found by ALT Linux Team (altlinux.org) and Linux Verification Center (linuxtesting.org).

Fixes bb54be589c7a ("liquidio: fix Octeon core watchdog timeout false alarm")
---
 drivers/net/ethernet/cavium/liquidio/lio_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/cavium/liquidio/lio_main.c +5 -4
index 1d79f6eaa41f6cbf..7b255126289b9fcd 100644
@@ -796,10 +796,11 @@ static int liquidio_watchdog(void *param)
 
 #ifdef CONFIG_MODULE_UNLOAD
 		vfs_mask1 = READ_ONCE(oct->sriov_info.vf_drv_loaded_mask);
-		vfs_mask2 = READ_ONCE(other_oct->sriov_info.vf_drv_loaded_mask);
-
-		vfs_referencing_pf  = hweight64(vfs_mask1);
-		vfs_referencing_pf += hweight64(vfs_mask2);
+		vfs_referencing_pf = hweight64(vfs_mask1);
+		if (other_oct) {
+			vfs_mask2 = READ_ONCE(other_oct->sriov_info.vf_drv_loaded_mask);
+			vfs_referencing_pf += hweight64(vfs_mask2);
+		}
 
 		refcount = module_refcount(THIS_MODULE);
 		if (refcount >= vfs_referencing_pf) {
Signature · 3 lines
Alexey V. Vissarionov
gremlin ПРИ altlinux ТЧК org; +vii-cmiii-ccxxix-lxxix-xlii
GPG: 0D92F19E1C0DC36E27F61A29CD17E2B43D879005 @ hkp://keys.gnupg.net
#1 lore raw
Quoted 19 lines · Alexey V. Vissarionov

get_other_octeon_device() may return NULL; avoid dereferencing the other_oct pointer in that case.

Found by ALT Linux Team (altlinux.org) and Linux Verification Center (linuxtesting.org).

Fixes bb54be589c7a ("liquidio: fix Octeon core watchdog timeout false alarm")
---
 drivers/net/ethernet/cavium/liquidio/lio_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/cavium/liquidio/lio_main.c +0 -0
index 1d79f6eaa41f6cbf..7b255126289b9fcd 100644
@@ -796,10 +796,11 @@ static int liquidio_watchdog(void *param)
 
 #ifdef CONFIG_MODULE_UNLOAD

drivers/net/ethernet/cavium/liquidio/lio_main.c static int liquidio_watchdog(void *param) · line 803

Quoted 10 lines
drivers/net/ethernet/cavium/liquidio/lio_main.c +5 -4
 		vfs_mask1 = READ_ONCE(oct->sriov_info.vf_drv_loaded_mask);
-		vfs_mask2 = READ_ONCE(other_oct->sriov_info.vf_drv_loaded_mask);
-
-		vfs_referencing_pf  = hweight64(vfs_mask1);
-		vfs_referencing_pf += hweight64(vfs_mask2);
+		vfs_referencing_pf = hweight64(vfs_mask1);
+		if (other_oct) {
+			vfs_mask2 = READ_ONCE(other_oct->sriov_info.vf_drv_loaded_mask);
+			vfs_referencing_pf += hweight64(vfs_mask2);
+		}

Obviously crashing when other_oct is NULL is bad..

But is it ok to proceed when it is NULL? Is leaving out the counts ok? I guess I don't really understand what other_oct actually represents here.

#2 lore raw

Good ${greeting_time}!

Quoted 4 lines · Jacob Keller
Quoted 4 lines

get_other_octeon_device() may return NULL; avoid dereferencing the other_oct pointer in that case.

(quoted diff) +0 -0
@@ -796,10 +796,11 @@ static int liquidio_watchdog(void *param)
 
Quoted 15 lines
Quoted 4 lines
drivers/net/ethernet/cavium/liquidio/lio_main.c +0 -1
 #ifdef CONFIG_MODULE_UNLOAD
 		vfs_mask1 =
 		READ_ONCE(oct->sriov_info.vf_drv_loaded_mask);
-		vfs_mask2 =

drivers/net/ethernet/cavium/liquidio/lio_main.c static int liquidio_watchdog(void *param) · line 803

Quoted 10 lines
drivers/net/ethernet/cavium/liquidio/lio_main.c +5 -3
 READ_ONCE(other_oct->sriov_info.vf_drv_loaded_mask);
-
-		vfs_referencing_pf = hweight64(vfs_mask1);
-		vfs_referencing_pf += hweight64(vfs_mask2);
+		vfs_referencing_pf = hweight64(vfs_mask1);
+		if (other_oct) {
+			vfs_mask2 =
 READ_ONCE(other_oct->sriov_info.vf_drv_loaded_mask);
+			vfs_referencing_pf += hweight64(vfs_mask2);
+		}

Obviously crashing when other_oct is NULL is bad..

Yes, even if this happens only when attempting to unload the module.

Quoted 3 lines

But is it ok to proceed when it is NULL? Is leaving out the counts ok? I guess I don't really understand what other_oct actually represents here.

As I can see, the vf_drv_loaded_mask is a bitmap containing the flags for all existing virtual functions of all devices. So, if there's no other device, its' functions are missing and marked as unavailable in the vf_drv_loaded_mask.

Signature · 3 lines
Alexey V. Vissarionov
gremlin ПРИ altlinux ТЧК org; +vii-cmiii-ccxxix-lxxix-xlii
GPG: 0D92F19E1C0DC36E27F61A29CD17E2B43D879005 @ hkp://keys.gnupg.net