From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795987660; b=wnkMg+ka5x/+le2ypy1t6JDQO2hTlP7pCN0sWZoCeT3auUtaN0nWezkGtOAsKWtS+nXL JHIJtUsoYVDdKOwHWpznemS0ZnyRuWAQq2Gabm+cqeoaUD0KDi+GtkgggPH/5QQlP3LG2 FZZSrlnovEPRjfiefWYlior0+ZK0KeEQvzLAB6IoaV8iW3xUY4mLFyOIbTgCA/GIs8dcu f+D2jXhhrWyL+2OmYiHH7RQ2bsnQWGyOz4+nJNrTZ3YaxlBvOpSTrhV3ml5jUUcwNGMAr wvbRMMG+CLWpw+UwXQYxyzzd1hqctBZoCSa4lBkcyHhHmeGnXLRNYEPW5owqGd66heQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795987660; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=nthtQj3o/Qs07frerH95DKkqj82xjpLwKNu8DoPW3ZM=; b=B9XqWVEETvD0iTu+PU405g4WTCewXFSK16NZGN6E5u9cYMav/znKjwveyvsw3oaqh0Lt GEot8LD8hsKZC0rv61FAG2Sl64rwDTzHNFEyG6BUluJJ8jwDo6dai9AWIcPIYPAxK6qMI T9MurrbwtoKdCMOUQMALYRkTO/Dh0Ch27qrlIE1LTx4EnIXGcButmSoj2ESn03pk9jaWb m0tbjzAEZWPrAxXyU76QVw4GiCgXn0J15JWLIrvkBCsL5Yjo3Ik/ypz8MGGiJlKH46t7Z fjECR2H0fZE5n5+1NHM/wEqw6WaNbmni6lAj2ZrR4euP88iq6DwxFYv3ZWUFRu0IQ7g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=M9tthYEZ; arc=none smtp.remote-ip=209.85.221.53 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5367B606A327 for ; Sun, 29 Nov 2026 21:27:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5367B606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=M9tthYEZ Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-491971ac844so8518984f8f.2 for ; Sun, 29 Nov 2026 13:27:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795987659; x=1796592459; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=nthtQj3o/Qs07frerH95DKkqj82xjpLwKNu8DoPW3ZM=; b=M9tthYEZOMKpX15KadTAvIKD7mjn2vBUcNlgYbC3jaL6z8U8n8Boh+iP6O3vpCot2l TUAku5e9iSaYCkVS95uhSTf28/dn2FsYrodj+ih9lzAtStEFwrdmEIF13oXpfA8u43wJ K2BewyME6HvcP1BOzJwfUUwiuB74xoh/rgHqmKnwdgDbZwjQQppGmHjzxUzfxlwzX97W 5qAG8qvlk/OQ3w4RVp6QlIVgcOM1Ky65bw22pozw4Ye92HIhS8z6jrkmhJh3Zi7N86Hy K3y2k2GynjJVQYY89Y/N7vtw1boqDkMeBSi32EMX+PDIYHbhAD5rb5hJE9pHy2YoPcPy FdBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795987659; x=1796592459; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nthtQj3o/Qs07frerH95DKkqj82xjpLwKNu8DoPW3ZM=; b=RKvTcI+7wAfqwBGRLCiqoDDarsHZ4YWsbX3PwkUcxMgnFGTldrDh91GMwsJ7B9SBK9 rUkEPjPU0vZpDL0XpCFwXYVnfKe/XKaAvH/bjP5PlVrGhR6X/kid8mxSprXoKt8yOwvz j3u8vk8Tb1T5iOAMND++mdqZ4p74xmE3dtyIz9bYuDE89XMFDlFPejIw+sDzgpgw4SGM gayhkD8jp1s7TU6wNB6K+4a11BCHZSbQe7SMZziQCeXTo9m8M6epFljOX1wtbB00ygPw IWfYkdOqIc0p69y7bkl4Sywv10ba/9/z9CaqfmEX9US8hYJIzfRR22SbO1PCeUpqal6f IOOQ== X-Forwarded-Encrypted: i=1; AL+hErEihq88jOHHXMH2UgUzZIAquhIky4OXXrFHZiDDP2TDsJOYDMbXQhRsaN/T43X0Zx5HTYQ7wlCwWx0tsLI=@vger.kernel.org X-Gm-Message-State: APuU4Z9nnGHWqcUGc2d7KVBhsUnS3En+7KvXas5aCNfUqRwWB17uvXeL pTdgCNYFQ4vWywwMrY/911B/8q0+J0750yf47hNZSX7/bI89FQ55ZjBE X-Gm-Gg: AZFdTZdwgDSTXYLuxYwEAUeqS15fkXf9pnl8gCa0vQhpoenevC0NsJXgkB89lhPt3ih kcWoyIOawiL418Ofh9haipuN556LA31tWauDHK0mWTChvVvRTuoLhBEBX5tK5FM33mtVw5slxsn zNQn2Eci+zF3yQNRB0AUxFjYKzIHWm4I+v+1djdFzYRRaKMXd/ClJxpE0/OoFjDJ7/+agqhKJG+ UDb9/fvkbWOOePGOI8jTCKSd97k0D/zME9CFoO62xnZHNoJRlb5JoFwRDclo7UPXlMKie8UeQLN +evqBYE5RXBVsWx8zDUETOcsHejDmSmn1+uq5PPRFlBxZbfXIyqcn2fhIWkQIuTuoW5WFcG7cvk ClmuM/fJLOyL2rGOc4d+gNeYYkwZrCKXyYI2EvlPZwgRVeWdyqtp4CVtl+YEbFEhiFZMgmWGttG LbT5df966xBwWp5bkCHTOoy8K1gE2ejIFAvl7TU/4msJyFFWcVMNdF1hL1IKinKSYlougd6Qu/m n9HRgykKotklk/YKss5GBiDfdaxbGJH8AqN3MLMHq7RNsxQovN/T90nDxMFE2TP813uCDdkUBgY LebR9mDq7tpjC5C4ZnHjFVfXbYmMKQaQm1zFteYU+bjy64Qg1M3spKy6eAIGA5oOZdnYrFBZRYG LkBFpTBITzVvdxty2qk9ksFzIAuK9e2u9XWA= X-Received: by 2002:a05:6000:4027:b0:4be:385b:afde with SMTP id ffacd0b85a97d-4be385bb1c7mr20265886f8f.46.1795987658164; Sun, 29 Nov 2026 13:27:38 -0800 (PST) Received: from dohko.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6baa397asm61090172f8f.48.2026.11.29.13.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 13:27:36 -0800 (PST) From: David Carlier To: Christian Brauner , Shuah Khan Cc: Oleg Nesterov , Josh Triplett , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, David Carlier Subject: [RFC PATCH 0/2] pidfd: add PIDFD_GETFD_NO_SELF Date: Sun, 29 Nov 2026 21:27:30 +0000 Message-ID: <20261129212732.805592-1-devnexen@gmail.com> X-Mailer: git-send-email 2.55.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit pidfd_getfd() on a task that shares the caller's fd table duplicates one of the caller's own descriptors. This is the only case that forces a pidfd_getfd() wrapper in the Rust standard library to be unsafe [1]. Add PIDFD_GETFD_NO_SELF, which makes pidfd_getfd() fail with ELOOP when the target shares the caller's fd table: the caller, its threads, or a CLONE_FILES task that has not unshared. The check is on the fd table rather than the thread group. A tgid comparison in userspace misses CLONE_FILES, and kcmp(KCMP_FILES) depends on CONFIG_KCMP. ELOOP is open to change. It only has to differ from EINVAL so that userspace can tell an old kernel from a refused target. Suggested by Josh Triplett. Tested on vfs.all (7.4-rc4) in a VM with the added selftests. An LLM helped with the analysis and generated the selftests. [1] https://github.com/rust-lang/libs-team/issues/939 David Carlier (2): pidfd: add PIDFD_GETFD_NO_SELF to pidfd_getfd() selftests/pidfd: test PIDFD_GETFD_NO_SELF include/uapi/linux/pidfd.h | 3 + kernel/pid.c | 29 ++- tools/testing/selftests/pidfd/pidfd.h | 4 + .../selftests/pidfd/pidfd_getfd_test.c | 177 +++++++++++++++++- 4 files changed, 205 insertions(+), 8 deletions(-) base-commit: 84fb6f8a1ba91eee3ffe6aa519686fce851a0e42 -- 2.55.0