From nobody Thu Apr 16 21:03:30 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 175513AE6F0 for ; Wed, 25 Feb 2026 16:18:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772036311; cv=none; b=AX42nicZ2hhy60+ajsIMJPQ2PhbrDJfUDqa6xD6YEr59Bd21hYQxn9ySuWc1xkIt9FrEzRh4PzL7U7krJRY3w/W9KrTmxLDq7/h/8lFeFAEykNQ9l9DQ+p5W83TOyOCV/aIAZUB7FGhNgwerzni7XuJ0TaIufH7EP4blYNXZ4NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772036311; c=relaxed/simple; bh=nZAbTNEYjbT7OyrVLysjIFwV3NC0j39fba+L6I4uabo=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=kJpQ2zscBKtxgItmNditmL+UxaUKAJzP47IUuUtDx6lW0XRRagAYVYnx2iVSO/UWxETnKV5DnmfuuCWJiIKg2/WmzWS2/OQmSWqVhi6XES4kglenuN6wsEr0/DHdNn5034x+mIlT4OBz/X5t4ANacBeedbgMs+ajRBqN82cNwQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OQ+o3fhQ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OQ+o3fhQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772036303; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=OVTT8pkOzSfNgPP5tB9MOHL/Pqx0mWw/QfLmkUlYmig=; b=OQ+o3fhQ5yaQtbuwLmyCDW9RzkR/Ll5smViNrXxUbMwZuyKwbm9kAAo+VWCljgEO7jwb5/ AlmhX1krizKcoYGvZifYGjrrQa6u8F6VEc9MnMvAMlDc0YogdW0Czjwm2kPJ9768pgLK5a iGtAZQrty9qhCO0fYM7SGvKBvlyrVBs= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-497-llfN0lq5MRWcxIwN0fvSNw-1; Wed, 25 Feb 2026 11:18:13 -0500 X-MC-Unique: llfN0lq5MRWcxIwN0fvSNw-1 X-Mimecast-MFC-AGG-ID: llfN0lq5MRWcxIwN0fvSNw_1772036292 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3D81C18002C3; Wed, 25 Feb 2026 16:18:12 +0000 (UTC) Received: from fedora (unknown [10.44.32.38]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id E19421800361; Wed, 25 Feb 2026 16:18:10 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 25 Feb 2026 17:18:11 +0100 (CET) Date: Wed, 25 Feb 2026 17:18:09 +0100 From: Oleg Nesterov To: Christian Brauner Cc: David Laight , linux-kernel@vger.kernel.org Subject: [PATCH] pidfd_prepare: don't pass O_RDWR to pidfs_alloc_file() Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" pidfs_alloc_file() does "flags |=3D O_RDWR" unconditionally. In fact pidfd files (and some users of anon_inode_getfile_fmode) do not need O_RDWR/FMODE_WRITE, add a comment to pidfs_alloc_file(). I guess this is an accidental legacy from 628ff7c1d8d8 ("anonfd: Allow maki= ng anon files read-only") which added O_RDWR to every anon_inode_getf*() call, then it was copied into the initial implementation of sys_pidfd_open(). Signed-off-by: Oleg Nesterov --- fs/pidfs.c | 2 +- kernel/fork.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/pidfs.c b/fs/pidfs.c index 318253344b5c..0e0176f5574f 100644 --- a/fs/pidfs.c +++ b/fs/pidfs.c @@ -1106,7 +1106,7 @@ struct file *pidfs_alloc_file(struct pid *pid, unsign= ed int flags) VFS_WARN_ON_ONCE(!pid->attr); =20 flags &=3D ~PIDFD_STALE; - flags |=3D O_RDWR; + flags |=3D O_RDWR; /* currently this is not necessary */ pidfd_file =3D dentry_open(&path, flags, current_cred()); /* Raise PIDFD_THREAD explicitly as do_dentry_open() strips it. */ if (!IS_ERR(pidfd_file)) diff --git a/kernel/fork.c b/kernel/fork.c index e832da9d15a4..80171158b0cd 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1895,7 +1895,7 @@ int pidfd_prepare(struct pid *pid, unsigned int flags= , struct file **ret_file) if (pidfd < 0) return pidfd; =20 - pidfs_file =3D pidfs_alloc_file(pid, flags | O_RDWR); + pidfs_file =3D pidfs_alloc_file(pid, flags); if (IS_ERR(pidfs_file)) return PTR_ERR(pidfs_file); =20 --=20 2.52.0