Skip to content

Commit 3db5984

Browse files
Miklos Szeredigregkh
authored andcommitted
vfs: canonicalize create mode in build_open_flags()
commit e68726f upstream. Userspace can pass weird create mode in open(2) that we canonicalize to "(mode & S_IALLUGO) | S_IFREG" in vfs_create(). The problem is that we use the uncanonicalized mode before calling vfs_create() with unforseen consequences. So do the canonicalization early in build_open_flags(). Signed-off-by: Miklos Szeredi <[email protected]> Tested-by: Richard W.M. Jones <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 57dba9b commit 3db5984

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/open.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,10 @@ static inline int build_open_flags(int flags, int mode, struct open_flags *op)
900900
int lookup_flags = 0;
901901
int acc_mode;
902902

903-
if (!(flags & O_CREAT))
904-
mode = 0;
905-
op->mode = mode;
903+
if (flags & O_CREAT)
904+
op->mode = (mode & S_IALLUGO) | S_IFREG;
905+
else
906+
op->mode = 0;
906907

907908
/* Must never be set by userspace */
908909
flags &= ~FMODE_NONOTIFY;

0 commit comments

Comments
 (0)