From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1050339853 for ; Mon, 30 Mar 2026 15:07:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.217.42 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774883261; cv=pass; b=H/8K/191iWqxQmPf0oWwHUVCOfFDw2VOIOrBzFpmyGOJf77n2U62Ts8u6JRTBAXnYDeyOm6a7ADsUF1EpRvz5dHlb2H1nBySBiw+F11IXhQLF5QZk3xwvCvv4EZp58/yIqb0/vRN0lSDheJ8wUWlFgqFiPB978e7nfofRCXTA4E= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774883261; c=relaxed/simple; bh=/x13DKtZaVDG7yiVUGXh9eKmBd78HM6nIK9Tv56z6jQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=msI4nDMCqv1UoyN52kBs8GF4LoGOksxt/Yr/T7CMnT26Jzb/afP/Zf6gTYncAmjD1oHQ1D+u7OE41K9oj5kllTNbuZV8cQ8HXGTyoDRmGXKQzzo/C5ZObNvvizOb4Uk30xi4u07tfaJ6TeNaIF7flYAComUwRKTOh2wpJJD68Uk= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UDVvAeY8; arc=pass smtp.client-ip=209.85.217.42 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) header.d=gmail.com header.i=@gmail.com header.b="UDVvAeY8" Received: by mail-vs1-f42.google.com with SMTP id ada2fe7eead31-5ffe41e8e83so2816125137.1 for ; Mon, 30 Mar 2026 08:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774883257; cv=none; d=google.com; s=arc-20240605; b=gmXrKI0rGOA9AYsZwCNUQudN9JBm1hK2jIQu2yj1Kde11Ntgdtu2m2Iw9Bh/FeuoIx o4eqVy8bDZFIoCR9WCLFPkAi8ZdfI/aq6PteL2vrvFAgSa4e7/qI9MyqiQIIUAzl95is KUfJLxSxnLcW1n14ftYwjkih0hEHIeV7hSLlmKDBrmcOJUfA6oojpY52FuC0Iy0wNGrC yXTDfFAEyIWml5QFdYw0btO40HeiiALw439Pt72fVQaK7qQ2xgS6zGjFamHA29yxHW+r foHSoZmTP3eqlsrNNrv3/XMXfccfcOroBw3lYZb2xyVKrgFvl4n2P8xI0e4zGTXos4+Y LM+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=i27yBCASimAbh8aqvQTLYNbe/ak/AL7sQPeMVmtc+JI=; fh=5SUL0Vha2qq0H2sCw2/frfDTrLbpom/2a5zpuuXj/hQ=; b=MTzPKlmXAYGktCXosXXCglLnOO/Mnc2pXzmFQBXiiW+pVbMT5nRiny1fvihdZtcQzI yQ4Uffu4eV0SYYydmS0AXxy750Y0VaQnTCN+C8DkltDjL4aWmB2/xEmcpVtq+9M0ncES twAvHbL223vnHq7sEFsS6b1j4CARCJDdx48630ihsWhPqD/53rezdUqfmWIqg9KDBAKZ kwD5LZszRJ0PSFJzVuMzPqxPOXCt4Z/VVFTWRu/hbO3WbsmOlum+f03wMagH4ICQKEiP rGNJwvH8neR7fkiFixybJaIf1s4A/V7n3H4ixMYvMcGPYopacMsjsWgPkbezaa2bg+op F4Jw==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774883257; x=1775488057; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=i27yBCASimAbh8aqvQTLYNbe/ak/AL7sQPeMVmtc+JI=; b=UDVvAeY8m5wlbQOXPTgFfY11Cx7Haf5wzVUmS9lx2Eq6W3kP+ITkzBB9ePKeOWRF71 msdtytfI1S9rJ2obJVxx1TjFFj0AJkNDgnSxBqhC1+RHEaywuaEhQPQmYJDGeRUoTc7K i2Pr07RnKRDwbY8Sk5aLQfmAKPtwMeY+90ZIq8YRRH1MkuhbEfjjJ2Kpp9okh7mInPpP CuyUPk9vskQajhxEPcHWLREXJyMf4O52s9Nnkc1mgAr94HBZu65LLXDRv6G/VNFYiCnW i13tFwiTAbVtn8NcPYwW1+NftkS64fkgc/zCH4YMAZ1kr6EjzEwb+TQP7crgO0uR+iug HLsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774883257; x=1775488057; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=i27yBCASimAbh8aqvQTLYNbe/ak/AL7sQPeMVmtc+JI=; b=DSlNvsl2vA56dDQEeqdqIAr0IAYZlNObaX6H6yyaa0h525ws987sIMtfGuQsoMO3wv 52ryFINTTjU7qOtrXy9U2LMjVrdOQRG3H5KwRdp8x7sxfMRP5b33k+2ocnmBxI0XJMj8 n4YsjA0nwkBMfoqNWr8gYLq4EgIWySKn2jgikkLIGqRarEAtIHHj19bwMDe6vKlTlq4e P5shtFwVn+iTr/1x4mgxWvfBpnnJuJgOH2MBmkExpeIZ39Un7AwsSW1ejw5v3W6txaE8 ak2GC3zpcP4wJb63drIsDLluVeK0a5d4RXh1uRdheNnILL040de/sIHmc2JJG3IDk55P D2CQ== X-Forwarded-Encrypted: i=1; AJvYcCX10EhYBI7+3z2D5d2Hhr21XXbCtmKTCf80LHUHJsGCuH922OeDXZrsrQVyl+9D+cigoKiTEwRwCBLCndU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2JZZTqJvm5ckqYPE6kbdA8RiSa+BeFV8rLQAauJPDiV+ddOjh plxLtvt6ZeAofKgAdqZjwha3GtAGR//17p0lY6+l6o5JErCz/FZWpXDZAP6FxUMJkUx6vDV9Had mKF+aNFmx/n14FeEDQxTBoVis8hlzYB0= X-Gm-Gg: ATEYQzz5MPD78F9KlPwOXpW6YVcrH7xr7W5uD0uGqGwaxAEBF4vW8Zuwhb8EOhxwpVR QDPadbwXtoGPdI9qjaCQeoBMn83T5bmW1LFPDEE1tgBxW0RXSJ4mQuh0nTE4Ts8Ufrtocn42VFV EHp2z1fh2EjoRghOWCiKiBtEYImKm0Qiic0pPNIEX5VtbwFokxKD27+6ltLc7qa2/3RoCEVOV+p DO6Bxu3caXxa1lp9ZdVOX59uNdwxEpzaB8kDX/b4bGT0Ikp5npzowbOD0uklkTeowNb7ZhbkFCq 6XNag/lTW/VZy1sqFdWHuXu+28m3GClr47J5izBmenA= X-Received: by 2002:a05:6102:84d1:b0:602:6ccd:7772 with SMTP id ada2fe7eead31-604fbdd4504mr3414117137.2.1774883257420; Mon, 30 Mar 2026 08:07:37 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260328172314.45807-1-dorjoychy111@gmail.com> <20260328172314.45807-2-dorjoychy111@gmail.com> In-Reply-To: From: Dorjoy Chowdhury Date: Mon, 30 Mar 2026 21:07:25 +0600 X-Gm-Features: AQROBzBiNZNQJDXYIA1g_QAQfKVpqrabu4vh65YgUWDTzh1Q_gvpOzHijv8ZYqQ Message-ID: Subject: Re: [PATCH v6 1/4] openat2: new OPENAT2_REGULAR flag support To: Jeff Layton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, gfs2@lists.linux.dev, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, v9fs@lists.linux.dev, linux-kselftest@vger.kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, chuck.lever@oracle.com, alex.aring@gmail.com, arnd@arndb.de, adilger@dilger.ca, mjguzik@gmail.com, smfrench@gmail.com, richard.henderson@linaro.org, mattst88@gmail.com, linmag7@gmail.com, tsbogend@alpha.franken.de, James.Bottomley@hansenpartnership.com, deller@gmx.de, davem@davemloft.net, andreas@gaisler.com, idryomov@gmail.com, amarkuze@redhat.com, slava@dubeyko.com, agruenba@redhat.com, trondmy@kernel.org, anna@kernel.org, sfrench@samba.org, pc@manguebit.org, ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com, shuah@kernel.org, miklos@szeredi.hu, hansg@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Mar 30, 2026 at 5:49=E2=80=AFPM Jeff Layton wr= ote: > > On Sat, 2026-03-28 at 23:22 +0600, Dorjoy Chowdhury wrote: > > This flag indicates the path should be opened if it's a regular file. > > This is useful to write secure programs that want to avoid being > > tricked into opening device nodes with special semantics while thinking > > they operate on regular files. This is a requested feature from the > > uapi-group[1]. > > > > A corresponding error code EFTYPE has been introduced. For example, if > > openat2 is called on path /dev/null with OPENAT2_REGULAR in the flag > > param, it will return -EFTYPE. EFTYPE is already used in BSD systems > > like FreeBSD, macOS. > > > > When used in combination with O_CREAT, either the regular file is > > created, or if the path already exists, it is opened if it's a regular > > file. Otherwise, -EFTYPE is returned. > > > > When OPENAT2_REGULAR is combined with O_DIRECTORY, -EINVAL is returned > > as it doesn't make sense to open a path that is both a directory and a > > regular file. > > > > [1]: https://uapi-group.org/kernel-features/#ability-to-only-open-regul= ar-files > > > > Signed-off-by: Dorjoy Chowdhury > > --- > > arch/alpha/include/uapi/asm/errno.h | 2 ++ > > arch/alpha/include/uapi/asm/fcntl.h | 1 + > > arch/mips/include/uapi/asm/errno.h | 2 ++ > > arch/parisc/include/uapi/asm/errno.h | 2 ++ > > arch/parisc/include/uapi/asm/fcntl.h | 1 + > > arch/sparc/include/uapi/asm/errno.h | 2 ++ > > arch/sparc/include/uapi/asm/fcntl.h | 1 + > > fs/ceph/file.c | 4 ++++ > > fs/fcntl.c | 4 ++-- > > fs/gfs2/inode.c | 6 ++++++ > > fs/namei.c | 4 ++++ > > fs/nfs/dir.c | 4 ++++ > > fs/open.c | 8 +++++--- > > fs/smb/client/dir.c | 14 +++++++++++++- > > include/linux/fcntl.h | 2 ++ > > include/uapi/asm-generic/errno.h | 2 ++ > > include/uapi/asm-generic/fcntl.h | 4 ++++ > > tools/arch/alpha/include/uapi/asm/errno.h | 2 ++ > > tools/arch/mips/include/uapi/asm/errno.h | 2 ++ > > tools/arch/parisc/include/uapi/asm/errno.h | 2 ++ > > tools/arch/sparc/include/uapi/asm/errno.h | 2 ++ > > tools/include/uapi/asm-generic/errno.h | 2 ++ > > 22 files changed, 67 insertions(+), 6 deletions(-) > > > > diff --git a/arch/alpha/include/uapi/asm/errno.h b/arch/alpha/include/u= api/asm/errno.h > > index 6791f6508632..1a99f38813c7 100644 > > --- a/arch/alpha/include/uapi/asm/errno.h > > +++ b/arch/alpha/include/uapi/asm/errno.h > > @@ -127,4 +127,6 @@ > > > > #define EHWPOISON 139 /* Memory page has hardware error */ > > > > +#define EFTYPE 140 /* Wrong file type for the intend= ed operation */ > > + > > #endif > > diff --git a/arch/alpha/include/uapi/asm/fcntl.h b/arch/alpha/include/u= api/asm/fcntl.h > > index 50bdc8e8a271..fe488bf7c18e 100644 > > --- a/arch/alpha/include/uapi/asm/fcntl.h > > +++ b/arch/alpha/include/uapi/asm/fcntl.h > > @@ -34,6 +34,7 @@ > > > > #define O_PATH 040000000 > > #define __O_TMPFILE 0100000000 > > +#define OPENAT2_REGULAR 0200000000 > > > > #define F_GETLK 7 > > #define F_SETLK 8 > > diff --git a/arch/mips/include/uapi/asm/errno.h b/arch/mips/include/uap= i/asm/errno.h > > index c01ed91b1ef4..1835a50b69ce 100644 > > --- a/arch/mips/include/uapi/asm/errno.h > > +++ b/arch/mips/include/uapi/asm/errno.h > > @@ -126,6 +126,8 @@ > > > > #define EHWPOISON 168 /* Memory page has hardware error */ > > > > +#define EFTYPE 169 /* Wrong file type for the intend= ed operation */ > > + > > #define EDQUOT 1133 /* Quota exceeded */ > > > > > > diff --git a/arch/parisc/include/uapi/asm/errno.h b/arch/parisc/include= /uapi/asm/errno.h > > index 8cbc07c1903e..93194fbb0a80 100644 > > --- a/arch/parisc/include/uapi/asm/errno.h > > +++ b/arch/parisc/include/uapi/asm/errno.h > > @@ -124,4 +124,6 @@ > > > > #define EHWPOISON 257 /* Memory page has hardware error */ > > > > +#define EFTYPE 258 /* Wrong file type for the intend= ed operation */ > > + > > #endif > > diff --git a/arch/parisc/include/uapi/asm/fcntl.h b/arch/parisc/include= /uapi/asm/fcntl.h > > index 03dee816cb13..d46812f2f0f4 100644 > > --- a/arch/parisc/include/uapi/asm/fcntl.h > > +++ b/arch/parisc/include/uapi/asm/fcntl.h > > @@ -19,6 +19,7 @@ > > > > #define O_PATH 020000000 > > #define __O_TMPFILE 040000000 > > +#define OPENAT2_REGULAR 0100000000 > > > > #define F_GETLK64 8 > > #define F_SETLK64 9 > > diff --git a/arch/sparc/include/uapi/asm/errno.h b/arch/sparc/include/u= api/asm/errno.h > > index 4a41e7835fd5..71940ec9130b 100644 > > --- a/arch/sparc/include/uapi/asm/errno.h > > +++ b/arch/sparc/include/uapi/asm/errno.h > > @@ -117,4 +117,6 @@ > > > > #define EHWPOISON 135 /* Memory page has hardware error */ > > > > +#define EFTYPE 136 /* Wrong file type for the intend= ed operation */ > > + > > #endif > > diff --git a/arch/sparc/include/uapi/asm/fcntl.h b/arch/sparc/include/u= api/asm/fcntl.h > > index 67dae75e5274..bb6e9fa94bc9 100644 > > --- a/arch/sparc/include/uapi/asm/fcntl.h > > +++ b/arch/sparc/include/uapi/asm/fcntl.h > > @@ -37,6 +37,7 @@ > > > > #define O_PATH 0x1000000 > > #define __O_TMPFILE 0x2000000 > > +#define OPENAT2_REGULAR 0x4000000 > > > > #define F_GETOWN 5 /* for sockets. */ > > #define F_SETOWN 6 /* for sockets. */ > > diff --git a/fs/ceph/file.c b/fs/ceph/file.c > > index 66bbf6d517a9..6d8d4c7765e6 100644 > > --- a/fs/ceph/file.c > > +++ b/fs/ceph/file.c > > @@ -977,6 +977,10 @@ int ceph_atomic_open(struct inode *dir, struct den= try *dentry, > > ceph_init_inode_acls(newino, &as_ctx); > > file->f_mode |=3D FMODE_CREATED; > > } > > + if ((flags & OPENAT2_REGULAR) && !d_is_reg(dentry)) { > > + err =3D -EFTYPE; > > + goto out_req; > > + } > > ^^^ > This doesn't look quite right. Here's a larger chunk of the code: > > -------------------------8<-------------------------- > if (d_in_lookup(dentry)) { > dn =3D ceph_finish_lookup(req, dentry, err); > if (IS_ERR(dn)) > err =3D PTR_ERR(dn); > } else { > /* we were given a hashed negative dentry */ > dn =3D NULL; > } > if (err) > goto out_req; > if (dn || d_really_is_negative(dentry) || d_is_symlink(dentry)) { > /* make vfs retry on splice, ENOENT, or symlink */ > doutc(cl, "finish_no_open on dn %p\n", dn); > err =3D finish_no_open(file, dn); > } else { > if (IS_ENCRYPTED(dir) && > !fscrypt_has_permitted_context(dir, d_inode(dentry)))= { > pr_warn_client(cl, > "Inconsistent encryption context (parent = %llx:%llx child %llx:%llx)\n", > ceph_vinop(dir), ceph_vinop(d_inode(dentr= y))); > goto out_req; > } > > doutc(cl, "finish_open on dn %p\n", dn); > if (req->r_op =3D=3D CEPH_MDS_OP_CREATE && req->r_reply_i= nfo.has_create_ino) { > struct inode *newino =3D d_inode(dentry); > > cache_file_layout(dir, newino); > ceph_init_inode_acls(newino, &as_ctx); > file->f_mode |=3D FMODE_CREATED; > } > err =3D finish_open(file, dentry, ceph_open); > } > -------------------------8<-------------------------- > > It looks like this won't handle it correctly if the pathwalk terminates > on a symlink (re: d_is_symlink() case). You should either set up a test > ceph cluster on your own, or reach out to the ceph community and ask > them to test this. > Thanks for reviewing. The d_is_symlink() case seems to be calling finish_no_open so shouldn't this be okay? > > err =3D finish_open(file, dentry, ceph_open); > > } > > out_req: > > diff --git a/fs/fcntl.c b/fs/fcntl.c > > index beab8080badf..240bb511557a 100644 > > --- a/fs/fcntl.c > > +++ b/fs/fcntl.c > > @@ -1169,9 +1169,9 @@ static int __init fcntl_init(void) > > * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY > > * is defined as O_NONBLOCK on some platforms and not on others. > > */ > > - BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ !=3D > > + BUILD_BUG_ON(21 - 1 /* for O_RDONLY being 0 */ !=3D > > HWEIGHT32( > > - (VALID_OPEN_FLAGS & ~(O_NONBLOCK | O_NDELAY)) | > > + (VALID_OPENAT2_FLAGS & ~(O_NONBLOCK | O_NDELAY)) = | > > __FMODE_EXEC)); > > > > fasync_cache =3D kmem_cache_create("fasync_cache", > > diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c > > index 8344040ecaf7..4604e2e8a9cc 100644 > > --- a/fs/gfs2/inode.c > > +++ b/fs/gfs2/inode.c > > @@ -738,6 +738,12 @@ static int gfs2_create_inode(struct inode *dir, st= ruct dentry *dentry, > > inode =3D gfs2_dir_search(dir, &dentry->d_name, !S_ISREG(mode) ||= excl); > > error =3D PTR_ERR(inode); > > if (!IS_ERR(inode)) { > > + if (file && (file->f_flags & OPENAT2_REGULAR) && !S_ISREG= (inode->i_mode)) { > > Isn't OPENAT2_REGULAR getting masked off in ->f_flags now? > Yes, I thought the masking off was happening after this codepath got executed. Maybe it's better anyway to pass another flags param to this function and forward the flags from the gfs2_atomic_open function and in other call sites pass 0 ? What do you think? Regards, Dorjoy