aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2015-09-09 19:31:08 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2015-09-09 19:31:08 +0000
commit9e18c9eb27cd81ed9e603105af1bebd0874230f7 (patch)
tree5f8a291f9d15bc0195612b1118ac92c1dffab01d
parent05e526fb5ab9d58a21fc4c2f1be782c00ff62edd (diff)
For open("name", O_DIRECTORY | O_CREAT), do not try to create the
named node, open(2) cannot create directories. But do allow the flag combination to succeed if the directory already exists. Declare the open("name", O_DIRECTORY | O_CREAT | O_EXCL) always invalid for the same reason, since open(2) cannot create directory. Note that there is an argument that O_DIRECTORY | O_CREAT should be invalid always, regardless of the target directory existence or O_EXCL. The current fix is conservative and allows the call to succeed in the situation where it succeeded before the patch. Reported by: Tom Ridge <freebsd@tom-ridge.com> Reviewed by: rwatson PR: 202892 Sponsored by: The FreeBSD Foundation MFC after: 1 week
Notes
svn path=/head/; revision=287599
-rw-r--r--sys/kern/vfs_vnops.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 740123f7b433..18a9ac311020 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -195,7 +195,10 @@ vn_open_cred(struct nameidata *ndp, int *flagp, int cmode, u_int vn_open_flags,
restart:
fmode = *flagp;
- if (fmode & O_CREAT) {
+ if ((fmode & (O_CREAT | O_EXCL | O_DIRECTORY)) == (O_CREAT |
+ O_EXCL | O_DIRECTORY))
+ return (EINVAL);
+ else if ((fmode & (O_CREAT | O_DIRECTORY)) == O_CREAT) {
ndp->ni_cnd.cn_nameiop = CREATE;
/*
* Set NOCACHE to avoid flushing the cache when