[PATCH] [PATCH v4] lib/ethdev: fix segfault in secondary process by validating dev_private pointer

Stephen Hemminger stephen at networkplumber.org
Mon Jul 28 23:45:52 CEST 2025


On Fri, 25 Jul 2025 08:55:26 -0400
Khadem Ullah <14pwcse1224 at uetpeshawar.edu.pk> wrote:

> In secondary processes, directly accessing 'dev->data->dev_private' can
> cause a segmentation fault if the primary process has exited or if the
> shared memory is no longer accessible.
> 
> The secondary process not only crashes on device close but also segfaults
> when executing commands like "show device info all" after the primary has
> exited.
> 
> This patch adds a mechanism in testpmd to monitor the primary process from the
> secondary using `rte_eal_primary_proc_alive()`, and introduces safety
> checks before dereferencing 'dev_private'. The `rte_mem_virt2phy()` call
> is also guarded to avoid access to invalid memory regions, with
> `unlikely()` hints to minimize impact in the fast path.
> 
> Fixes: bdad90d12ec8 ("ethdev: change device info get callback to return int")
> Cc: stable at dpdk.org
> 
> Signed-off-by: Khadem Ullah <14pwcse1224 at uetpeshawar.edu.pk>
> ---
>  app/test-pmd/testpmd.c  | 56 ++++++++++++++++++++++++++++++++++++++---
>  lib/ethdev/rte_ethdev.c | 15 ++++++++++-
>  2 files changed, 66 insertions(+), 5 deletions(-)


The test-pmd monitoring is good, and should have done back when secondary
support was added. Please submit just that part of the patch and add a Fixes tag.
You can use the f_quit flag like the signal handler.

The use of volatile and standard atomic overlap.
Testpmd is older code so just uses volatile so you don't need to use
rte_atomic there. Just set f_quit in the alarm handler and avoid restarting alarm
if primary exits.

In future, want to add something like:
	rte_eal_primary_proc_notifier(void (*cb)(void *), void *);
and use some variation of pidfd or inotify to call the function when primary
dies either by termination or abort.

The ethdev part is not necessary, and really won't address the race; leave it out.


More information about the stable mailing list