[PATCH net v2] xdp: xdp_mem_allocator can be NULL in trace_mem_connect().

Subsystems: networking [general], the rest, xdp (express data path)

STALE1638d

3 messages, 3 authors, 2022-03-09 · open the first message on its own page

[PATCH net v2] xdp: xdp_mem_allocator can be NULL in trace_mem_connect().

From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: 2022-03-09 20:47:44

Since the commit mentioned below __xdp_reg_mem_model() can return a NULL
pointer. This pointer is dereferenced in trace_mem_connect() which leads
to segfault.

The trace points (mem_connect + mem_disconnect) were put in place to
pair connect/disconnect using the IDs. The ID is only assigned if
__xdp_reg_mem_model() does not return NULL. That connect trace point is
of no use if there is no ID.

Skip that connect trace point if xdp_alloc is NULL.

[ Toke Høiland-Jørgensen delivered the reasoning for skipping the trace
  point ]

Fixes: 4a48ef70b93b8 ("xdp: Allow registering memory model without rxq reference")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
v1…v2:
   - Instead letting the trace point deal with a NULL pointer, skip the
     trace point.

 net/core/xdp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 7aba355049862..8ebb22eb6497c 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -357,7 +357,8 @@ int xdp_rxq_info_reg_mem_model(struct xdp_rxq_info *xdp_rxq,
 	if (IS_ERR(xdp_alloc))
 		return PTR_ERR(xdp_alloc);
 
-	trace_mem_connect(xdp_alloc, xdp_rxq);
+	if (xdp_alloc)
+		trace_mem_connect(xdp_alloc, xdp_rxq);
 	return 0;
 }
 
-- 
2.35.1

Re: [PATCH net v2] xdp: xdp_mem_allocator can be NULL in trace_mem_connect().

From: Steven Rostedt <rostedt@goodmis.org>
Date: 2022-03-09 21:36:21

On Wed, 9 Mar 2022 21:47:38 +0100
Sebastian Andrzej Siewior [off-list ref] wrote:
quoted hunk
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -357,7 +357,8 @@ int xdp_rxq_info_reg_mem_model(struct xdp_rxq_info *xdp_rxq,
 	if (IS_ERR(xdp_alloc))
 		return PTR_ERR(xdp_alloc);
 
-	trace_mem_connect(xdp_alloc, xdp_rxq);
+	if (xdp_alloc)
Eliminate the check when tracing is disabled:

	if (trace_mem_connect_enabled() && xdp_alloc)

-- Steve

+		trace_mem_connect(xdp_alloc, xdp_rxq);
 	return 0;
 }
 

Re: [PATCH net v2] xdp: xdp_mem_allocator can be NULL in trace_mem_connect().

From: Toke Høiland-Jørgensen <hidden>
Date: 2022-03-09 21:52:23

Sebastian Andrzej Siewior [off-list ref] writes:
Since the commit mentioned below __xdp_reg_mem_model() can return a NULL
pointer. This pointer is dereferenced in trace_mem_connect() which leads
to segfault.

The trace points (mem_connect + mem_disconnect) were put in place to
pair connect/disconnect using the IDs. The ID is only assigned if
__xdp_reg_mem_model() does not return NULL. That connect trace point is
of no use if there is no ID.

Skip that connect trace point if xdp_alloc is NULL.

[ Toke Høiland-Jørgensen delivered the reasoning for skipping the trace
  point ]

Fixes: 4a48ef70b93b8 ("xdp: Allow registering memory model without rxq reference")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
With Steven's fix:

Acked-by: Toke Høiland-Jørgensen <redacted>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help