Commit bb458c64 authored by Al Viro's avatar Al Viro

Safer ABI for O_TMPFILE

[suggested by Rasmus Villemoes] make O_DIRECTORY | O_RDWR part of O_TMPFILE;
that will fail on old kernels in a lot more cases than what I came up with.
And make sure O_CREAT doesn't get there...
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 4fbeb19d
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#define O_SYNC (__O_SYNC|O_DSYNC) #define O_SYNC (__O_SYNC|O_DSYNC)
#define O_PATH 040000000 #define O_PATH 040000000
#define O_TMPFILE 0100000000 #define __O_TMPFILE 0100000000
#define F_GETLK 7 #define F_GETLK 7
#define F_SETLK 8 #define F_SETLK 8
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#define O_INVISIBLE 004000000 /* invisible I/O, for DMAPI/XDSM */ #define O_INVISIBLE 004000000 /* invisible I/O, for DMAPI/XDSM */
#define O_PATH 020000000 #define O_PATH 020000000
#define O_TMPFILE 040000000 #define __O_TMPFILE 040000000
#define F_GETLK64 8 #define F_GETLK64 8
#define F_SETLK64 9 #define F_SETLK64 9
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#define O_SYNC (__O_SYNC|O_DSYNC) #define O_SYNC (__O_SYNC|O_DSYNC)
#define O_PATH 0x1000000 #define O_PATH 0x1000000
#define O_TMPFILE 0x2000000 #define __O_TMPFILE 0x2000000
#define F_GETOWN 5 /* for sockets. */ #define F_GETOWN 5 /* for sockets. */
#define F_SETOWN 6 /* for sockets. */ #define F_SETOWN 6 /* for sockets. */
......
...@@ -2977,7 +2977,7 @@ static struct file *path_openat(int dfd, struct filename *pathname, ...@@ -2977,7 +2977,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
file->f_flags = op->open_flag; file->f_flags = op->open_flag;
if (unlikely(file->f_flags & O_TMPFILE)) { if (unlikely(file->f_flags & __O_TMPFILE)) {
error = do_tmpfile(dfd, pathname, nd, flags, op, file, &opened); error = do_tmpfile(dfd, pathname, nd, flags, op, file, &opened);
goto out; goto out;
} }
......
...@@ -840,8 +840,8 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o ...@@ -840,8 +840,8 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o
if (flags & __O_SYNC) if (flags & __O_SYNC)
flags |= O_DSYNC; flags |= O_DSYNC;
if (flags & O_TMPFILE) { if (flags & __O_TMPFILE) {
if (!(flags & O_CREAT)) if ((flags & O_TMPFILE_MASK) != O_TMPFILE)
return -EINVAL; return -EINVAL;
acc_mode = MAY_OPEN | ACC_MODE(flags); acc_mode = MAY_OPEN | ACC_MODE(flags);
} else if (flags & O_PATH) { } else if (flags & O_PATH) {
......
...@@ -84,10 +84,14 @@ ...@@ -84,10 +84,14 @@
#define O_PATH 010000000 #define O_PATH 010000000
#endif #endif
#ifndef O_TMPFILE #ifndef __O_TMPFILE
#define O_TMPFILE 020000000 #define __O_TMPFILE 020000000
#endif #endif
/* a horrid kludge trying to make sure that this will fail on old kernels */
#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY | O_RDWR)
#define O_TMPFILE_MASK (__O_TMPFILE | O_DIRECTORY | O_CREAT | O_ACCMODE)
#ifndef O_NDELAY #ifndef O_NDELAY
#define O_NDELAY O_NONBLOCK #define O_NDELAY O_NONBLOCK
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment