Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1095724ybm; Wed, 27 May 2020 16:19:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGV6jGWMJ6KYa0gJJ/jbgGz14dphXCKa9zTVP9zphiJ8WMwnqrBL/N6Wxqwl0ZXOVV2jZi X-Received: by 2002:a17:906:f212:: with SMTP id gt18mr602863ejb.150.1590621542949; Wed, 27 May 2020 16:19:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590621542; cv=none; d=google.com; s=arc-20160816; b=UzBdOr6LtSt7TBeYIDYD4HdMFquq/26ZSy/NFkuRtNWyJ6p8doWKVQjZtlOe315DxU eeUuiFZ/ZolVHLCDrXM/vfWdNdKuGRWowqrHMruyXjZRYeuP/PO6quyXQm7YSbsOMczu oEyCOCHRtgB3oHY8qdQWUKBYMitt+rljI80s9OBsfhZW9CWVPcySglYozVQK1o6mfMhP JbNN7xwyR4vBo8HZa27upNHoGGxubN31d8XMBSxIx+1dHY9s0+WAZbehaB+TdFLbH/46 t+w4x23v57AnPwkFPVLyrjWf5lHaJp9noriXXsB2loTgxLmXfpJNXsTpk6B1H6zn0nNz T8bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=IvIiNk5Rt43KlEYsmTRpid2GcTpKtVGMiwgSx9PQxcg=; b=GDwmxfBNma2vNKgNTIyiiv6RvU5NDBv9HK2KEBOzzFR0wpgp4wcvy3xvQYYmSBEv9K qgBusQ2zONWFz1q5GO3bhQv6EBXRBH43xPA1cilVKOY0H/yXA9gmZwMY1HfMJW+QeOF7 bOdpYasHiocC6mZFAIk/zklld359xhdfcvTcc9jvWC0ghjmWjTCmUyd2DvMF4ZZndov2 x15fnIaJV4sD4zae5kNwBcMqquHGx5xHjZMPM4NiM5mlZ9qQlUgKqoyrEXHeyuQlgB+u gt54KN/mbQCjK3rBRvFvZEenSchKqA+Ljho6tBygSGqJJbjoG3E5JArurCMLBujM+mTu 211w== ARC-Authentication-Results: i=1; mx.google.com; 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 o16si2663604ejx.200.2020.05.27.16.18.39; Wed, 27 May 2020 16:19:02 -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; 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 S1725801AbgE0XQu (ORCPT + 99 others); Wed, 27 May 2020 19:16:50 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53028 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725267AbgE0XQt (ORCPT ); Wed, 27 May 2020 19:16:49 -0400 Received: from ip5f5af183.dynamic.kabel-deutschland.de ([95.90.241.131] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1je5Hy-0005uN-T4; Wed, 27 May 2020 23:16:47 +0000 Date: Thu, 28 May 2020 01:16:46 +0200 From: Christian Brauner To: Kees Cook Cc: linux-kernel@vger.kernel.org, Andy Lutomirski , Tycho Andersen , Matt Denton , Sargun Dhillon , Jann Horn , Chris Palmer , Aleksa Sarai , Robert Sesek , Jeffrey Vander Stoep , Linux Containers Subject: Re: [PATCH 1/2] seccomp: notify user trap about unused filter Message-ID: <20200527231646.4v743erjpzh6qe5f@wittgenstein> References: <20200527111902.163213-1-christian.brauner@ubuntu.com> <202005271408.58F806514@keescook> <20200527220532.jplypougn3qzwrms@wittgenstein> <202005271537.75548B6@keescook> <20200527224501.jddwcmvtvjtjsmsx@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200527224501.jddwcmvtvjtjsmsx@wittgenstein> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 28, 2020 at 12:45:02AM +0200, Christian Brauner wrote: > On Wed, May 27, 2020 at 03:37:58PM -0700, Kees Cook wrote: > > On Thu, May 28, 2020 at 12:05:32AM +0200, Christian Brauner wrote: > > > The main question also is, is there precedence where the kernel just > > > closes the file descriptor for userspace behind it's back? I'm not sure > > > I've heard of this before. That's not how that works afaict; it's also > > > not how we do pidfds. We don't just close the fd when the task > > > associated with it goes away, we notify and then userspace can close. > > > > But there's a mapping between pidfd and task struct that is separate > > from task struct itself, yes? I.e. keeping a pidfd open doesn't pin > > struct task in memory forever, right? > > No, but that's an implementation detail and we discussed that. It pins > struct pid instead of task_struct. Once the process is fully gone you > just get ESRCH. > For example, fds to /proc/// fds aren't just closed once the > task has gone away, userspace will just get ESRCH when it tries to open > files under there but the fd remains valid until close() is called. > > In addition, of all the anon inode fds, none of them have the "close the > file behind userspace back" behavior: io_uring, signalfd, timerfd, btf, > perf_event, bpf-prog, bpf-link, bpf-map, pidfd, userfaultfd, fanotify, > inotify, eventpoll, fscontext, eventfd. These are just core kernel ones. > I'm pretty sure that it'd be very odd behavior if we did that. I'd > rather just notify userspace and leave the close to them. But maybe I'm > missing something. I'm also starting to think this isn't even possible or currently doable safely. The fdtable in the kernel would end up with a dangling pointer, I would think. Unless you backtrack all fds that still have a reference into the fdtable and refer to that file and close them all in the kernel which I don't think is possible and also sounds very dodgy. This also really seems like we would be breaking a major contract, namely that fds stay valid until userspace calls close, execve(), or exits. Christian