All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Czerner <lczerner@redhat.com>
To: zhanchengbin <zhanchengbin1@huawei.com>
Cc: Theodore Ts'o <tytso@mit.edu>,
	linux-ext4@vger.kernel.org, liuzhiqiang26@huawei.com,
	linfeilong <linfeilong@huawei.com>
Subject: Re: [bug report] misc/fsck.c: Processes may kill other processes.
Date: Thu, 29 Sep 2022 13:28:13 +0200	[thread overview]
Message-ID: <20220929112813.6aqtktwaff2m7fh2@fedora> (raw)
In-Reply-To: <4ffe3143-fc53-7178-cf44-f3481eb96ae4@huawei.com>

On Thu, Sep 29, 2022 at 03:39:57PM +0800, zhanchengbin wrote:
> Hi Tytso,
> I find a error in misc/fsck.c, if run the fsck -N command, processes
> don't execute, just show what would be done. However, the pid whose
> value is -1 is added to the instance_list list in the execute
> function,if the kill_all function is called later, kill(-1, signum)
> is executed, Signals are sent to all processes except the number one
> process and itself. Other processes will be killed if they use the
> default signal processing function.

Hi,

indeed we'd like to avoid killing the instance that was not ran because
of noexecute. Can you try the following patch?

Thanks!
-Lukas


diff --git a/misc/fsck.c b/misc/fsck.c
index 1f6ec7d9..8fae7730 100644
--- a/misc/fsck.c
+++ b/misc/fsck.c
@@ -497,9 +497,10 @@ static int execute(const char *type, const char *device, const char *mntpt,
 	}
 
 	/* Fork and execute the correct program. */
-	if (noexecute)
+	if (noexecute) {
 		pid = -1;
-	else if ((pid = fork()) < 0) {
+		inst->flags |= FLAG_DONE;
+	} else if ((pid = fork()) < 0) {
 		perror("fork");
 		free(inst);
 		return errno;
@@ -544,6 +545,9 @@ static int kill_all(int signum)
 	struct fsck_instance *inst;
 	int	n = 0;
 
+	if (noexecute)
+		return 0;
+
 	for (inst = instance_list; inst; inst = inst->next) {
 		if (inst->flags & FLAG_DONE)
 			continue;


> 
> execute:
>     if (noexecute)
>         pid = -1;
>     inst->pid = pid;
>     // Find the end of the list, so we add the instance on at the end.
> 
> kill_all:
>     for (inst = instance_list; inst; inst = inst->next) {
>         kill(inst->pid, signum);
>     }
> 
> misc/fsck.c:
> main:
>     ->PRS
>         case 'N':
>             noexecute++;
>     for (num_devices) {
>         if (cancel_requested) {
>             ->kill_all(SIGTERM);
>         }
>         ->fsck_device
>             ->execute
>     }
> 
> (gdb) bt
> #0  execute (type=<optimized out>, type@entry=0x412cd0 "ext4",
> device=0x412b00 "/root/a.img", mntpt=<optimized out>,
> interactive=interactive@entry=1) at fsck.c:523
> #1  0x0000000000404959 in fsck_device (fs=fs@entry=0x412ac0,
> interactive=interactive@entry=1) at fsck.c:727
> #2  0x0000000000402704 in main (argc=<optimized out>, argv=<optimized out>)
> at fsck.c:1333
> (gdb) p inst->pid
> $7 = -1
> 
> regards,
> Zhan Chengbin
> 


  reply	other threads:[~2022-09-29 11:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-29  7:39 [bug report] misc/fsck.c: Processes may kill other processes zhanchengbin
2022-09-29 11:28 ` Lukas Czerner [this message]
2022-09-30  1:42   ` zhanchengbin
2022-09-30  7:20     ` Lukas Czerner
2022-10-04 22:18       ` Darrick J. Wong
2022-10-10  8:09       ` Karel Zak
2022-10-10  9:26         ` zhanchengbin

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=20220929112813.6aqtktwaff2m7fh2@fedora \
    --to=lczerner@redhat.com \
    --cc=linfeilong@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=liuzhiqiang26@huawei.com \
    --cc=tytso@mit.edu \
    --cc=zhanchengbin1@huawei.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.