Skip to contentSkip to conversation

xdp: add NULL pointer check in __xdp_return()

PATCH Applied Taehee Yoo 3 participants 3 messages Jul 26, 2018 – Jul 27, 2018

Subsystems (3)
lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH v3 1/1 xdp: add NULL pointer check in __xdp_return()

rhashtable_lookup() can return NULL. so that NULL pointer check routine should be added.

Fixes 02b55e5657c3 ("xdp: add MEM_TYPE_ZERO_COPY")

---
V3 : reduce code line
V2 : add WARN_ON_ONCE when xa is NULL.

 net/core/xdp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/xdp.c +2 -1
index 9d1f220..6771f18 100644
@@ -345,7 +345,8 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
 		rcu_read_lock();
 		/* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */
 		xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
-		xa->zc_alloc->free(xa->zc_alloc, handle);
+		if (!WARN_ON_ONCE(!xa))
+			xa->zc_alloc->free(xa->zc_alloc, handle);
 		rcu_read_unlock();
 	default:
 		/* Not possible, checked in xdp_rxq_info_reg_mem_model() */
Signature · 1 line
2.9.3
Acked-by on v3 1/1
#1 lore raw

Den tors 26 juli 2018 kl 16:18 skrev Taehee Yoo <[email protected]>:

Quoted 4 lines

rhashtable_lookup() can return NULL. so that NULL pointer check routine should be added.

Thanks Taehee!

Quoted 26 lines
Fixes 02b55e5657c3 ("xdp: add MEM_TYPE_ZERO_COPY")

---
V3 : reduce code line
V2 : add WARN_ON_ONCE when xa is NULL.

 net/core/xdp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/xdp.c +2 -2
index 9d1f220..6771f18 100644
@@ -345,7 +345,8 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
                rcu_read_lock();
                /* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */
                xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
-               xa->zc_alloc->free(xa->zc_alloc, handle);
+               if (!WARN_ON_ONCE(!xa))
+                       xa->zc_alloc->free(xa->zc_alloc, handle);
                rcu_read_unlock();
        default:
                /* Not possible, checked in xdp_rxq_info_reg_mem_model() */
--

2.9.3