liquidio: check other_oct before dereferencing
Subsystems (3)
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).
--- 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
@@ -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
Quoted 19 lines · Alexey V. Vissarionov
get_other_octeon_device()may return NULL; avoid dereferencing theother_octpointer 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")Signed-off-by Alexey V. Vissarionov <[email protected]>--- 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@@ -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
-4vfs_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.
Good ${greeting_time}!
Quoted 4 lines · Jacob Keller
Quoted 4 lines
get_other_octeon_device()may return NULL; avoid dereferencing theother_octpointer 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
-3READ_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_octis 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_octactually 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