openat2: new OPENAT2_REGULAR flag support
Subsystems (15)
v4 cover openat2: new OPENAT2_REGULAR flag support
Note that in v4, for now, I have returned -EINVAL from the atomic_open codepaths. I do want to make this new flag properly supported and proper api behavior, but last time I could not quite understand what should be done for the atomic_open codepaths. So to have a more concrete discussion, I have included the -EINVAL changes.
Changes in v4:
- changed O_REGULAR to OPENAT2_REGULAR
- OPENAT2_REGULAR does not affect O_PATH
- OPENAT2_REGULAR with O_DIRECTORY will open path for both directory or regular file
- atomic_open codepaths updated to return -EINVAL when OPENAT2_REGULAR is set
- commit message includes the uapi-group URL
- v3 is at: https://lore.kernel.org/linux-fsdevel/[email protected]/T/
Changes in v3:
- included motivation about O_REGULAR flag in commit message e.g., programs not wanting to be tricked into opening device nodes
- fixed commit message wrongly referencing ENOTREGULAR instead of ENOTREG
- fixed the O_REGULAR flag in arch/parisc/include/uapi/asm/fcntl.h from 060000000 to 0100000000
- added 2 commits converting arch/{mips,sparc}/include/uapi/asm/fcntl.h O_* macros from hex to octal
- v2 is at: https://lore.kernel.org/linux-fsdevel/[email protected]/T/
Changes in v2:
- rename ENOTREGULAR to ENOTREG
- define ENOTREG in uapi/asm-generic/errno.h (instead of errno-base.h) and in arch/*/include/uapi/asm/errno.h files
- override O_REGULAR in arch/{alpha,sparc,parisc}/include/uapi/asm/fcntl.h due to clash with include/uapi/asm-generic/fcntl.h
- I have kept the kselftest but now that O_REGULAR and ENOTREG can have different value on different architectures I am not sure if it's right
- v1 is at: https://lore.kernel.org/linux-fsdevel/[email protected]/T/
Hi,
I came upon this "Ability to only open regular files" uapi feature suggestion from https://uapi-group.org/kernel-features/#ability-to-only-open-regular-files
and thought it would be something I could do as a first patch and get to know the kernel code a bit better.
I am not quite sure if the semantics that I baked into the code for this O_REGULAR flag's behavior when combined with other flags like O_CREAT look good and if there are other places that need the checks. I can fixup my patch according to suggestions for improvement. I did some happy path testing and the O_REGULAR flag seems to work as intended.
Thanks.
Regards,
Dorjoy
Dorjoy Chowdhury (4):
openat2: new OPENAT2_REGULAR flag support kselftest/openat2: test for OPENAT2_REGULAR flag sparc/fcntl.h: convert O_* flag macros from hex to octal mips/fcntl.h: convert O_* flag macros from hex to octal
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/mips/include/uapi/asm/fcntl.h | 22 ++++----- 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 | 35 +++++++------- fs/9p/vfs_inode.c | 3 ++ fs/9p/vfs_inode_dotl.c | 3 ++ fs/ceph/file.c | 3 ++ fs/fuse/dir.c | 3 ++ fs/gfs2/inode.c | 3 ++ fs/namei.c | 9 +++- fs/nfs/dir.c | 3 ++ fs/nfs/file.c | 3 ++ fs/open.c | 2 +- fs/smb/client/dir.c | 3 ++ fs/vboxsf/dir.c | 3 ++ 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 + .../testing/selftests/openat2/openat2_test.c | 46 ++++++++++++++++++- 28 files changed, 138 insertions(+), 31 deletions(-)
Signature · 1 line
2.53.0
PATCH v4 1/4 openat2: new OPENAT2_REGULAR flag support
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 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.
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, the path will be opened if the path is either a regular file or a directory.
[1]: https://uapi-group.org/kernel-features/#ability-to-only-open-regular-files
--- 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/9p/vfs_inode.c | 3 +++ fs/9p/vfs_inode_dotl.c | 3 +++ fs/ceph/file.c | 3 +++ fs/fuse/dir.c | 3 +++ fs/gfs2/inode.c | 3 +++ fs/namei.c | 9 ++++++++- fs/nfs/dir.c | 3 +++ fs/nfs/file.c | 3 +++ fs/open.c | 2 +- fs/smb/client/dir.c | 3 +++ fs/vboxsf/dir.c | 3 +++ 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 ++ 26 files changed, 65 insertions(+), 2 deletions(-)
arch/alpha/include/uapi/asm/errno.h +2 -0
@@ -127,4 +127,6 @@#define EHWPOISON 139/* Memory page has hardware error */ +#define EFTYPE 140/* Wrong file type for the intended operation */ +#endif
arch/alpha/include/uapi/asm/fcntl.h +1 -0
@@ -34,6 +34,7 @@#define O_PATH 040000000#define __O_TMPFILE 0100000000 +#define OPENAT2_REGULAR 0200000000#define F_GETLK 7#define F_SETLK 8
arch/mips/include/uapi/asm/errno.h +2 -0
@@ -126,6 +126,8 @@#define EHWPOISON 168/* Memory page has hardware error */ +#define EFTYPE 169/* Wrong file type for the intended operation */ +#define EDQUOT 1133/* Quota exceeded */
arch/parisc/include/uapi/asm/errno.h +2 -0
@@ -124,4 +124,6 @@#define EHWPOISON 257/* Memory page has hardware error */ +#define EFTYPE 258/* Wrong file type for the intended operation */ +#endif
arch/parisc/include/uapi/asm/fcntl.h +1 -0
@@ -19,6 +19,7 @@#define O_PATH 020000000#define __O_TMPFILE 040000000 +#define OPENAT2_REGULAR 0100000000#define F_GETLK64 8#define F_SETLK64 9
arch/sparc/include/uapi/asm/errno.h +2 -0
@@ -117,4 +117,6 @@#define EHWPOISON 135/* Memory page has hardware error */ +#define EFTYPE 136/* Wrong file type for the intended operation */ +#endif
arch/sparc/include/uapi/asm/fcntl.h +1 -0
@@ -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. */
fs/9p/vfs_inode.c +3 -0
@@ -771,6 +771,9 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,struct inode *inode;int p9_omode; +if (flags &OPENAT2_REGULAR ) +return -EINVAL ; +if (d_in_lookup (dentry)) {struct dentry *res =v9fs_vfs_lookup (dir, dentry,0 );if (res ||d_really_is_positive (dentry))
fs/9p/vfs_inode_dotl.c +3 -0
@@ -239,6 +239,9 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,struct v9fs_session_info *v9ses;struct posix_acl *pacl =NULL , *dacl =NULL ; +if (flags &OPENAT2_REGULAR ) +return -EINVAL ; +if (d_in_lookup (dentry)) {struct dentry *res =v9fs_vfs_lookup (dir, dentry,0 );if (res ||d_really_is_positive (dentry))
fs/ceph/file.c +3 -0
@@ -794,6 +794,9 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,if (dentry->d_name.len >NAME_MAX )return -ENAMETOOLONG ; +if (flags &OPENAT2_REGULAR ) +return -EINVAL ; + err =ceph_wait_on_conflict_unlink (dentry);if (err)return err;
fs/fuse/dir.c +3 -0
@@ -936,6 +936,9 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,if (fuse_is_bad (dir))return -EIO ; +if (flags &OPENAT2_REGULAR ) +return -EINVAL ; +if (d_in_lookup (entry)) {struct dentry *res =fuse_lookup (dir, entry,0 );if (res ||d_really_is_positive (entry))
fs/gfs2/inode.c +3 -0
@@ -1385,6 +1385,9 @@ static int gfs2_atomic_open(struct inode *dir, struct dentry *dentry, {bool excl = !!(flags &O_EXCL ); +if (flags &OPENAT2_REGULAR ) +return -EINVAL ; +if (d_in_lookup (dentry)) {struct dentry *d =__gfs2_lookup (dir, dentry, file);if (file->f_mode &FMODE_OPENED ) {
fs/namei.c +8 -1
@@ -4614,8 +4614,15 @@ static int do_open(struct nameidata *nd,if (unlikely (error))return error; } -if ((nd->flags &LOOKUP_DIRECTORY ) && !d_can_lookup (nd->path.dentry)) + +if ((open_flag &OPENAT2_REGULAR ) && (nd->flags &LOOKUP_DIRECTORY )) { +if (!d_is_reg (nd->path.dentry) && !d_can_lookup (nd->path.dentry)) +return -EFTYPE ; + }else if ((open_flag &OPENAT2_REGULAR ) && !d_is_reg (nd->path.dentry)) { +return -EFTYPE ; + }else if ((nd->flags &LOOKUP_DIRECTORY ) && !d_can_lookup (nd->path.dentry)) {return -ENOTDIR ; + } do_truncate = false; acc_mode = op->acc_mode;
fs/nfs/dir.c +3 -0
@@ -2315,6 +2315,9 @@ int nfs_atomic_open_v23(struct inode *dir, struct dentry *dentry,if (dentry->d_name.len >NFS_SERVER (dir)->namelen)return -ENAMETOOLONG ; +if (open_flags &OPENAT2_REGULAR ) +return -EINVAL ; +if (open_flags &O_CREAT ) { error =nfs_do_create (dir, dentry, mode, open_flags);if (!error) {
fs/nfs/file.c +3 -0
@@ -52,6 +52,9 @@ int nfs_check_flags(int flags)if ((flags & (O_APPEND |O_DIRECT )) == (O_APPEND |O_DIRECT ))return -EINVAL ; +if (flags &OPENAT2_REGULAR ) +return -EINVAL ; +return 0 ; }EXPORT_SYMBOL_GPL (nfs_check_flags);
fs/open.c +1 -1
@@ -1211,7 +1211,7 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)* values before calling build_open_flags(), but openat2(2) checks all * of its arguments. */ -if (flags & ~VALID_OPEN_FLAGS ) +if (flags & ~VALID_OPENAT2_FLAGS )return -EINVAL ;if (how->resolve & ~VALID_RESOLVE_FLAGS )return -EINVAL ;
fs/smb/client/dir.c +3 -0
@@ -473,6 +473,9 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,if (unlikely (cifs_forced_shutdown (CIFS_SB (inode->i_sb))))return smb_EIO (smb_eio_trace_forced_shutdown); +if (oflags &OPENAT2_REGULAR ) +return -EINVAL ; +/* * Posix open is only called (at lookup time) for file create now. For * opens (rather than creates), because we do not know if it is a file
fs/vboxsf/dir.c +3 -0
@@ -318,6 +318,9 @@ static int vboxsf_dir_atomic_open(struct inode *parent, struct dentry *dentry,u64 handle;int err; +if (flags &OPENAT2_REGULAR ) +return -EINVAL ; +if (d_in_lookup (dentry)) {struct dentry *res =vboxsf_dir_lookup (parent, dentry,0 );if (res ||d_really_is_positive (dentry))
include/linux/fcntl.h +2 -0
@@ -12,6 +12,8 @@ FASYNC | O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | \ O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE) +#define VALID_OPENAT2_FLAGS (VALID_OPEN_FLAGS | OPENAT2_REGULAR) +/* List of all valid flags for the how->resolve argument: */ #define VALID_RESOLVE_FLAGS \ (RESOLVE_NO_XDEV | RESOLVE_NO_MAGICLINKS | RESOLVE_NO_SYMLINKS | \
include/uapi/asm-generic/errno.h +2 -0
@@ -122,4 +122,6 @@#define EHWPOISON 133/* Memory page has hardware error */ +#define EFTYPE 134/* Wrong file type for the intended operation */ +#endif
include/uapi/asm-generic/fcntl.h +4 -0
@@ -88,6 +88,10 @@#define __O_TMPFILE 020000000#endif +#ifndef OPENAT2_REGULAR +#define OPENAT2_REGULAR 040000000 +#endif +/* a horrid kludge trying to make sure that this will fail on old kernels */ #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
tools/arch/alpha/include/uapi/asm/errno.h +2 -0
@@ -127,4 +127,6 @@#define EHWPOISON 139/* Memory page has hardware error */ +#define EFTYPE 140/* Wrong file type for the intended operation */ +#endif
tools/arch/mips/include/uapi/asm/errno.h +2 -0
@@ -126,6 +126,8 @@#define EHWPOISON 168/* Memory page has hardware error */ +#define EFTYPE 169/* Wrong file type for the intended operation */ +#define EDQUOT 1133/* Quota exceeded */
tools/arch/parisc/include/uapi/asm/errno.h +2 -0
@@ -124,4 +124,6 @@#define EHWPOISON 257/* Memory page has hardware error */ +#define EFTYPE 258/* Wrong file type for the intended operation */ +#endif
tools/arch/sparc/include/uapi/asm/errno.h +2 -0
@@ -117,4 +117,6 @@#define EHWPOISON 135/* Memory page has hardware error */ +#define EFTYPE 136/* Wrong file type for the intended operation */ +#endif
tools/include/uapi/asm-generic/errno.h +2 -0
@@ -122,4 +122,6 @@#define EHWPOISON 133/* Memory page has hardware error */ +#define EFTYPE 134/* Wrong file type for the intended operation */ +#endif
Signature · 1 line
2.53.0
PATCH v4 2/4 kselftest/openat2: test for OPENAT2_REGULAR flag
In reply to Dorjoy ChowdhuryJust a happy path test.
--- .../testing/selftests/openat2/openat2_test.c | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
tools/testing/selftests/openat2/openat2_test.c +45 -1
@@ -320,8 +320,51 @@ void test_openat2_flags(void) } } +#ifndef OPENAT2_REGULAR +#define OPENAT2_REGULAR 040000000 +#endif + +#ifndef EFTYPE +#define EFTYPE 134 +#endif + +void test_openat2_regular_flag (void ) +{ +if (!openat2_supported) { +ksft_test_result_skip ("Skipping %s as openat2 is not supported\n" , __func__); +return ; + } + +struct open_how how = { + .flags =OPENAT2_REGULAR |O_RDONLY + }; + +int fd =sys_openat2 (AT_FDCWD ,"/dev/null" , &how); + +if (fd == -ENOENT ) { +ksft_test_result_skip ("Skipping %s as there is no /dev/null\n" , __func__); +return ; + } + +if (fd != -EFTYPE ) { +ksft_test_result_fail ("openat2 should return EFTYPE\n" ); +return ; + } + + how.flags =OPENAT2_REGULAR |O_DIRECTORY |O_RDONLY ; + + fd =sys_openat2 (AT_FDCWD ,"/dev" , &how); + +if (fd <0 ) { +ksft_test_result_fail ("openat2 should open directory with both O_DIRECTORY and OPENAT2_REGULAR\n" ); +return ; + } + +ksft_test_result_pass ("%s succeeded\n" , __func__); +} +#define NUM_TESTS (NUM_OPENAT2_STRUCT_VARIATIONS * NUM_OPENAT2_STRUCT_TESTS + \ - NUM_OPENAT2_FLAG_TESTS) + NUM_OPENAT2_FLAG_TESTS + 1)int main (int argc,char **argv) {
@@ -330,6 +373,7 @@ int main(int argc, char **argv)test_openat2_struct ();test_openat2_flags (); +test_openat2_regular_flag ();if (ksft_get_fail_cnt () +ksft_get_error_cnt () >0 )ksft_exit_fail ();
Signature · 1 line
2.53.0
PATCH v4 3/4 sparc/fcntl.h: convert O_* flag macros from hex to octal
In reply to Dorjoy ChowdhuryFollowing the convention in include/uapi/asm-generic/fcntl.h and other architecture specific arch/*/include/uapi/asm/fcntl.h files.
--- arch/sparc/include/uapi/asm/fcntl.h | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-)
arch/sparc/include/uapi/asm/fcntl.h +18 -18
@@ -2,23 +2,23 @@#ifndef _SPARC_FCNTL_H#define _SPARC_FCNTL_H -#define O_APPEND 0x0008 -#define FASYNC 0x0040/* fcntl, for BSD compatibility */ -#define O_CREAT 0x0200/* not fcntl */ -#define O_TRUNC 0x0400/* not fcntl */ -#define O_EXCL 0x0800/* not fcntl */ -#define O_DSYNC 0x2000/* used to be O_SYNC, see below */ -#define O_NONBLOCK 0x4000 +#define O_APPEND 0000000010 +#define FASYNC 0000000100/* fcntl, for BSD compatibility */ +#define O_CREAT 0000001000/* not fcntl */ +#define O_TRUNC 0000002000/* not fcntl */ +#define O_EXCL 0000004000/* not fcntl */ +#define O_DSYNC 0000020000/* used to be O_SYNC, see below */ +#define O_NONBLOCK 0000040000#if defined(__sparc__) && defined(__arch64__) -#define O_NDELAY 0x0004 +#define O_NDELAY 0000000004#else -#define O_NDELAY (0x0004 | O_NONBLOCK) +#define O_NDELAY (0000000004 | O_NONBLOCK)#endif -#define O_NOCTTY 0x8000/* not fcntl */ -#define O_LARGEFILE 0x40000 -#define O_DIRECT 0x100000/* direct disk access hint */ -#define O_NOATIME 0x200000 -#define O_CLOEXEC 0x400000 +#define O_NOCTTY 0000100000/* not fcntl */ +#define O_LARGEFILE 0001000000 +#define O_DIRECT 0004000000/* direct disk access hint */ +#define O_NOATIME 0010000000 +#define O_CLOEXEC 0020000000/* * Before Linux 2.6.33 only O_DSYNC semantics were implemented, but using * the O_SYNC flag. We continue to use the existing numerical value
@@ -32,12 +32,12 @@* * Note: __O_SYNC must never be used directly. */ -#define __O_SYNC 0x800000 +#define __O_SYNC 0040000000#define O_SYNC (__O_SYNC|O_DSYNC) -#define O_PATH 0x1000000 -#define __O_TMPFILE 0x2000000 -#define OPENAT2_REGULAR 0x4000000 +#define O_PATH 0100000000 +#define __O_TMPFILE 0200000000 +#define OPENAT2_REGULAR 0400000000#define F_GETOWN 5/* for sockets. */ #define F_SETOWN 6/* for sockets. */
Signature · 1 line
2.53.0
PATCH v4 4/4 mips/fcntl.h: convert O_* flag macros from hex to octal
In reply to Dorjoy ChowdhuryFollowing the convention in include/uapi/asm-generic/fcntl.h and other architecture specific arch/*/include/uapi/asm/fcntl.h files.
--- arch/mips/include/uapi/asm/fcntl.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
arch/mips/include/uapi/asm/fcntl.h +11 -11
@@ -11,15 +11,15 @@#include <asm/sgidefs.h> -#define O_APPEND 0x0008 -#define O_DSYNC 0x0010/* used to be O_SYNC, see below */ -#define O_NONBLOCK 0x0080 -#define O_CREAT 0x0100/* not fcntl */ -#define O_TRUNC 0x0200/* not fcntl */ -#define O_EXCL 0x0400/* not fcntl */ -#define O_NOCTTY 0x0800/* not fcntl */ -#define FASYNC 0x1000/* fcntl, for BSD compatibility */ -#define O_LARGEFILE 0x2000/* allow large file opens */ +#define O_APPEND 0000010 +#define O_DSYNC 0000020/* used to be O_SYNC, see below */ +#define O_NONBLOCK 0000200 +#define O_CREAT 0000400/* not fcntl */ +#define O_TRUNC 0001000/* not fcntl */ +#define O_EXCL 0002000/* not fcntl */ +#define O_NOCTTY 0004000/* not fcntl */ +#define FASYNC 0010000/* fcntl, for BSD compatibility */ +#define O_LARGEFILE 0020000/* allow large file opens */ /* * Before Linux 2.6.33 only O_DSYNC semantics were implemented, but using * the O_SYNC flag. We continue to use the existing numerical value
@@ -33,9 +33,9 @@* * Note: __O_SYNC must never be used directly. */ -#define __O_SYNC 0x4000 +#define __O_SYNC 0040000#define O_SYNC (__O_SYNC|O_DSYNC) -#define O_DIRECT 0x8000/* direct disk access hint */ +#define O_DIRECT 0100000/* direct disk access hint */ #define F_GETLK 14#define F_SETLK 6
Signature · 1 line
2.53.0
Quoted 83 lines · Dorjoy Chowdhury
Note that in v4, for now, I have returned
-EINVALfrom theatomic_opencodepaths. I do want to make this new flag properly supported and proper api behavior, but last time I could not quite understand what should be done for theatomic_opencodepaths. So to have a more concrete discussion, I have included the-EINVALchanges.Changes in v4:
- changedO_REGULARtoOPENAT2_REGULAR
-OPENAT2_REGULARdoes not affectO_PATH
-OPENAT2_REGULARwithO_DIRECTORYwill open path for both directory or regular file
-atomic_opencodepaths updated to return-EINVALwhenOPENAT2_REGULARis set
- commit message includes the uapi-group URL
- v3 is at: https://lore.kernel.org/linux-fsdevel/[email protected]/T/Changes in v3:
- included motivation aboutO_REGULARflag in commit message e.g., programs not wanting to be tricked into opening device nodes
- fixed commit message wrongly referencing ENOTREGULAR instead of ENOTREG
- fixed theO_REGULARflag inarch/parisc/include/uapi/asm/fcntl.hfrom 060000000 to 0100000000
- added 2 commits convertingarch/{mips,sparc}/include/uapi/asm/fcntl.hO_* macros from hex to octal
- v2 is at: https://lore.kernel.org/linux-fsdevel/[email protected]/T/Changes in v2:
- rename ENOTREGULAR to ENOTREG
- define ENOTREG inuapi/asm-generic/errno.h(instead oferrno-base.h) and inarch/*/include/uapi/asm/errno.hfiles
- overrideO_REGULARinarch/{alpha,sparc,parisc}/include/uapi/asm/fcntl.hdue to clash withinclude/uapi/asm-generic/fcntl.h
- I have kept the kselftest but now thatO_REGULARand ENOTREG can have different value on different architectures I am not sure if it's right
- v1 is at: https://lore.kernel.org/linux-fsdevel/[email protected]/T/Hi,
I came upon this "Ability to only open regular files" uapi feature suggestion from https://uapi-group.org/kernel-features/#ability-to-only-open-regular-files
and thought it would be something I could do as a first patch and get to know the kernel code a bit better.I am not quite sure if the semantics that I baked into the code for this
O_REGULARflag's behavior when combined with other flags likeO_CREATlook good and if there are other places that need the checks. I can fixup my patch according to suggestions for improvement. I did some happy path testing and theO_REGULARflag seems to work as intended.Thanks.
Regards,
DorjoyDorjoy Chowdhury (4):
openat2: newOPENAT2_REGULARflag support kselftest/openat2: test forOPENAT2_REGULARflagsparc/fcntl.h: convert O_* flag macros from hex to octalmips/fcntl.h: convert O_* flag macros from hex to octalarch/alpha/include/uapi/asm/errno.h | 2 + arch/alpha/include/uapi/asm/fcntl.h | 1 + arch/mips/include/uapi/asm/errno.h | 2 + arch/mips/include/uapi/asm/fcntl.h | 22 ++++----- 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 | 35 +++++++------- fs/9p/vfs_inode.c | 3 ++ fs/9p/vfs_inode_dotl.c | 3 ++ fs/ceph/file.c | 3 ++ fs/fuse/dir.c | 3 ++ fs/gfs2/inode.c | 3 ++ fs/namei.c | 9 +++- fs/nfs/dir.c | 3 ++ fs/nfs/file.c | 3 ++ fs/open.c | 2 +- fs/smb/client/dir.c | 3 ++ fs/vboxsf/dir.c | 3 ++ 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 + .../testing/selftests/openat2/openat2_test.c | 46 ++++++++++++++++++- 28 files changed, 138 insertions(+), 31 deletions(-)
Quoted 3 lines
--
2.53.0
Hi,
I would appreciate some feedback on this patch series. I think there are 2 things that need definite feedback.
1) I have defined OPENAT2_REGULAR to be in the 32-bit space. At first, I tried to make it the 33rd bit but then realized, there are existing structs like (struct open_flag and others) where the flag (or similar) members are of type int or unsigned int which get passed over to lots of places. So I ended up making it a flag in the 32-bit space. I guess it's okay as it's not easy to add new flags to existing open syscalls due to backward compatibility anyway.
2) For now, I am returning -EINVAL from the atomic_open codepaths. What would be the proper way to handle this? And is there anything needed for the file_operations.open codepaths (right now, do_open already checks and returns errors for the new flag before we reach file_operations.open)? I am a bit confused about the new flag and network filesystems where obviously the new flag won't be recognized by the server. So, if we want to handle the new flag properly in those filesystems, does the flag need to be masked out? It's a bit hard for me to understand the right thing that should be done as I am not familiar with all the code so I appreciate any help and suggestions on this.
Thanks.
Regards,
Dorjoy
Quoted 113 lines · Dorjoy Chowdhury
Quoted 83 lines · Dorjoy Chowdhury
Note that in v4, for now, I have returned
-EINVALfrom theatomic_opencodepaths. I do want to make this new flag properly supported and proper api behavior, but last time I could not quite understand what should be done for theatomic_opencodepaths. So to have a more concrete discussion, I have included the-EINVALchanges.Changes in v4:
- changedO_REGULARtoOPENAT2_REGULAR
-OPENAT2_REGULARdoes not affectO_PATH
-OPENAT2_REGULARwithO_DIRECTORYwill open path for both directory or regular file
-atomic_opencodepaths updated to return-EINVALwhenOPENAT2_REGULARis set
- commit message includes the uapi-group URL
- v3 is at: https://lore.kernel.org/linux-fsdevel/[email protected]/T/Changes in v3:
- included motivation aboutO_REGULARflag in commit message e.g., programs not wanting to be tricked into opening device nodes
- fixed commit message wrongly referencing ENOTREGULAR instead of ENOTREG
- fixed theO_REGULARflag inarch/parisc/include/uapi/asm/fcntl.hfrom 060000000 to 0100000000
- added 2 commits convertingarch/{mips,sparc}/include/uapi/asm/fcntl.hO_* macros from hex to octal
- v2 is at: https://lore.kernel.org/linux-fsdevel/[email protected]/T/Changes in v2:
- rename ENOTREGULAR to ENOTREG
- define ENOTREG inuapi/asm-generic/errno.h(instead oferrno-base.h) and inarch/*/include/uapi/asm/errno.hfiles
- overrideO_REGULARinarch/{alpha,sparc,parisc}/include/uapi/asm/fcntl.hdue to clash withinclude/uapi/asm-generic/fcntl.h
- I have kept the kselftest but now thatO_REGULARand ENOTREG can have different value on different architectures I am not sure if it's right
- v1 is at: https://lore.kernel.org/linux-fsdevel/[email protected]/T/Hi,
I came upon this "Ability to only open regular files" uapi feature suggestion from https://uapi-group.org/kernel-features/#ability-to-only-open-regular-files
and thought it would be something I could do as a first patch and get to know the kernel code a bit better.I am not quite sure if the semantics that I baked into the code for this
O_REGULARflag's behavior when combined with other flags likeO_CREATlook good and if there are other places that need the checks. I can fixup my patch according to suggestions for improvement. I did some happy path testing and theO_REGULARflag seems to work as intended.Thanks.
Regards,
DorjoyDorjoy Chowdhury (4):
openat2: newOPENAT2_REGULARflag support kselftest/openat2: test forOPENAT2_REGULARflagsparc/fcntl.h: convert O_* flag macros from hex to octalmips/fcntl.h: convert O_* flag macros from hex to octalarch/alpha/include/uapi/asm/errno.h | 2 + arch/alpha/include/uapi/asm/fcntl.h | 1 + arch/mips/include/uapi/asm/errno.h | 2 + arch/mips/include/uapi/asm/fcntl.h | 22 ++++----- 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 | 35 +++++++------- fs/9p/vfs_inode.c | 3 ++ fs/9p/vfs_inode_dotl.c | 3 ++ fs/ceph/file.c | 3 ++ fs/fuse/dir.c | 3 ++ fs/gfs2/inode.c | 3 ++ fs/namei.c | 9 +++- fs/nfs/dir.c | 3 ++ fs/nfs/file.c | 3 ++ fs/open.c | 2 +- fs/smb/client/dir.c | 3 ++ fs/vboxsf/dir.c | 3 ++ 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 + .../testing/selftests/openat2/openat2_test.c | 46 ++++++++++++++++++- 28 files changed, 138 insertions(+), 31 deletions(-)Quoted 3 lines
--
2.53.0Hi,
I would appreciate some feedback on this patch series. I think there are 2 things that need definite feedback.1) I have defined
OPENAT2_REGULARto be in the 32-bit space. At first, I tried to make it the 33rd bit but then realized, there are existing structs like (structopen_flagand others) where the flag (or similar) members are of type int or unsigned int which get passed over to lots of places. So I ended up making it a flag in the 32-bit space. I guess it's okay as it's not easy to add new flags to existing open syscalls due to backward compatibility anyway.2) For now, I am returning
-EINVALfrom theatomic_opencodepaths. What would be the proper way to handle this? And is there anything needed for the file_operations.open codepaths (right now,do_openalready checks and returns errors for the new flag before we reach file_operations.open)? I am a bit confused about the new flag and network filesystems where obviously the new flag won't be recognized by the server. So, if we want to handle the new flag properly in those filesystems, does the flag need to be masked out? It's a bit hard for me to understand the right thing that should be done as I am not familiar with all the code so I appreciate any help and suggestions on this.
Quoted 4 lines
Thanks.
Regards,
Dorjoy
Hi,
Gentle ping for review on this patch series. Thanks!
Regards,
Dorjoy