* [PATCH 0/4] um: Set parent-death signal for sub-processes
@ 2024-10-24 14:28 Tiwei Bie
2024-10-24 14:28 ` [PATCH 1/4] um: Add os_set_pdeathsig helper function Tiwei Bie
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Tiwei Bie @ 2024-10-24 14:28 UTC (permalink / raw)
To: richard, anton.ivanov, johannes; +Cc: linux-um, linux-kernel, Tiwei Bie
The ubd io and write_sigio threads/processes may leak e.g. when
the main process is killed by "kill -9". Fix it by setting the
parent-death signal for them.
Tiwei Bie (4):
um: Add os_set_pdeathsig helper function
um: Set parent-death signal for ubd io thread/process
um: Set parent-death signal for write_sigio thread/process
um: Use os_set_pdeathsig helper in winch thread/process
arch/um/drivers/chan_user.c | 3 +--
arch/um/drivers/ubd_kern.c | 1 +
arch/um/include/shared/os.h | 2 ++
arch/um/os-Linux/process.c | 6 ++++++
arch/um/os-Linux/sigio.c | 1 +
5 files changed, 11 insertions(+), 2 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] um: Add os_set_pdeathsig helper function
2024-10-24 14:28 [PATCH 0/4] um: Set parent-death signal for sub-processes Tiwei Bie
@ 2024-10-24 14:28 ` Tiwei Bie
2024-10-24 14:28 ` [PATCH 2/4] um: Set parent-death signal for ubd io thread/process Tiwei Bie
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Tiwei Bie @ 2024-10-24 14:28 UTC (permalink / raw)
To: richard, anton.ivanov, johannes; +Cc: linux-um, linux-kernel, Tiwei Bie
This helper can be used to set the parent-death signal of the calling
process to SIGKILL to ensure that the process will be killed if the
UML kernel dies unexpectedly without proper cleanup. This helper will
be used in the follow-up patches.
Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
---
arch/um/include/shared/os.h | 2 ++
arch/um/os-Linux/process.c | 6 ++++++
2 files changed, 8 insertions(+)
diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
index 09f8201de5db..d709a24dc6fc 100644
--- a/arch/um/include/shared/os.h
+++ b/arch/um/include/shared/os.h
@@ -216,6 +216,8 @@ extern int os_drop_memory(void *addr, int length);
extern int can_drop_memory(void);
extern int os_mincore(void *addr, unsigned long len);
+void os_set_pdeathsig(void);
+
/* execvp.c */
extern int execvp_noalloc(char *buf, const char *file, char *const argv[]);
/* helper.c */
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c
index f20602e793d9..9f086f939420 100644
--- a/arch/um/os-Linux/process.c
+++ b/arch/um/os-Linux/process.c
@@ -12,6 +12,7 @@
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ptrace.h>
+#include <sys/prctl.h>
#include <sys/wait.h>
#include <asm/unistd.h>
#include <init.h>
@@ -203,3 +204,8 @@ void init_new_thread_signals(void)
set_handler(SIGIO);
signal(SIGWINCH, SIG_IGN);
}
+
+void os_set_pdeathsig(void)
+{
+ prctl(PR_SET_PDEATHSIG, SIGKILL);
+}
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] um: Set parent-death signal for ubd io thread/process
2024-10-24 14:28 [PATCH 0/4] um: Set parent-death signal for sub-processes Tiwei Bie
2024-10-24 14:28 ` [PATCH 1/4] um: Add os_set_pdeathsig helper function Tiwei Bie
@ 2024-10-24 14:28 ` Tiwei Bie
2024-10-24 14:28 ` [PATCH 3/4] um: Set parent-death signal for write_sigio thread/process Tiwei Bie
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Tiwei Bie @ 2024-10-24 14:28 UTC (permalink / raw)
To: richard, anton.ivanov, johannes; +Cc: linux-um, linux-kernel, Tiwei Bie
The ubd io thread is not really a traditional thread. Set the
parent-death signal for it to ensure that it will be killed if
the UML kernel dies unexpectedly without proper cleanup.
Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
---
arch/um/drivers/ubd_kern.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 7f28ec1929dc..2b8d04e67600 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -1499,6 +1499,7 @@ int io_thread(void *arg)
{
int n, count, written, res;
+ os_set_pdeathsig();
os_fix_helper_signals();
while(1){
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] um: Set parent-death signal for write_sigio thread/process
2024-10-24 14:28 [PATCH 0/4] um: Set parent-death signal for sub-processes Tiwei Bie
2024-10-24 14:28 ` [PATCH 1/4] um: Add os_set_pdeathsig helper function Tiwei Bie
2024-10-24 14:28 ` [PATCH 2/4] um: Set parent-death signal for ubd io thread/process Tiwei Bie
@ 2024-10-24 14:28 ` Tiwei Bie
2024-10-24 14:28 ` [PATCH 4/4] um: Use os_set_pdeathsig helper in winch thread/process Tiwei Bie
2024-10-25 9:37 ` [PATCH 0/4] um: Set parent-death signal for sub-processes Johannes Berg
4 siblings, 0 replies; 6+ messages in thread
From: Tiwei Bie @ 2024-10-24 14:28 UTC (permalink / raw)
To: richard, anton.ivanov, johannes; +Cc: linux-um, linux-kernel, Tiwei Bie
The write_sigio thread is not really a traditional thread. Set
the parent-death signal for it to ensure that it will be killed
if the UML kernel dies unexpectedly without proper cleanup.
Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
---
arch/um/os-Linux/sigio.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c
index 9e71794839e8..9aac8def4d63 100644
--- a/arch/um/os-Linux/sigio.c
+++ b/arch/um/os-Linux/sigio.c
@@ -55,6 +55,7 @@ static int write_sigio_thread(void *unused)
int i, n, respond_fd;
char c;
+ os_set_pdeathsig();
os_fix_helper_signals();
fds = ¤t_poll;
while (1) {
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] um: Use os_set_pdeathsig helper in winch thread/process
2024-10-24 14:28 [PATCH 0/4] um: Set parent-death signal for sub-processes Tiwei Bie
` (2 preceding siblings ...)
2024-10-24 14:28 ` [PATCH 3/4] um: Set parent-death signal for write_sigio thread/process Tiwei Bie
@ 2024-10-24 14:28 ` Tiwei Bie
2024-10-25 9:37 ` [PATCH 0/4] um: Set parent-death signal for sub-processes Johannes Berg
4 siblings, 0 replies; 6+ messages in thread
From: Tiwei Bie @ 2024-10-24 14:28 UTC (permalink / raw)
To: richard, anton.ivanov, johannes; +Cc: linux-um, linux-kernel, Tiwei Bie
Since we have a helper now, let's switch to using it. It will make
the code slightly more consistent.
Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
---
arch/um/drivers/chan_user.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/um/drivers/chan_user.c b/arch/um/drivers/chan_user.c
index 1434114b2f34..35f9beeb19b3 100644
--- a/arch/um/drivers/chan_user.c
+++ b/arch/um/drivers/chan_user.c
@@ -10,7 +10,6 @@
#include <signal.h>
#include <termios.h>
#include <sys/ioctl.h>
-#include <sys/prctl.h>
#include "chan_user.h"
#include <os.h>
#include <um_malloc.h>
@@ -162,7 +161,7 @@ static __noreturn int winch_thread(void *arg)
int count;
char c = 1;
- prctl(PR_SET_PDEATHSIG, SIGKILL);
+ os_set_pdeathsig();
pty_fd = data->pty_fd;
pipe_fd = data->pipe_fd;
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] um: Set parent-death signal for sub-processes
2024-10-24 14:28 [PATCH 0/4] um: Set parent-death signal for sub-processes Tiwei Bie
` (3 preceding siblings ...)
2024-10-24 14:28 ` [PATCH 4/4] um: Use os_set_pdeathsig helper in winch thread/process Tiwei Bie
@ 2024-10-25 9:37 ` Johannes Berg
4 siblings, 0 replies; 6+ messages in thread
From: Johannes Berg @ 2024-10-25 9:37 UTC (permalink / raw)
To: Tiwei Bie, richard, anton.ivanov; +Cc: linux-um, linux-kernel
On Thu, 2024-10-24 at 22:28 +0800, Tiwei Bie wrote:
> The ubd io and write_sigio threads/processes may leak e.g. when
> the main process is killed by "kill -9". Fix it by setting the
> parent-death signal for them.
>
I always used killall, but yeah, good idea, thanks!
johannes
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-10-25 9:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-24 14:28 [PATCH 0/4] um: Set parent-death signal for sub-processes Tiwei Bie
2024-10-24 14:28 ` [PATCH 1/4] um: Add os_set_pdeathsig helper function Tiwei Bie
2024-10-24 14:28 ` [PATCH 2/4] um: Set parent-death signal for ubd io thread/process Tiwei Bie
2024-10-24 14:28 ` [PATCH 3/4] um: Set parent-death signal for write_sigio thread/process Tiwei Bie
2024-10-24 14:28 ` [PATCH 4/4] um: Use os_set_pdeathsig helper in winch thread/process Tiwei Bie
2024-10-25 9:37 ` [PATCH 0/4] um: Set parent-death signal for sub-processes Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®