aboutsummaryrefslogtreecommitdiffstats
path: root/fs/namei.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/namei.c')
-rw-r--r--fs/namei.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/fs/namei.c b/fs/namei.c
index ee01308a01d1..fcfc5539252c 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1544,28 +1544,31 @@ int may_open(struct path *path, int acc_mode, int flag)
1544 * An append-only file must be opened in append mode for writing. 1544 * An append-only file must be opened in append mode for writing.
1545 */ 1545 */
1546 if (IS_APPEND(inode)) { 1546 if (IS_APPEND(inode)) {
1547 error = -EPERM;
1547 if ((flag & FMODE_WRITE) && !(flag & O_APPEND)) 1548 if ((flag & FMODE_WRITE) && !(flag & O_APPEND))
1548 return -EPERM; 1549 goto err_out;
1549 if (flag & O_TRUNC) 1550 if (flag & O_TRUNC)
1550 return -EPERM; 1551 goto err_out;
1551 } 1552 }
1552 1553
1553 /* O_NOATIME can only be set by the owner or superuser */ 1554 /* O_NOATIME can only be set by the owner or superuser */
1554 if (flag & O_NOATIME) 1555 if (flag & O_NOATIME)
1555 if (!is_owner_or_cap(inode)) 1556 if (!is_owner_or_cap(inode)) {
1556 return -EPERM; 1557 error = -EPERM;
1558 goto err_out;
1559 }
1557 1560
1558 /* 1561 /*
1559 * Ensure there are no outstanding leases on the file. 1562 * Ensure there are no outstanding leases on the file.
1560 */ 1563 */
1561 error = break_lease(inode, flag); 1564 error = break_lease(inode, flag);
1562 if (error) 1565 if (error)
1563 return error; 1566 goto err_out;
1564 1567
1565 if (flag & O_TRUNC) { 1568 if (flag & O_TRUNC) {
1566 error = get_write_access(inode); 1569 error = get_write_access(inode);
1567 if (error) 1570 if (error)
1568 return error; 1571 goto err_out;
1569 1572
1570 /* 1573 /*
1571 * Refuse to truncate files with mandatory locks held on them. 1574 * Refuse to truncate files with mandatory locks held on them.
@@ -1583,12 +1586,17 @@ int may_open(struct path *path, int acc_mode, int flag)
1583 } 1586 }
1584 put_write_access(inode); 1587 put_write_access(inode);
1585 if (error) 1588 if (error)
1586 return error; 1589 goto err_out;
1587 } else 1590 } else
1588 if (flag & FMODE_WRITE) 1591 if (flag & FMODE_WRITE)
1589 vfs_dq_init(inode); 1592 vfs_dq_init(inode);
1590 1593
1591 return 0; 1594 return 0;
1595err_out:
1596 ima_counts_put(path, acc_mode ?
1597 acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC) :
1598 ACC_MODE(flag) & (MAY_READ | MAY_WRITE));
1599 return error;
1592} 1600}
1593 1601
1594/* 1602/*