diff mbox series

liquidio: avoid NULL pointer dereference in lio_vf_rep_copy_packet()

Message ID 20221128102659.4946-1-a.burakov@rosalinux.ru (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series liquidio: avoid NULL pointer dereference in lio_vf_rep_copy_packet() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 2 blamed authors not CCed: raghu.vatsavayi@cavium.com vijaya.guvva@cavium.com; 4 maintainers not CCed: raghu.vatsavayi@cavium.com pabeni@redhat.com kuba@kernel.org vijaya.guvva@cavium.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Aleksandr Burakov Nov. 28, 2022, 10:26 a.m. UTC
lio_vf_rep_copy_packet() passes pg_info->page to skb_add_rx_frag()
that dereferences it without any check. So, it does not make sense
to call skb_add_rx_frag() when pg_info->page is NULL to avoid an segfault.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Aleksandr Burakov <a.burakov@rosalinux.ru>
Fixes: 1f233f327913 ("liquidio: switchdev support for LiquidIO NIC")
---
 drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Jakub Kicinski Nov. 30, 2022, 5:23 a.m. UTC | #1
On Mon, 28 Nov 2022 13:26:59 +0300 Aleksandr Burakov wrote:
> --- a/drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c
> +++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c
> @@ -272,13 +272,12 @@ lio_vf_rep_copy_packet(struct octeon_device *oct,
>  				pg_info->page_offset;
>  			memcpy(skb->data, va, MIN_SKB_SIZE);
>  			skb_put(skb, MIN_SKB_SIZE);
> +			skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
> +					pg_info->page,
> +					pg_info->page_offset + MIN_SKB_SIZE,
> +					len - MIN_SKB_SIZE,
> +					LIO_RXBUFFER_SZ);
>  		}
> -
> -		skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
> -				pg_info->page,
> -				pg_info->page_offset + MIN_SKB_SIZE,
> -				len - MIN_SKB_SIZE,
> -				LIO_RXBUFFER_SZ);
>  	} else {
>  		struct octeon_skb_page_info *pg_info =
>  			((struct octeon_skb_page_info *)(skb->cb));

The else branch also looks at pg_info and derefs page like there's 
no tomorrow. You need to put a bit more effort into the analysis.

Marvell people please chime in and tell us what the intention is here.
Whether page can be NULL here or this is defensive programming and can
be dropped.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c
index 600de587d7a9..e70b9ccca380 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c
@@ -272,13 +272,12 @@  lio_vf_rep_copy_packet(struct octeon_device *oct,
 				pg_info->page_offset;
 			memcpy(skb->data, va, MIN_SKB_SIZE);
 			skb_put(skb, MIN_SKB_SIZE);
+			skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
+					pg_info->page,
+					pg_info->page_offset + MIN_SKB_SIZE,
+					len - MIN_SKB_SIZE,
+					LIO_RXBUFFER_SZ);
 		}
-
-		skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
-				pg_info->page,
-				pg_info->page_offset + MIN_SKB_SIZE,
-				len - MIN_SKB_SIZE,
-				LIO_RXBUFFER_SZ);
 	} else {
 		struct octeon_skb_page_info *pg_info =
 			((struct octeon_skb_page_info *)(skb->cb));