2022-10-08 03:22:55

by zhanchengbin

[permalink] [raw]
Subject: [PATCH] misc/fsck.c: Processes may kill other processes.

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.

Signed-off-by: zhanchengbin <[email protected]>
---
misc/fsck.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/misc/fsck.c b/misc/fsck.c
index 4efe10ec..faf7789d 100644
--- a/misc/fsck.c
+++ b/misc/fsck.c
@@ -546,6 +546,8 @@ static int kill_all(int signum)
for (inst = instance_list; inst; inst = inst->next) {
if (inst->flags & FLAG_DONE)
continue;
+ if (inst->pid == -1)
+ continue;
kill(inst->pid, signum);
n++;
}
--
2.27.0


2022-10-10 07:51:39

by Lukas Czerner

[permalink] [raw]
Subject: Re: [PATCH] misc/fsck.c: Processes may kill other processes.

On Sat, Oct 08, 2022 at 11:05:48AM +0800, zhanchengbin wrote:
> 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.
>
> Signed-off-by: zhanchengbin <[email protected]>
> ---
> misc/fsck.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/misc/fsck.c b/misc/fsck.c
> index 4efe10ec..faf7789d 100644
> --- a/misc/fsck.c
> +++ b/misc/fsck.c
> @@ -546,6 +546,8 @@ static int kill_all(int signum)
> for (inst = instance_list; inst; inst = inst->next) {
> if (inst->flags & FLAG_DONE)
> continue;
> + if (inst->pid == -1)
> + continue;

That works, but I think we can afford to be a little defensive here.
Anything <= 0 is a bug and can have unexpected consequences if we
actually call the kill().

if (inst->pid <= 0)
continue;


Also as Darrick pointed out we need to send the patch to util-linux
(disk-utils/fsck.c) as well if you haven't already.

-Lukas


> kill(inst->pid, signum);
> n++;
> }
> --
> 2.27.0
>

2022-10-10 08:33:51

by zhanchengbin

[permalink] [raw]
Subject: Re: [PATCH] misc/fsck.c: Processes may kill other processes.



On 2022/10/10 15:17, Lukas Czerner wrote:
> On Sat, Oct 08, 2022 at 11:05:48AM +0800, zhanchengbin wrote:
>> 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.
>>
>> Signed-off-by: zhanchengbin <[email protected]>
>> ---
>> misc/fsck.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/misc/fsck.c b/misc/fsck.c
>> index 4efe10ec..faf7789d 100644
>> --- a/misc/fsck.c
>> +++ b/misc/fsck.c
>> @@ -546,6 +546,8 @@ static int kill_all(int signum)
>> for (inst = instance_list; inst; inst = inst->next) {
>> if (inst->flags & FLAG_DONE)
>> continue;
>> + if (inst->pid == -1)
>> + continue;
>
> That works, but I think we can afford to be a little defensive here.
> Anything <= 0 is a bug and can have unexpected consequences if we
> actually call the kill().
>
> if (inst->pid <= 0)
> continue

OK, I'll fix this and send the v2 version of the patch.

>
>
> Also as Darrick pointed out we need to send the patch to util-linux
> (disk-utils/fsck.c) as well if you haven't already.

I'll check and modify util-linux(disk-utils/fsck.c).

-zhanchengbin

>
> -Lukas
>
>
>> kill(inst->pid, signum);
>> n++;
>> }
>> --
>> 2.27.0
>>
>
> .
>