@@ -1503,7 +1503,7 @@ int may_open(struct path *path, int acc_mode, int flag)
15031503 * An append-only file must be opened in append mode for writing.
15041504 */
15051505 if (IS_APPEND (inode )) {
1506- if ((flag & FMODE_WRITE ) && !(flag & O_APPEND ))
1506+ if ((flag & O_ACCMODE ) != O_RDONLY && !(flag & O_APPEND ))
15071507 return - EPERM ;
15081508 if (flag & O_TRUNC )
15091509 return - EPERM ;
@@ -1547,7 +1547,7 @@ static int handle_truncate(struct path *path)
15471547 * what get passed to sys_open().
15481548 */
15491549static int __open_namei_create (struct nameidata * nd , struct path * path ,
1550- int flag , int mode )
1550+ int open_flag , int mode )
15511551{
15521552 int error ;
15531553 struct dentry * dir = nd -> path .dentry ;
@@ -1565,7 +1565,7 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
15651565 if (error )
15661566 return error ;
15671567 /* Don't check for write permission, don't truncate */
1568- return may_open (& nd -> path , 0 , flag & ~O_TRUNC );
1568+ return may_open (& nd -> path , 0 , open_flag & ~O_TRUNC );
15691569}
15701570
15711571/*
@@ -1736,7 +1736,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
17361736 error = mnt_want_write (nd .path .mnt );
17371737 if (error )
17381738 goto exit_mutex_unlock ;
1739- error = __open_namei_create (& nd , & path , flag , mode );
1739+ error = __open_namei_create (& nd , & path , open_flag , mode );
17401740 if (error ) {
17411741 mnt_drop_write (nd .path .mnt );
17421742 goto exit ;
@@ -1798,7 +1798,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
17981798 if (error )
17991799 goto exit ;
18001800 }
1801- error = may_open (& nd .path , acc_mode , flag );
1801+ error = may_open (& nd .path , acc_mode , open_flag );
18021802 if (error ) {
18031803 if (will_truncate )
18041804 mnt_drop_write (nd .path .mnt );
0 commit comments