Skip to content

Commit e68726f

Browse files
author
Miklos Szeredi
committed
vfs: canonicalize create mode in build_open_flags()
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]> CC: [email protected]
1 parent ddf343f commit e68726f

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
@@ -852,9 +852,10 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o
852852
int lookup_flags = 0;
853853
int acc_mode;
854854

855-
if (!(flags & O_CREAT))
856-
mode = 0;
857-
op->mode = mode;
855+
if (flags & O_CREAT)
856+
op->mode = (mode & S_IALLUGO) | S_IFREG;
857+
else
858+
op->mode = 0;
858859

859860
/* Must never be set by userspace */
860861
flags &= ~FMODE_NONOTIFY;

0 commit comments

Comments
 (0)