Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2862075pxf; Sun, 21 Mar 2021 09:23:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMnFSYkSlghR+ffoQ0nf87nCy02jXWefJbO2L9CVuw5cj12mE71pasVPP9oJQDJQVr0RRW X-Received: by 2002:a17:907:76ed:: with SMTP id kg13mr14393652ejc.99.1616343823921; Sun, 21 Mar 2021 09:23:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616343823; cv=none; d=google.com; s=arc-20160816; b=EwJJzRvBZRQSM3kzyXchmZbzxfS+N75lanMDW0xtqnEshSYLWBdblone7yR+kVQ3L9 2YRKdvyVU43thtWLGxL6rNZ7EM3mlEBNTBYhuh9EZS2Rg/va0HN2ANvPEufY6J5ZxhTh cjrv9tUChK9IJBbsivSLx2H0pzwgNRE44qzZcn47j9x/ohMNtL5ANT2guiOicZ3L9Tf/ uSlbSUQVzZHG1s20nJAxHo6wrN8ASIJ6sYUB7HXk1RLrCmFU0fQXEIIktz4CeEqQ7QHO fciaFbPEHAcgFIfyXHLjRSjBS2yPhKBbBrPplcY+wYHfoWsfY9JLMzsSqUloni94CgGF CxLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=cSj4LvG+PL+eupZk/yxZhhmPk+3KBEqBV8K2BbUolG4=; b=apoN8SX8gLPvH0u8EqSqniQ/4hYOG1pe9rKZ1bonthWr6s2TBt0VSRSSngv3htcMXx owCyIyn8Bihyl7jM6h7D9XgSdbadSq0PcyFqXTGvhTFTk2ixqemyUVuSWE0VKr1LgSlL Yj9rEq89HytMzkHBD0FDeZu4iJJJCftIB4jtSK6J9tO89+RriWGSwlcLtai/ujU01Rd3 eib12qrrIXviFjPIlj26Y5dZRGOaYO0hTTIHOy610AEQ0V+8PgxdwOdVjABFxBRKNXSA ijlETdYVshN2PHAZcWkqyIj5zXKi2gWdc86NtExGB5B4m3YfI6nTgRo2MWXmK05VVtZA UsXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=KYshwrcu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si9867529ejr.588.2021.03.21.09.23.21; Sun, 21 Mar 2021 09:23:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=KYshwrcu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230091AbhCUPkZ (ORCPT + 99 others); Sun, 21 Mar 2021 11:40:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230353AbhCUPkO (ORCPT ); Sun, 21 Mar 2021 11:40:14 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B6EFC061762 for ; Sun, 21 Mar 2021 08:40:14 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id k24so6997424pgl.6 for ; Sun, 21 Mar 2021 08:40:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=cSj4LvG+PL+eupZk/yxZhhmPk+3KBEqBV8K2BbUolG4=; b=KYshwrcu3AyE3tNU4VO8dcqQojtWeMPb4f1BV/G+muf9WUX/BBUc/WBs/zG+9qwRu4 GxNpXPABZollLWQhsEQ0w/ybfytvsF1bMtyWabM8Z5Pd9WDrUk5bi+13rbFxRQkBnqQr qA9fB+TJNvHjDrPXapVqic7qESbZqW4HyEldw3qpptYvZYEvubUmVyHx3MycWTGxVVjY iCUpYPxbKrmilIv8ITWPSVItyMj8FOMPEo0/oGKpbhanWTH1xYWvlZ5Mr2BpIoe85/GJ xXRVFrkTO5+hzFZW484IdZjD92tbkcjoCjjEpASwmz3AAfW0x035Mvk3GGPDxK6QhOQG ZYCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cSj4LvG+PL+eupZk/yxZhhmPk+3KBEqBV8K2BbUolG4=; b=AoWKud/dQqU5O5F2aVewWR5z7HkX+Gcyw1MYl9r/XPgi4hASg+SKGPBj4NFceMVOZw q39vY9p6JeMhbhNqcJ3aK4qRMgt0iY91K6Mbll9FtUJ+/JD6KtzIZmS1yBZAoXhjvxrF Ael6K4EUiGqwtI2a7XDJyXAkS5hqCr35vMzWroSi5/KQkOXGfpp3JwUl6C8IFussyc2+ stdrjf/dqQ+vVsE8GWUfhCgZCHKocyh8MSxndlkbDH+4VbhL44W5njT6/98dGtHOjP+s Mwhbx29nIv8NJ/JYqoFhIZwDsuIJ9NIIH7XJVmT2o9sq8UIizQAzs+DD3iepRBCKJ6ou xxEw== X-Gm-Message-State: AOAM532oB6laEceqO2ycBeOajNQNxtXIPQmEF5i5vou06YeFdrtPXjHT 9xSFiyclxT8uUVux+DwLZSL7rg== X-Received: by 2002:a05:6a00:138e:b029:204:422e:a87e with SMTP id t14-20020a056a00138eb0290204422ea87emr17837504pfg.24.1616341213914; Sun, 21 Mar 2021 08:40:13 -0700 (PDT) Received: from [192.168.1.134] ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id j92sm11120505pja.29.2021.03.21.08.40.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Mar 2021 08:40:13 -0700 (PDT) Subject: Re: [PATCH 1/2] signal: don't allow sending any signals to PF_IO_WORKER threads To: "Eric W. Biederman" Cc: Linus Torvalds , io-uring , Linux Kernel Mailing List , Oleg Nesterov , Stefan Metzmacher References: <20210320153832.1033687-1-axboe@kernel.dk> <20210320153832.1033687-2-axboe@kernel.dk> <43f05d70-11a9-d59a-1eac-29adc8c53894@kernel.dk> From: Jens Axboe Message-ID: Date: Sun, 21 Mar 2021 09:40:11 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/21/21 8:54 AM, Eric W. Biederman wrote: > Jens Axboe writes: > >> On 3/20/21 3:38 PM, Eric W. Biederman wrote: >>> Linus Torvalds writes: >>> >>>> On Sat, Mar 20, 2021 at 9:19 AM Eric W. Biederman 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 >>>> -EAGAIN". >>>> >>>> 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 >>> queue. >>> >>> 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 >> thread. >> >> 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. > > I agree about signals. Especially because being able to use kill(2) > with the tid of thread is a linuxism and a backwards compatibility thing > from before we had CLONE_THREAD. > > I think for kill(2) we should just return -ESRCH. > > Thank you for providing the reasoning that is what I really saw missing > in the patches. The why. And software is difficult to maintain without > the why. Thanks Eric, I'll change that patch to -ESRCH and augment the commit message a bit. -- Jens Axboe