Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp542949rdb; Thu, 30 Nov 2023 11:17:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNS6orAX7/x/JwosjjuNqvQzf8soT1wiu8pAWR1EFxrMy3MZawCZe5XsD2nKn7UNHLCRwQ X-Received: by 2002:a05:6808:2115:b0:3b2:eade:5e81 with SMTP id r21-20020a056808211500b003b2eade5e81mr646427oiw.34.1701371859745; Thu, 30 Nov 2023 11:17:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701371859; cv=none; d=google.com; s=arc-20160816; b=KGfuGRxDZofAdCXIhoNvPuuyOIX0shJeYx4CGs5/d0Hr/gQztrid50NWvy+jJlslAh ppVtrwDgo1GoI8mOCKN0zuKjiaLkLdGjApLe8y5NVoZdeoxQC2EjgtVijmghucWqq8Ax Sp5OjIuMIM/cN9QLhsLmpjEiQjdzInQuUwzbQ3vMZZGPyjCZ3ggoRkSGV2ggmina2YwB pLyilV9ZqGF+8DsgNNlVX7Wb/qUpBmN5SnKfhu2bXTUWl4veGwGmFXnYjEBYlxXAhkdK sMVgawFGQtlcCV1JqoVaYipvy+enPFsimQe5GuchzfJUijNeONooN/04i8tdz17CRYyW ax9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=iQZWO0/diNEJkkg7lAgOL9yfv4aOzoXSzlS73uZBPds=; fh=fU9r/pRKXZsW7ZzvGQk/x4gDFoHJGsXrLHnaZekz0xw=; b=JCN/FPWHXM9NLGcLkkfBLzxJPXNcrVFcST+2gPKK3zZY0i73V0TIJO98TmB4qllS6n szyPjOY1xFaCLZX4fcWqLm1WlKYQZA6igXDaD8TVJUMNOsQ4561v2V6G29LreHA4Cxxe AG2bwTNOzF33Q7xOD4NRuUVpvupUBcAZi0TusvpXkvLceC8OIW4rfN0XM4EcRm+tmtzP OyZxiuo93P5ct38vvv8pRgznKHO2D/XZRvczbPqpYHjpdehPEvxtG5Vu0HK21iy7DD2P XfJbNRJEj2iFUNyJ17qFG+4FCVHYrFnS4SVrzuRsHJNF/xsEkuUpfmLpPOLudVHhvueh zZGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm3 header.b=XkIPJIeq; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=TPFatEdJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id be7-20020a656e47000000b005c215b317e9si1980494pgb.478.2023.11.30.11.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 11:17:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm3 header.b=XkIPJIeq; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=TPFatEdJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 781E1826E3AC; Thu, 30 Nov 2023 11:17:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235230AbjK3TRU (ORCPT + 99 others); Thu, 30 Nov 2023 14:17:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232657AbjK3TRT (ORCPT ); Thu, 30 Nov 2023 14:17:19 -0500 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18E711704; Thu, 30 Nov 2023 11:17:25 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B50C65C00DB; Thu, 30 Nov 2023 14:17:22 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 30 Nov 2023 14:17:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1701371842; x=1701458242; bh=iQ ZWO0/diNEJkkg7lAgOL9yfv4aOzoXSzlS73uZBPds=; b=XkIPJIeqbBdVpFJqgr O5fippdUxsE4FcOTUGIBEiNqIdyZMnHSp4Bla1GEtxVuoLANGMjOiIu4jNuRDANH uVv8siM8MYxbiSnOfGAIj5o2LUcs/h2ZLsaI8ueHJQT/TDj/HwPSi8JmfygyQgjq tBUdW0pg5qh6c3cYPA15LMll+2pSLFTE6l2zfu6ppwnD4nLDG8KWbaiLNVa/rL/6 tVx33Ld9rGKLAN8hJgHuGM0zEj1bLRg4saDlt3XtAC29DBPTzn/IwzeFV/vKS2bn pJXFbtWgaY4Nt7RFMO22LJ5y3hqKIYn9Iejw5MbGpLufDaAqNleDhXbW8CGHA1bs 2Sdg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1701371842; x=1701458242; bh=iQZWO0/diNEJk kg7lAgOL9yfv4aOzoXSzlS73uZBPds=; b=TPFatEdJK8CIsFYFX91uL8rjEHKnH mUoOA4CvktpHgmndqfGm4/tsDRGIlZ9bZb0On6SJNIiuTvDLi1vbAs+2YrLnzmd7 EdyOgxPJIMoVmsfUr4/P/5o2hGB9cTLmcl46HgEKjUIvkjccX8oRLzvMBOOGblMx MHz5GeZR0hUsMIz0N3ndsXGgZLIFcXsDZ0d3C8iymCqSyAk3ar8q6WOd3N2nQh2x ysMFjRbg+sa9oUbYJmS8siRzg4wDGTj3FtPF/TS+DMuBRUryFQSOhb6wDBYN8zNN tT/ufTjrZMeaoaJ8QQ/b5j5r/zR7e6kKCuSYH5sO+osj6UGIFp6bNEV1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeijedguddvvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefvhigt hhhoucetnhguvghrshgvnhcuoehthigthhhosehthigthhhordhpihiiiigrqeenucggtf frrghtthgvrhhnpeeutedttefgjeefffehffffkeejueevieefudelgeejuddtfeffteek lefhleelteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehthigthhhosehthigthhhordhpihiiiigr X-ME-Proxy: Feedback-ID: i21f147d5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Nov 2023 14:17:20 -0500 (EST) Date: Thu, 30 Nov 2023 12:17:19 -0700 From: Tycho Andersen To: Mathieu Desnoyers Cc: Florian Weimer , Christian Brauner , Oleg Nesterov , "Eric W . Biederman" , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Tycho Andersen , Kees Cook Subject: Re: [RFC 1/3] pidfd: allow pidfd_open() on non-thread-group leaders Message-ID: References: <20231130163946.277502-1-tycho@tycho.pizza> <874jh3t7e9.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLACK autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 30 Nov 2023 11:17:37 -0800 (PST) On Thu, Nov 30, 2023 at 02:00:01PM -0500, Mathieu Desnoyers wrote: > On 2023-11-30 13:54, Tycho Andersen wrote: > > On Thu, Nov 30, 2023 at 07:37:02PM +0100, Florian Weimer wrote: > > > * Tycho Andersen: > > > > > > > From: Tycho Andersen > > > > > > > > We are using the pidfd family of syscalls with the seccomp userspace > > > > notifier. When some thread triggers a seccomp notification, we want to do > > > > some things to its context (munge fd tables via pidfd_getfd(), maybe write > > > > to its memory, etc.). However, threads created with ~CLONE_FILES or > > > > ~CLONE_VM mean that we can't use the pidfd family of syscalls for this > > > > purpose, since their fd table or mm are distinct from the thread group > > > > leader's. In this patch, we relax this restriction for pidfd_open(). > > > > > > Does this mean that pidfd_getfd cannot currently be used to get > > > descriptors for a TID if that TID doesn't happen to share its descriptor > > > set with the thread group leader? > > > > Correct, that's what I'm trying to solve. > > > > > I'd like to offer a userspace API which allows safe stashing of > > > unreachable file descriptors on a service thread. > > > > By "safe" here do you mean not accessible via pidfd_getfd()? > > For the LTTng-UST use-case, we need to be able to create and > use a file descriptor from an agent thread injected within the target > process in a way that is safe against patterns where the application > blindly close all file descriptors (for-loop doing close(2), > closefrom(2) or closeall(2)). > > The main issue here is that even though we could handle errors > (-1, errno=EBADF) in the sendmsg/recvmsg calls, re-use of a file > descriptor by the application can lead to data corruption, which > is certainly an unwanted consequence. > > AFAIU glibc has similar requirements with respect to io_uring > file descriptors. I see, thanks. And this introduces another problem: what if one of these things is a memfd, then that memory needs to be invisible to the process as well presumably? This "invisible to the process" mapping would solve another longstanding problem with seccomp: handlers could copy syscall arguments to this safe memory area and then _CONTINUE things safely... Tycho