From: Bruce Richardson <bruce.richardson@intel.com>
To: Sunyang Wu <sunyang.wu@jaguarmicro.com>
Cc: <dev@dpdk.org>, <aman.deep.singh@intel.com>, <stable@dpdk.org>
Subject: Re: [PATCH] app/testpmd: avoid cmdline use-after-free on SIGINT
Date: Mon, 27 Apr 2026 11:02:28 +0100 [thread overview]
Message-ID: <ae80NGXJc7qgqoDA@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <20260427091055.22412-1-sunyang.wu@jaguarmicro.com>
On Mon, Apr 27, 2026 at 05:10:55PM +0800, Sunyang Wu wrote:
> When testpmd runs in interactive mode, SIGINT is handled by setting
> the quit flag and calling prompt_exit() so the cmdline input path can
> be interrupted.
>
> However, prompt() frees the cmdline object with cmdline_stdin_exit()
> after cmdline_interact() returns, while the global testpmd_cl pointer
> may still be observed by a later signal during shutdown. If SIGINT
> arrives after the cmdline object is freed, prompt_exit() may call
> cmdline_quit() on stale state and trigger a use-after-free.
>
> Keep the existing prompt_exit() behavior so interactive input can
> still be cancelled, but store the cmdline object in a local variable
> and clear testpmd_cl before freeing it.
>
> This preserves the interactive-mode fix introduced for Windows while
> avoiding a shutdown-time use-after-free.
>
> Fixes: f1d0993e034e ("app/testpmd: fix interactive mode on Windows")
> Cc: stable@dpdk.org
>
> Signed-off-by: Sunyang Wu <sunyang.wu@jaguarmicro.com>
> ---
> app/test-pmd/cmdline.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index c5abeb5730..e3ed0f1865 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -14500,22 +14500,28 @@ cmdline_read_from_file(const char *filename, bool echo)
> void
> prompt_exit(void)
> {
> - cmdline_quit(testpmd_cl);
> + if (testpmd_cl != NULL)
> + cmdline_quit(testpmd_cl);
> }
>
> /* prompt function, called from main on MAIN lcore */
> void
> prompt(void)
> {
> - testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
> - if (testpmd_cl == NULL) {
> + struct cmdline *cl;
> +
> + cl = cmdline_stdin_new(main_ctx, "testpmd> ");
> + if (cl == NULL) {
> fprintf(stderr,
> "Failed to create stdin based cmdline context\n");
> return;
> }
>
> - cmdline_interact(testpmd_cl);
> - cmdline_stdin_exit(testpmd_cl);
> + testpmd_cl = cl;
> + cmdline_interact(cl);
> + /* Clear global pointer before freeing cmdline object. */
> + testpmd_cl = NULL;
> + cmdline_stdin_exit(cl);
> }
Do you need some memory barriers in this code to guarantee that the NULL
pointer is visible to other threads before you start calling the exit
function?
/Bruce
next prev parent reply other threads:[~2026-04-27 10:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 9:10 [PATCH] app/testpmd: avoid cmdline use-after-free on SIGINT Sunyang Wu
2026-04-27 10:02 ` Bruce Richardson [this message]
2026-04-27 10:33 ` 回复: " Sunyang Wu
2026-04-27 10:43 ` Bruce Richardson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ae80NGXJc7qgqoDA@bricha3-mobl1.ger.corp.intel.com \
--to=bruce.richardson@intel.com \
--cc=aman.deep.singh@intel.com \
--cc=dev@dpdk.org \
--cc=stable@dpdk.org \
--cc=sunyang.wu@jaguarmicro.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox