prctl: add PR_[GS]ET_KILLABLE
Subsystems (4)
PATCH 1/1 prctl: add PR_[GS]ET_KILLABLE
PR_SET_KILLABLE clears the SIGNAL_UNKILLABLE flag. This allows CLONE_NEWPID tasks to restore normal signal behavior, opting out of the special signal protection for init processes.
This is required for job control in a shell that uses CLONE_NEWPID for child processes.
This prctl does not allow setting the SIGNAL_UNKILLABLE flag, only clearing.
--- include/uapi/linux/prctl.h | 4 ++++ kernel/sys.c | 11 +++++++++++ 2 files changed, 15 insertions(+)
include/uapi/linux/prctl.h +4 -0
@@ -219,4 +219,8 @@ struct prctl_mm_map {# define PR_SPEC_DISABLE (1UL << 2)# define PR_SPEC_FORCE_DISABLE (1UL << 3) +/* Control SIGNAL_UNKILLABLE */ +#define PR_GET_KILLABLE 54 +#define PR_SET_KILLABLE 55 +#endif /* _LINUX_PRCTL_H */
kernel/sys.c +11 -0
@@ -2484,6 +2484,17 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,return -EINVAL ; error =arch_prctl_spec_ctrl_set (me, arg2, arg3);break ; +case PR_GET_KILLABLE : +if (arg3 || arg4 || arg5) +return -EINVAL ; + error =put_user (!(me->signal->flags &SIGNAL_UNKILLABLE ), + (int __user *)arg2); +break ; +case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; + me->signal->flags &= ~SIGNAL_UNKILLABLE ; +break ;default : error = -EINVAL ;break ;
Signature · 1 line
2.18.0
Quoted 3 lines · Jürg Billeter
This is required for job control in a shell that uses
CLONE_NEWPIDfor child processes.
Could you explain in more details?
kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 2496
Quoted 4 lines
kernel/sys.c +4
-0+case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; + me->signal->flags &= ~SIGNAL_UNKILLABLE ;
this needs spin_lock_irq(me->sighand->siglock).
Oleg.
Quoted 6 lines · Oleg Nesterov
Quoted 3 lines · Jürg Billeter
This is required for job control in a shell that uses
CLONE_NEWPIDfor child processes.Could you explain in more details?
The SIGNAL_UNKILLABLE flag, which is implicitly set for tasks cloned with CLONE_NEWPID, has the effect of ignoring all signals (from userspace) if the corresponding handler is set to SIG_DFL. The only exceptions are SIGKILL and SIGSTOP and they are only accepted if raised from an ancestor namespace.
SIGINT, SIGQUIT and SIGTSTP are used in job control for ^C, ^\, ^Z. While a task with the SIGNAL_UNKILLABLE flag could install handlers for these signals, this is not sufficient to implement a shell that uses CLONE_NEWPID for child processes:
* As SIGSTOP is ignored when raised from the SIGNAL_UNKILLABLE process itself, I don't think it's possible to implement the stop action in a custom SIGTSTP handler.
* Many applications do not install handlers for these signals and thus, job control won't work properly with unmodified applications.
Job control in a shell is just an example. There are other scenarios, of course, where applications rely on the default actions as described in signal(7), and PID isolation may be useful. In my opinion, the kernel support for preventing accidental killing of the "init" process should really be optional and this new prctl provides this without breaking backward compatibility.
Quoted 6 lines
kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 2496
Quoted 4 lines
kernel/sys.c +4
-0+case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; + me->signal->flags &= ~SIGNAL_UNKILLABLE ;this needs
spin_lock_irq(me->sighand->siglock).
Thanks for the review, will fix this for v2.
Jürg
Quoted 25 lines · Jürg Billeter
Quoted 6 lines · Oleg Nesterov
Quoted 3 lines · Jürg Billeter
This is required for job control in a shell that uses
CLONE_NEWPIDfor child processes.Could you explain in more details?
The
SIGNAL_UNKILLABLEflag, which is implicitly set for tasks cloned withCLONE_NEWPID, has the effect of ignoring all signals (from userspace) if the corresponding handler is set toSIG_DFL. The only exceptions are SIGKILL and SIGSTOP and they are only accepted if raised from an ancestor namespace.SIGINT, SIGQUIT and SIGTSTP are used in job control for ^C, ^\, ^Z. While a task with the
SIGNAL_UNKILLABLEflag could install handlers for these signals, this is not sufficient to implement a shell that usesCLONE_NEWPIDfor child processes:* As SIGSTOP is ignored when raised from the
SIGNAL_UNKILLABLEprocess itself, I don't think it's possible to implement the stop action in a custom SIGTSTP handler.
* Many applications do not install handlers for these signals and thus, job control won't work properly with unmodified applications.
Quoted 6 lines
Job control in a shell is just an example. There are other scenarios, of course, where applications rely on the default actions as described in signal(7), and PID isolation may be useful. In my opinion, the kernel support for preventing accidental killing of the "init" process should really be optional and this new prctl provides this without breaking backward compatibility.
This makes sense and exactly that information needs to be in the changelog.
Thanks,
tglx
PATCH v2 1/1 prctl: add PR_[GS]ET_KILLABLE
In reply to Jürg BilleterPR_SET_KILLABLE clears the SIGNAL_UNKILLABLE flag. This allows CLONE_NEWPID tasks to restore normal signal behavior, opting out of the special signal protection for init processes. This prctl does not allow setting the SIGNAL_UNKILLABLE flag, only clearing.
The SIGNAL_UNKILLABLE flag, which is implicitly set for tasks cloned with CLONE_NEWPID, has the effect of ignoring all signals (from userspace) if the corresponding handler is set to SIG_DFL. The only exceptions are SIGKILL and SIGSTOP and they are only accepted if raised from an ancestor namespace.
SIGINT, SIGQUIT and SIGTSTP are used in job control for ^C, ^\, ^Z. While a task with the SIGNAL_UNKILLABLE flag could install handlers for these signals, this is not sufficient to implement a shell that uses CLONE_NEWPID for child processes:
* As SIGSTOP is ignored when raised from the SIGNAL_UNKILLABLE process itself, it's not possible to implement the stop action in a custom SIGTSTP handler.
* Many applications do not install handlers for these signals and thus, job control won't work properly with unmodified applications.
There are other scenarios besides job control in a shell where applications rely on the default actions as described in signal(7) and PID isolation may be useful. This new prctl makes the signal protection for "init" processes optional, without breaking backward compatibility.
---
v2: Hold siglock for PR_SET_KILLABLE, expand commit message.
include/uapi/linux/prctl.h | 4 ++++ kernel/sys.c | 13 +++++++++++++ 2 files changed, 17 insertions(+)
include/uapi/linux/prctl.h +4 -0
@@ -219,4 +219,8 @@ struct prctl_mm_map {# define PR_SPEC_DISABLE (1UL << 2)# define PR_SPEC_FORCE_DISABLE (1UL << 3) +/* Control SIGNAL_UNKILLABLE */ +#define PR_GET_KILLABLE 54 +#define PR_SET_KILLABLE 55 +#endif /* _LINUX_PRCTL_H */
kernel/sys.c +13 -0
@@ -2484,6 +2484,19 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,return -EINVAL ; error =arch_prctl_spec_ctrl_set (me, arg2, arg3);break ; +case PR_GET_KILLABLE : +if (arg3 || arg4 || arg5) +return -EINVAL ; + error =put_user (!(me->signal->flags &SIGNAL_UNKILLABLE ), + (int __user *)arg2); +break ; +case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; +spin_lock_irq (&me->sighand->siglock); + me->signal->flags &= ~SIGNAL_UNKILLABLE ; +spin_unlock_irq (&me->sighand->siglock); +break ;default : error = -EINVAL ;break ;
Signature · 1 line
2.18.0
Quoted 12 lines · Jürg Billeter
PR_SET_KILLABLEclears theSIGNAL_UNKILLABLEflag. This allowsCLONE_NEWPIDtasks to restore normal signal behavior, opting out of the special signal protection for init processes. This prctl does not allow setting theSIGNAL_UNKILLABLEflag, only clearing.The
SIGNAL_UNKILLABLEflag, which is implicitly set for tasks cloned withCLONE_NEWPID, has the effect of ignoring all signals (from userspace) if the corresponding handler is set toSIG_DFL. The only exceptions are SIGKILL and SIGSTOP and they are only accepted if raised from an ancestor namespace.
Quoted 4 lines
SIGINT, SIGQUIT and SIGTSTP are used in job control for ^C, ^\, ^Z. While a task with the
SIGNAL_UNKILLABLEflag could install handlers for these signals, this is not sufficient to implement a shell that usesCLONE_NEWPIDfor child processes:
Ah. My question wasn't clear, sorry.
Could you explain your use-case? Why a shell wants to use CLONE_NEWPID? And what do we actually want in, say, ^Z case? Just stop the child reaper or may be it would be better to stop the whole pid namespace?
Quoted 3 lines
* As SIGSTOP is ignored when raised from the
SIGNAL_UNKILLABLEprocess itself, it's not possible to implement the stop action in a custom SIGTSTP handler.
Yes. So may be we actually want to change __isig() paths to use SEND_SIG_FORCED (this is not that simple), or perhaps we can change __send_signal() to not drop SIGSTOP sent to itself, or may be we can even introduce SIG_DFL_EVEN_IF_INIT, I dunno.
Quoted 2 lines
* Many applications do not install handlers for these signals and thus, job control won't work properly with unmodified applications.
I can't understand this. An application should be changed anyway to do PR_SET_KILLABLE?
Let me clarify. I am not arguing with this patch, probably it makes sense in any case. I am just trying to understand your real motivation for this change.
kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 2498
Quoted 6 lines
kernel/sys.c +6
-0+case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; +spin_lock_irq (&me->sighand->siglock); + me->signal->flags &= ~SIGNAL_UNKILLABLE ; +spin_unlock_irq (&me->sighand->siglock);
OK, but then you need to change the CLONE_PARENT/SIGNAL_UNKILLABLE check in copy_process().
Oleg.
Quoted 10 lines · Oleg Nesterov
Quoted 4 lines · Jürg Billeter
SIGINT, SIGQUIT and SIGTSTP are used in job control for ^C, ^\, ^Z. While a task with the
SIGNAL_UNKILLABLEflag could install handlers for these signals, this is not sufficient to implement a shell that usesCLONE_NEWPIDfor child processes:Ah. My question wasn't clear, sorry.
Could you explain your use-case? Why a shell wants to use
CLONE_NEWPID?
To guarantee that there won't be any runaway processes, i.e., ensure that no descendants (background helper daemons or misbehaving processes) survive when the child process is terminated. And to prevent children from killing their ancestors. This is not something that can be always-on in all shells, but it could be an option for users that want this control/isolation.
Quoted 2 lines
And what do we actually want in, say, ^Z case? Just stop the child reaper or may be it would be better to stop the whole pid namespace?
Stopping the whole PID namespace would be interesting, however, I think this should be discussed separately if and when there is a proposal to support this. For now the process group is stopped, same as without PID namespaces.
Quoted 8 lines
Quoted 3 lines
* As SIGSTOP is ignored when raised from the
SIGNAL_UNKILLABLEprocess itself, it's not possible to implement the stop action in a custom SIGTSTP handler.Yes. So may be we actually want to change
__isig()paths to useSEND_SIG_FORCED(this is not that simple), or perhaps we can change__send_signal()to not drop SIGSTOP sent to itself, or may be we can even introduceSIG_DFL_EVEN_IF_INIT, I dunno.
In my opinion, my patch is much simpler and also more general as it covers all scenarios where regular signal handling is required or desired for "init" processes, with minimal code changes (after PR_SET_KILLABLE, binaries that expect SIG_DFL to work can be executed without changes).
Quoted 5 lines
Quoted 2 lines
* Many applications do not install handlers for these signals and thus, job control won't work properly with unmodified applications.
I can't understand this. An application should be changed anyway to do
PR_SET_KILLABLE?
PR_SET_KILLABLE can be called (e.g., by the shell) between clone() and execve(). (Some applications may have issues running as subreaper but that's a separate matter, signal handling will work as expected).
Quoted 9 lines
kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 2498
Quoted 6 lines
kernel/sys.c +6
-0+case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; +spin_lock_irq (&me->sighand->siglock); + me->signal->flags &= ~SIGNAL_UNKILLABLE ; +spin_unlock_irq (&me->sighand->siglock);OK, but then you need to change the CLONE_PARENT/SIGNAL_UNKILLABLE check in
copy_process().
Good point, need a different check for the PID namespace root process in copy_process().
Thanks,
Jürg
Quoted 7 lines · Jürg Billeter
Quoted 3 lines
Could you explain your use-case? Why a shell wants to use
CLONE_NEWPID?To guarantee that there won't be any runaway processes, i.e., ensure that no descendants (background helper daemons or misbehaving processes) survive when the child process is terminated.
We already have PR_SET_CHILD_SUBREAPER.
Perhaps we can finally add PR_KILL_MY_DESCENDANTS_ON_EXIT? This was already discussed some time ago, but I can't find the previous discussion... Simple to implement.
Quoted 2 lines
And to prevent
children from killing their ancestors.
OK, this is the only reason for CLONE_NEWPID which I can understand so far. Not that I understand why this is that useful ;)
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
* As SIGSTOP is ignored when raised from the
SIGNAL_UNKILLABLEprocess itself, it's not possible to implement the stop action in a custom SIGTSTP handler.Yes. So may be we actually want to change
__isig()paths to useSEND_SIG_FORCED(this is not that simple), or perhaps we can change__send_signal()to not drop SIGSTOP sent to itself, or may be we can even introduceSIG_DFL_EVEN_IF_INIT, I dunno.In my opinion, my patch is much simpler and also more general as it
Yes, yes, let me repeat that I am not arguing with your patch, I am just trying to understand what
Quoted 5 lines
Quoted 2 lines
I can't understand this. An application should be changed anyway to do
PR_SET_KILLABLE?
PR_SET_KILLABLEcan be called (e.g., by the shell) betweenclone()andexecve().
OK, this is true.
Oleg.
Quoted 9 lines · Oleg Nesterov
Quoted 7 lines · Jürg Billeter
Quoted 3 lines
Could you explain your use-case? Why a shell wants to use
CLONE_NEWPID?To guarantee that there won't be any runaway processes, i.e., ensure that no descendants (background helper daemons or misbehaving processes) survive when the child process is terminated.
Quoted 5 lines
We already have
PR_SET_CHILD_SUBREAPER.Perhaps we can finally add
PR_KILL_MY_DESCENDANTS_ON_EXIT? This was already discussed some time ago, but I can't find the previous discussion... Simple to implement.
This would definitely be an option. You mentioned it last October in the PR_SET_PDEATHSIG_PROC discussion¹. However, as PID namespaces already exist and appear to be a good fit for the most part, I think it makes sense to just add the missing pieces to PID namespaces instead of duplicating part of the PID namespace functionality.
Also, based on Eric's comment in that other discussion about no_new_privs not being allowed to increase the attack surface, PR_KILL_MY_DESCENDANTS_ON_EXIT might require CAP_SYS_ADMIN as well (due to setuid children). In which case the only potential benefit would be that it still allows the child to kill arbitrary processes, as far as I can tell.
Quoted 4 lines
Quoted 1 line
And to prevent children from killing their ancestors.
OK, this is the only reason for
CLONE_NEWPIDwhich I can understand so far. Not that I understand why this is that useful ;)
The overall goal is increasing isolation between (some) child processes and the rest of the system. Isolation from runaway processes and isolation from signals are independent aspects and it could be useful to control them independently. However, I also expect it to be common that both are wanted at the same time.
Jürg
Quoted 13 lines · Jürg Billeter
Quoted 11 lines · Oleg Nesterov
Quoted 7 lines · Jürg Billeter
Quoted 3 lines
Could you explain your use-case? Why a shell wants to use
CLONE_NEWPID?To guarantee that there won't be any runaway processes, i.e., ensure that no descendants (background helper daemons or misbehaving processes) survive when the child process is terminated.
We already have
PR_SET_CHILD_SUBREAPER.
Quoted 7 lines
Quoted 3 lines
Perhaps we can finally add
PR_KILL_MY_DESCENDANTS_ON_EXIT? This was already discussed some time ago, but I can't find the previous discussion... Simple to implement.This would definitely be an option. You mentioned it last October in the
PR_SET_PDEATHSIG_PROCdiscussion¹. However, as PID namespaces already exist and appear to be a good fit for the most part,
Sure, if CLONE_NEWPID fits your needs you can use it,
Quoted 3 lines
I think it
makes sense to just add the missing pieces to PID namespaces instead of duplicating part of the PID namespace functionality.
Again, I am not arguing with your change.
PR_KILL_MY_DESCENDANTS_ON_EXIT can make sense just like PR_SET_CHILD_SUBREAPER even if PID namespace functionality implies both. Simply because CLONE_NEWPID is not necessarily the best tool, if nothing else you do not necessarily want the pid isolation.
Quoted 4 lines
Also, based on Eric's comment in that other discussion about
no_new_privsnot being allowed to increase the attack surface,PR_KILL_MY_DESCENDANTS_ON_EXITmight requireCAP_SYS_ADMINas well (due to setuid children).
No, no, the exiting parent should simply do group_send_sig_info(SIGKILL) for every descendant and rely on check_kill_permission().
OK, lets forget it for now.
Oleg.
Quoted 22 lines · Jürg Billeter
Quoted 9 lines · Oleg Nesterov
Quoted 7 lines · Jürg Billeter
Quoted 3 lines
Could you explain your use-case? Why a shell wants to use
CLONE_NEWPID?To guarantee that there won't be any runaway processes, i.e., ensure that no descendants (background helper daemons or misbehaving processes) survive when the child process is terminated.
Quoted 5 lines
We already have
PR_SET_CHILD_SUBREAPER.Perhaps we can finally add
PR_KILL_MY_DESCENDANTS_ON_EXIT? This was already discussed some time ago, but I can't find the previous discussion... Simple to implement.This would definitely be an option. You mentioned it last October in the
PR_SET_PDEATHSIG_PROCdiscussion¹. However, as PID namespaces already exist and appear to be a good fit for the most part, I think it makes sense to just add the missing pieces to PID namespaces instead of duplicating part of the PID namespace functionality.
Quoted 6 lines
Also, based on Eric's comment in that other discussion about
no_new_privsnot being allowed to increase the attack surface,PR_KILL_MY_DESCENDANTS_ON_EXITmight requireCAP_SYS_ADMINas well (due to setuid children). In which case the only potential benefit would be that it still allows the child to kill arbitrary processes, as far as I can tell.
We don't require CAP_SYS_ADMIN if it is a session and so I think a similar allowance can be made for PR_KILL_MY_DESCENDANTS_ON_EXIT. There is a long standing tradition of being able to kill your own descendants in linux. I don't think this allows anything that the tranditional session allowance for killing process won't.
Quoted 1 line
From the other direction I think we can just go ahead and fix handling
of the job control stop signals as well. As far as I understand it there is a legitimate complaint that SIGTSTP SIGTTIN SIGTTOU do not work on a pid namespace leader.
The current implementation actual overshoots. We only need to ignore signals from the descendants in the pid namespace. Ideally signals from other processes are treated like normal. We have only been able to apply that ideal to SIGSTOP and SIGKILL as we can handle them in prepare_signal. Other signals can be blocked which means the logic to handle them needs to live in get_signal where we may have no sender information.
Signals with signal handlers we treat as normal.
Signals with whose default action is to ignore the signal we treat as normal.
If a process is not in a context where job control has been set up then SIGTSTP SIGTTIN and SIGTTOU are ignored. I believe a typical init process lives in just such an environment. So I think we can safely remove the special handling for the job control stops and not have anyone care.
The rule is that the process group of the process must have a parent in the same session, or the job control signals are ignored.
A typical init processes calls setsid, which guarantees it has no parents in the same session. So the default action of the job control stops will be to ignore the signal.
A process once a session leader will always be a session leader, and will never have any parents in a different pgrp in the same session.
So I think this gives us wiggle room needed to just fix this behavior.
Let's see.
For the signals SIGTSTP SIGTTIN and SIGTTOU if we are the typical init process and we are a session leader we simply don't care who sends those signals they will be ignored.
So I say we double check my assumption. Look at sysv init, busy box, upstart, systemd, whatever android uses, and the container runtimes light weight inits. Document it in a change log and just remove the special case.
If except when handling job control signals is interesting init always winds up a signal group leader I can't see the point in forcing init to ignore the job control stop signals.
Quoted 1 line
In the future please use mesage-id based links to email disccussions. That way people can look up the conversations in other email archives.
Eric
Quoted 5 lines · Eric W. Biederman
From the other direction I think we can just go ahead and fix handling of the job control stop signals as well. As far as I understand it there is a legitimate complaint that SIGTSTP SIGTTIN SIGTTOU do not work on a pid namespace leader.
Quoted 7 lines
The current implementation actual overshoots. We only need to ignore signals from the descendants in the pid namespace. Ideally signals from other processes are treated like normal. We have only been able to apply that ideal to SIGSTOP and SIGKILL as we can handle them in
prepare_signal. Other signals can be blocked which means the logic to handle them needs to live inget_signalwhere we may have no sender information.
SIGINT and SIGQUIT are also relevant for job control. Would the same approach be possible for them?
And I would like to allow regular POSIX signal behavior also for signals used outside job control, e.g., SIGTERM, for maximum compatibility with existing applications. Furthermore, it would also be good to allow a PID namespace leader to send a signal to itself.
Do you think we can and should cover all of the above without a prctl by loosening the restrictions imposed by SIGNAL_UNKILLABLE (with reasonable effort)?
In my opinion, my patch still makes sense as it simply allows regular POSIX signal behavior for PID namespace leaders and it doesn't risk any compatibility issues as the behavior doesn't change at all for processes that don't invoke the new prctl. I.e., simple patch, low risk, and covers all signals.
In the meantime I've tested the missing patch for copy_process() and will send out v3 of the patch in case the new prctl makes sense after all.
Jürg
Quoted 13 lines · Jürg Billeter
PR_SET_KILLABLEclears theSIGNAL_UNKILLABLEflag. This allowsCLONE_NEWPIDtasks to restore normal signal behavior, opting out of the special signal protection for init processes.This is required for job control in a shell that uses
CLONE_NEWPIDfor child processes.This prctl does not allow setting the
SIGNAL_UNKILLABLEflag, only clearing.Signed-off-by Jürg Billeter <[email protected]>---
[...]
Quoted 4 lines
kernel/sys.c +0
-0
[...]
kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 2497
Quoted 5 lines
kernel/sys.c +5
-0+case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; + me->signal->flags &= ~SIGNAL_UNKILLABLE ; +break ;
I don't have an opinion on this patchset otherwise, but should this prctl maybe block PR_SET_KILLABLE if you're actually the real init process? This seems like it could potentially lead to weird things.
This code in kernel/fork.c seems to rely on the fact that global init is SIGNAL_UNKILLABLE, and probably also leads to weirdness if container init is non-SIGNAL_UNKILLABLE:
/*
* Siblings of global init remain as zombies on exit since they are
* not reaped by their parent (swapper). To solve this and to avoid
* multi-rooted process trees, prevent global and container-inits
* from creating siblings.
*/
if ((clone_flags & CLONE_PARENT) &&
current->signal->flags & SIGNAL_UNKILLABLE)
return ERR_PTR(-EINVAL);Quoted 15 lines · Jann Horn
On Mon, Jul 30, 2018 at 10:01 AM Jürg Billeter <[email protected]> wrote:
[...]
Quoted 4 lines
kernel/sys.c +0
-0[...]
kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 2497
Quoted 5 lines
kernel/sys.c +5
-0+case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; + me->signal->flags &= ~SIGNAL_UNKILLABLE ; +break ;
Quoted 3 lines
I don't have an opinion on this patchset otherwise, but should this prctl maybe block
PR_SET_KILLABLEif you're actually the real init process? This seems like it could potentially lead to weird things.
While I don't expect global init to use this, I can't think of a good reason to disallow it in the kernel. Do you have specific concerns or is the code in kernel/fork.c the only reason? I prefer avoiding special cases unless really required.
Quoted 3 lines
This code in
kernel/fork.cseems to rely on the fact that global init isSIGNAL_UNKILLABLE, and probably also leads to weirdness if container init is non-SIGNAL_UNKILLABLE:
Yes, Oleg has mentioned this as well. I have to change copy_process() to directly check for the PID namespace root process instead of checking for SIGNAL_UNKILLABLE.
Jürg
Quoted 17 lines · Jürg Billeter
Quoted 15 lines · Jann Horn
On Mon, Jul 30, 2018 at 10:01 AM Jürg Billeter <[email protected]> wrote:
[...]
Quoted 4 lines
kernel/sys.c +0
-0[...]
Quoted 5 lines
kernel/sys.c +5
-0+case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; + me->signal->flags &= ~SIGNAL_UNKILLABLE ; +break ;
Quoted 7 lines
Quoted 3 lines
I don't have an opinion on this patchset otherwise, but should this prctl maybe block
PR_SET_KILLABLEif you're actually the real init process? This seems like it could potentially lead to weird things.While I don't expect global init to use this, I can't think of a good reason to disallow it in the kernel. Do you have specific concerns or is the code in
kernel/fork.cthe only reason?
No, I don't have any other specific concerns.
Quoted 1 line
I prefer avoiding special cases unless really required.
PATCH v3 1/2 fork: do not rely on SIGNAL_UNKILLABLE for init check
In reply to Jürg Billetercopy_process() currently checks the SIGNAL_UNKILLABLE flag to determine whether to accept CLONE_PARENT. In preparation for allowing init processes to opt out of SIGNAL_UNKILLABLE, directly check whether the process is an init process with is_child_reaper().
--- kernel/fork.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/fork.c +1 -1
@@ -1646,7 +1646,7 @@ static __latent_entropy struct task_struct *copy_process(* from creating siblings. */ if ((clone_flags &CLONE_PARENT ) && - current->signal->flags &SIGNAL_UNKILLABLE ) +is_child_reaper (task_tgid (current)))return ERR_PTR (-EINVAL );/*
Signature · 1 line
2.18.0
PATCH v3 2/2 prctl: add PR_[GS]ET_KILLABLE
PR_SET_KILLABLE clears the SIGNAL_UNKILLABLE flag. This allows CLONE_NEWPID tasks to restore normal signal behavior, opting out of the special signal protection for init processes. This prctl does not allow setting the SIGNAL_UNKILLABLE flag, only clearing.
The SIGNAL_UNKILLABLE flag, which is implicitly set for tasks cloned with CLONE_NEWPID, has the effect of ignoring all signals (from userspace) if the corresponding handler is set to SIG_DFL. The only exceptions are SIGKILL and SIGSTOP and they are only accepted if raised from an ancestor namespace.
SIGINT, SIGQUIT and SIGTSTP are used in job control for ^C, ^\, ^Z. While a task with the SIGNAL_UNKILLABLE flag could install handlers for these signals, this is not sufficient to implement a shell that uses CLONE_NEWPID for child processes:
* As SIGSTOP is ignored when raised from the SIGNAL_UNKILLABLE process itself, it's not possible to implement the stop action in a custom SIGTSTP handler.
* Many applications do not install handlers for these signals and thus, job control won't work properly with unmodified applications.
There are other scenarios besides job control in a shell where applications rely on the default actions as described in signal(7) and PID isolation may be useful. This new prctl makes the signal protection for "init" processes optional, without breaking backward compatibility.
--- include/uapi/linux/prctl.h | 4 ++++ kernel/sys.c | 13 +++++++++++++ 2 files changed, 17 insertions(+)
include/uapi/linux/prctl.h +4 -0
@@ -219,4 +219,8 @@ struct prctl_mm_map {# define PR_SPEC_DISABLE (1UL << 2)# define PR_SPEC_FORCE_DISABLE (1UL << 3) +/* Control SIGNAL_UNKILLABLE */ +#define PR_GET_KILLABLE 54 +#define PR_SET_KILLABLE 55 +#endif /* _LINUX_PRCTL_H */
kernel/sys.c +13 -0
@@ -2484,6 +2484,19 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,return -EINVAL ; error =arch_prctl_spec_ctrl_set (me, arg2, arg3);break ; +case PR_GET_KILLABLE : +if (arg3 || arg4 || arg5) +return -EINVAL ; + error =put_user (!(me->signal->flags &SIGNAL_UNKILLABLE ), + (int __user *)arg2); +break ; +case PR_SET_KILLABLE : +if (arg2 !=1 || arg3 || arg4 || arg5) +return -EINVAL ; +spin_lock_irq (&me->sighand->siglock); + me->signal->flags &= ~SIGNAL_UNKILLABLE ; +spin_unlock_irq (&me->sighand->siglock); +break ;default : error = -EINVAL ;break ;
Signature · 1 line
2.18.0
Andrew Morton
maintainerQuoted 22 lines · On Fri, 3 Aug 2018 16:40:21 +0200 Jürg Billeter <[email protected]> wrote:
PR_SET_KILLABLEclears theSIGNAL_UNKILLABLEflag. This allowsCLONE_NEWPIDtasks to restore normal signal behavior, opting out of the special signal protection for init processes. This prctl does not allow setting theSIGNAL_UNKILLABLEflag, only clearing.The
SIGNAL_UNKILLABLEflag, which is implicitly set for tasks cloned withCLONE_NEWPID, has the effect of ignoring all signals (from userspace) if the corresponding handler is set toSIG_DFL. The only exceptions are SIGKILL and SIGSTOP and they are only accepted if raised from an ancestor namespace.SIGINT, SIGQUIT and SIGTSTP are used in job control for ^C, ^\, ^Z. While a task with the
SIGNAL_UNKILLABLEflag could install handlers for these signals, this is not sufficient to implement a shell that usesCLONE_NEWPIDfor child processes:* As SIGSTOP is ignored when raised from the
SIGNAL_UNKILLABLEprocess itself, it's not possible to implement the stop action in a custom SIGTSTP handler.
* Many applications do not install handlers for these signals and thus, job control won't work properly with unmodified applications.
Quoted 4 lines
There are other scenarios besides job control in a shell where applications rely on the default actions as described in signal(7) and PID isolation may be useful. This new prctl makes the signal protection for "init" processes optional, without breaking backward compatibility.
This one is above my pay grade. Eric & Oleg: could you please provide input?