Re: [PATCH 1/2] signal: don't allow sending any signals to PF_IO_WORKER threads
From: Jens Axboe
Date: Sat Mar 20 2021 - 18:43:02 EST
On 3/20/21 3:38 PM, Eric W. Biederman wrote:
> Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> writes:
>> On Sat, Mar 20, 2021 at 9:19 AM Eric W. Biederman <ebiederm@xxxxxxxxxxxx> wrote:
>>> The creds should be reasonably in-sync with the rest of the threads.
>> It's not about credentials (despite the -EPERM).
>> It's about the fact that kernel threads cannot handle signals, and
>> then get caught in endless loops of "if (sigpending()) return
>> For a normal user thread, that "return -EAGAIN" (or whatever) will end
>> up returning an error to user space - and before it does that, it will
>> go through the "oh, returning to user space, so handle signal" path.
>> Which will clear sigpending etc.
>> A thread that never returns to user space fundamentally cannot handle
>> this. The sigpending() stays on forever, the signal never gets
>> handled, the thread can't do anything.
>> So delivering a signal to a kernel thread fundamentally cannot work
>> (although we do have some threads that explicitly see "oh, if I was
>> killed, I will exit" - think things like in-kernel nfsd etc).
> I agree that getting a kernel thread to receive a signal is quite
> tricky. But that is not what the patch affects.
> The patch covers the case when instead of specifying the pid of the
> process to kill(2) someone specifies the tid of a thread. Which implies
> that type is PIDTYPE_TGID, and in turn the signal is being placed on the
> t->signal->shared_pending queue. Not the thread specific t->pending
> So my question is since the signal is delivered to the process as a
> whole why do we care if someone specifies the tid of a kernel thread,
> rather than the tid of a userspace thread?
Right, that's what this first patch does, and in all honesty, it's not
required like the 2/2 patch is. I do think it makes it more consistent,
though - the threads don't take signals, period. Allowing delivery from
eg kill(2) and then pass it to the owning task of the io_uring is
somewhat counterintuitive, and differs from earlier kernels where there
was no relationsship between that owning task and the async worker
That's why I think the patch DOES make sense. These threads may share a
personality with the owning task, but I don't think we should be able to
manipulate them from userspace at all. That includes SIGSTOP, of course,
but also regular signals.
Hence I do think we should do something like this.