Commit 31d1726d authored by Al Viro's avatar Al Viro

make build_open_flags() treat O_CREAT | O_EXCL as implying O_NOFOLLOW

O_CREAT | O_EXCL means "-EEXIST if we run into a trailing symlink".
As it is, we might or might not have LOOKUP_FOLLOW in op->intent
in that case - that depends upon having O_NOFOLLOW in open flags.
It doesn't matter, since we won't be checking it in that case -
do_last() bails out earlier.

However, making sure it's not set (i.e. acting as if we had an explicit
O_NOFOLLOW) makes the behaviour more explicit and allows to reorder the
check for O_CREAT | O_EXCL in do_last() with the call of step_into()
immediately following it.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 1c9f5e06
...@@ -3396,22 +3396,17 @@ static int do_last(struct nameidata *nd, ...@@ -3396,22 +3396,17 @@ static int do_last(struct nameidata *nd,
if (unlikely(error < 0)) if (unlikely(error < 0))
return error; return error;
/*
* create/update audit record if it already exists.
*/
audit_inode(nd->name, path.dentry, 0);
if (unlikely((open_flag & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) {
path_to_nameidata(&path, nd);
return -EEXIST;
}
seq = 0; /* out of RCU mode, so the value doesn't matter */ seq = 0; /* out of RCU mode, so the value doesn't matter */
inode = d_backing_inode(path.dentry); inode = d_backing_inode(path.dentry);
finish_lookup: finish_lookup:
error = step_into(nd, &path, 0, inode, seq); error = step_into(nd, &path, 0, inode, seq);
if (unlikely(error)) if (unlikely(error))
return error; return error;
if (unlikely((open_flag & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) {
audit_inode(nd->name, nd->path.dentry, 0);
return -EEXIST;
}
finish_open: finish_open:
/* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */ /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
error = complete_walk(nd); error = complete_walk(nd);
......
...@@ -1049,8 +1049,10 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op) ...@@ -1049,8 +1049,10 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)
if (flags & O_CREAT) { if (flags & O_CREAT) {
op->intent |= LOOKUP_CREATE; op->intent |= LOOKUP_CREATE;
if (flags & O_EXCL) if (flags & O_EXCL) {
op->intent |= LOOKUP_EXCL; op->intent |= LOOKUP_EXCL;
flags |= O_NOFOLLOW;
}
} }
if (flags & O_DIRECTORY) if (flags & O_DIRECTORY)
......
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