Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8210667imu; Tue, 4 Dec 2018 04:57:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/WmJRzFV3MEnO4MDrD4fkj5qjmSUHo18FFY4QgbUmOPhGX7Uz1HgFzuOYm8BGy72fKexF3E X-Received: by 2002:a17:902:280b:: with SMTP id e11mr20065255plb.269.1543928247352; Tue, 04 Dec 2018 04:57:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543928247; cv=none; d=google.com; s=arc-20160816; b=rAEdDKGfJ1oC+H8k+FY7F91VCmNRgmqBMV82WrfpC7bFrAtjUUZpBdBV55CPXJhNuR YDrLkXF1hj5KzkdVzpyo6HhEza2qOTuetPVnVYvPcqYj/tPdP4poWohXQ0rISQEC7kyb lOl2a2qtm0UIQrkxFN8JA36mrvUh6ssqDaaPgxvjF6rI1suCL4SvSx7SJcolKkNldhq9 8tqnt0/SFPCUk1A0FTQq7aV6QtE+PhhS/OccY44F7yeN+1ORhxLQxCazs9KQU1vAxVfN TOxLT0+dOhTT61bcVWIDglUYfAIfd6smEB3DMQYL/Yth5sQNLogz6F41q6HU+lIJyByX 1fyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=J1nsZTj9HO8ebFA0m5DOUYOEtwH+SQzq633HVckAz7o=; b=qEHAHeU9DMNyINGIc14WW18hvypW3bFg+yWCcbgMioK7/R+ly1Dg8pskKdsjD/w/py saF/C7u4KZS47wTw0aUBHevm2d8ZPB7Ith2xADRad8EmHr/cSfMcUTA6v5UGFqpyCkgd pkNw9SfIfNNv/ZqmbNeryoyUkaH3HnUV+Aq9L7NiIge76qv4qIeGauXf4Kiyb6fylrqa UEvuTdi2ZU7xgVEdz7MLzsHqbjGkI1Rfny0HYl/fCdGM0rYVaQkkkAbSLX2LqkHPMLEJ GmZt2a9QM9GJoOpyNOXIgqN7oSo0xN1OzGcbfYqCi4q9mLoguGZ92qK+Oy7YT091e4DG dv4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si16480936pge.48.2018.12.04.04.57.11; Tue, 04 Dec 2018 04:57:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726351AbeLDMzT (ORCPT + 99 others); Tue, 4 Dec 2018 07:55:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33020 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725767AbeLDMzT (ORCPT ); Tue, 4 Dec 2018 07:55:19 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 126A33002887; Tue, 4 Dec 2018 12:55:18 +0000 (UTC) Received: from oldenburg2.str.redhat.com (dhcp-192-219.str.redhat.com [10.33.192.219]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F170D5C23E; Tue, 4 Dec 2018 12:55:11 +0000 (UTC) From: Florian Weimer To: Christian Brauner Cc: ebiederm@xmission.com, linux-kernel@vger.kernel.org, serge@hallyn.com, jannh@google.com, luto@kernel.org, akpm@linux-foundation.org, oleg@redhat.com, cyphar@cyphar.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, dancol@google.com, timmurray@google.com, linux-man@vger.kernel.org, Kees Cook Subject: Re: [PATCH v2] signal: add procfd_signal() syscall References: <20181120105124.14733-1-christian@brauner.io> <87in0g5aqo.fsf@oldenburg.str.redhat.com> <746B7C49-CC7B-4040-A7EF-82491796D360@brauner.io> <20181202100304.labt63mzrlr5utdl@brauner.io> <8736rebl9s.fsf@oldenburg.str.redhat.com> <20181203180224.fkvw4kajtbvru2ku@brauner.io> Date: Tue, 04 Dec 2018 13:55:10 +0100 In-Reply-To: <20181203180224.fkvw4kajtbvru2ku@brauner.io> (Christian Brauner's message of "Mon, 3 Dec 2018 19:02:29 +0100") Message-ID: <874lbtjvtd.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 04 Dec 2018 12:55:18 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Christian Brauner: > On Mon, Dec 03, 2018 at 05:57:51PM +0100, Florian Weimer wrote: >> * Christian Brauner: >> >> > Ok, I finally have access to source code again. Scratch what I said above! >> > I looked at the code and tested it. If the process has exited but not >> > yet waited upon aka is a zombie procfd_send_signal() will return 0. This >> > is identical to kill(2) behavior. It should've been sort-of obvious >> > since when a process is in zombie state /proc/ will still be around >> > which means that struct pid must still be around. >> >> Should we make this state more accessible, by providing a different >> error code? > > No, I don't think we want that. Imho, It's not really helpful. Signals > are still delivered to zombies. If zombie state were to always mean that > no-one is going to wait on this thread anymore then it would make sense > to me. But given that zombie can also mean that someone put a > sleep(1000) right before their wait() call in the parent it seems odd to > report back that it is a zombie. It allows for error checking that the recipient of a signal is still running. It's obviously not reliable, but I think it could be helpful in the context of closely cooperating processes. >> Will the system call ever return ESRCH, given that you have a handle for >> the process? > > Yes, whenever you signal a process that has already been waited upon: > - get procfd handle referring to > - exits and is waited upon > - procfd_send_signal(procfd, ...) returns -1 with errno == ESRCH I see, thanks. >> Do you want to land all this in one kernel release? I wonder how >> applications are supposed to discover kernel support if functionality is >> split across several kernel releases. If you get EINVAL or EBADF, it >> may not be obvious what is going on. > > Sigh, I get that but I really don't want to have to land this in one big > chunk. I want this syscall to go in in a as soon as we can to fulfill > the most basic need: having a way that guarantees us that we signal the > process that we intended to signal. > > The thread case is easy to implement on top of it. But I suspect we will > quibble about the exact semantics for a long time. Even now we have been > on multiple - justified - detrous. That's all pefectly fine and > expected. But if we have the basic functionality in we have time to do > all of that. We might even land it in the same kernel release still. I > really don't want to come of as tea-party-kernel-conservative here but I > have time-and-time again seen that making something fancy and cover ever > interesting feature in one patchset takes a very very long time. > > If you care about userspace being able to detect that case I can return > EOPNOTSUPP when a tid descriptor is passed. I suppose that's fine. Or alternatively, when thread group support is added, introduce a flag that applications have to use to enable it, so that they can probe for support by checking support for the flag. I wouldn't be opposed to a new system call like this either: int procfd_open (pid_t thread_group, pid_t thread_id, unsigned flags); But I think this is frowned upon on the kernel side. >> What happens if you use the new interface with an O_PATH descriptor? > > You get EINVAL. When an O_PATH file descriptor is created the kernel > will set file->f_op = &empty_fops at which point the check I added > if (!proc_is_tgid_procfd(f.file)) > goto err; > will fail. Imho this is correct behavior since technically signaling a > struct pid is the equivalent of writing to a file and hence doesn't > purely operate on the file descriptor level. Yes, that's quite reasonable. Thanks. Florian