All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Rajnoha <prajnoha@sourceware.org>
To: lvm-devel@redhat.com
Subject: main - toollib: fix segfault if using -S|--select with log/report_command_log=1 setting
Date: Tue,  7 Mar 2023 14:30:36 +0000 (GMT)	[thread overview]
Message-ID: <20230307143036.A8D95385559E@sourceware.org> (raw)

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=cd14d3fcc0e03136d0cea1ab1a9edff3b8b9dbeb
Commit:        cd14d3fcc0e03136d0cea1ab1a9edff3b8b9dbeb
Parent:        c8f2125b85afe043af1b2e887a80f882b8d8d7c7
Author:        Peter Rajnoha <prajnoha@redhat.com>
AuthorDate:    Tue Mar 7 14:45:06 2023 +0100
Committer:     Peter Rajnoha <prajnoha@redhat.com>
CommitterDate: Tue Mar 7 15:29:54 2023 +0100

toollib: fix segfault if using -S|--select with log/report_command_log=1 setting

When we are using -S|--select for non-reporting tools while using command log
reporting (log/report_command_log=1 setting), we need to create an internal
processing handle to handle the selection itself. In this case, the internal
processing handle to execute the selection (to process the -S|--select) has
a parent handle (that is processing the actual non-reporting command).

When this parent handle exists, we can't destroy the command log report
in destroy_processing_handle as there's still the parent processing to
finish. The parent processing may still generate logs which need to be
reported in the command log report. If the command log report was
destroyed prematurely together with destroying the internal processing
handle for -S|--select, then any subsequent log request from processing
the actual command (and hence an attermpt to access the command log report)
ended up with a segfault.

See also: https://bugzilla.redhat.com/show_bug.cgi?id=2175220
---
 WHATS_NEW       |  1 +
 tools/toollib.c | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/WHATS_NEW b/WHATS_NEW
index 8523b5eb7..7c979d69c 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 version 2.03.20 - 
 ====================================
+  Fix segfault if using -S|--select with log/report_command_log=1 setting.
   Configure now fails when requested lvmlockd dependencies are missing.
   Add some configure Gentoo enhancements for static builds.
 
diff --git a/tools/toollib.c b/tools/toollib.c
index 194088ea6..43e628abf 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -2050,7 +2050,20 @@ void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle
 
 		log_restore_report_state(cmd->cmd_report.saved_log_report_state);
 
-		if (!cmd->is_interactive) {
+		/*
+		 * Do not destroy current cmd->report_group and cmd->log_rh
+		 * (the log report) yet if we're running interactively
+		 * (== running in lvm shell) or if there's a parent handle
+		 * (== we're executing nested processing, like it is when
+		 * doing selection for parent's process_each_* processing).
+		 *
+		 * In both cases, there's still possible further processing
+		 * to do outside the processing covered by the handle we are
+		 * destroying here and for which we may still need to access
+		 * the log report to cover the rest of the processing.
+		 *
+		 */
+		if (!cmd->is_interactive && !handle->parent) {
 			if (!dm_report_group_destroy(cmd->cmd_report.report_group))
 				stack;
 			cmd->cmd_report.report_group = NULL;


                 reply	other threads:[~2023-03-07 14:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230307143036.A8D95385559E@sourceware.org \
    --to=prajnoha@sourceware.org \
    --cc=lvm-devel@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.