Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp531018rdb; Thu, 30 Nov 2023 11:00:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFppGDF762BJm07Im4bJftlP6yXzlsujgfVx22+eLAGMgdGrNk4jJ7UhdFwmXslibcaqAc7 X-Received: by 2002:a05:6830:3a9a:b0:6cd:9b5:f07f with SMTP id dj26-20020a0568303a9a00b006cd09b5f07fmr219029otb.8.1701370847784; Thu, 30 Nov 2023 11:00:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701370847; cv=none; d=google.com; s=arc-20160816; b=dDXsgVSnoE1PljtNnWsnnsYmTuPOZ3eVVz0NtbREuxNGAUTMfT39CFSkdm4BWX0vak mUE1r6aCPtSJ+Q8hF74E38vq+Mr9mZ45rYnEz3TGMsatucnCbO2sMIMdcCMiA3DaTIAB mNBR9JgPlB1d2rZvWxl4Q49IJ/tOwDZdCiBtHyFufbrDRa3FIpRmIiwPOTi5oufrMmo8 LBpHeqJkL6Pz+aH6ckzpnU148+h8oFjq+J+fi0cQptHZyA0Dw3mZMlrKw2xts0OyN4e1 NqYe5xRO3g9l7GVDS453/xiqfnfGq+nj+7pnZIyDC9fGWJlJD58sMM+zQUdoP+GWDalv qCFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=mxiEe53dnseGE9vRXNNbZdb/CLpYjsc2hDCxednDuvw=; fh=l6KCumAio3Asf7JSuXaVAnt3OZ2ydnbMb3TjsVPNwcA=; b=Fk+zVcWgm+AjvqTe7oJaofpHGo2wC9qVj2RzwC8AN07Ya4ZOwINRKEZ20jIed9ZT6l LCNyUb5fMrtQcRKAFYZ1FTDCXzva6ZIP9lsPVMa7WDUnuqh7GvS7280dTxlbkTC2aVa4 bZXUqIpCc5CLD0PzYclMgQ9XxFRgFO7EdpWUdIbBN0rwm7tNOYY7eHe6HZpSkV3J2nKQ T8w2IO1Ux+CyZVNpcbwIKM6MGTu1xUIA5dLWFqMgtvrLON3tLWIkDxRAyePDxiiyMCMn sp45aL61JGAWZudWLqPc/LZ0wjRliI6dr8wXHWklMCUuiDXYC7gxi8ApIEIZoosyJs82 UEvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=Erxk7VjU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id x24-20020a4a6218000000b0058a0d3fb332si630266ooc.66.2023.11.30.11.00.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 11:00:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=Erxk7VjU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DD072807558B; Thu, 30 Nov 2023 11:00:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231199AbjK3TAA (ORCPT + 99 others); Thu, 30 Nov 2023 14:00:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbjK3S77 (ORCPT ); Thu, 30 Nov 2023 13:59:59 -0500 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A996ED48; Thu, 30 Nov 2023 11:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1701370803; bh=BObGTsR9eRsXFgPPmYkraabswwf/jPu4KRxicRxkChU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Erxk7VjUY2Kbt018z3ZmFmTM9vr57N350YYaSOx5StFL+loZ7obXN/CNymA3OUi8T 388Ir8uxLj1GE86rTpqPOEzLpI0x7yuMoEnxKS4yAH7GwMhQCA0mY2ebt+Sz7vkvDr VbMs9YowhH0VKhDjK86puxnrTcLKlkuwtPmoJu+e7LvUmHqeJ0lJAaSP1prXJS9weE TOqzp2Cy7Kxk+mrdbkVgau10xt7CGFw9N3UoPQR7wISQUhbYS9SDr+X6mCxcB/A3+/ 9mD9SP+BbbEAk72WUbla8U+hnZvb3DOOpbYtO7236++YFJiOvYqZxwbqx1U2OQHkIM ftg5W9IHkxg9w== Received: from [172.16.0.134] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4Sh59H21LLz1f02; Thu, 30 Nov 2023 14:00:03 -0500 (EST) Message-ID: Date: Thu, 30 Nov 2023 14:00:01 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 1/3] pidfd: allow pidfd_open() on non-thread-group leaders Content-Language: en-US To: Tycho Andersen , Florian Weimer Cc: Christian Brauner , Oleg Nesterov , "Eric W . Biederman" , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Tycho Andersen References: <20231130163946.277502-1-tycho@tycho.pizza> <874jh3t7e9.fsf@oldenburg.str.redhat.com> From: Mathieu Desnoyers In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Thu, 30 Nov 2023 11:00:17 -0800 (PST) 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. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com