Commit 7ce1e15d authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for_v5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs

Pull ext2, quota, udf fixes and cleanups from Jan Kara:

 - two small quota fixes (in grace time handling and possible missed
   accounting of preallocated blocks beyond EOF).

 - some ext2 cleanups

 - udf fixes for better compatibility with Windows 10 generated media
   (named streams, write-protection using domain-identifier, placement
   of volume recognition sequence)

 - some udf cleanups

* tag 'for_v5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs:
  quota: fix wrong condition in is_quota_modification()
  fs-udf: Delete an unnecessary check before brelse()
  ext2: Delete an unnecessary check before brelse()
  udf: Drop forward function declarations
  udf: Verify domain identifier fields
  udf: augment UDF permissions on new inodes
  udf: Use dynamic debug infrastructure
  udf: reduce leakage of blocks related to named streams
  udf: prevent allocation beyond UDF partition
  quota: fix condition for resetting time limit in do_set_dqblk()
  ext2: code cleanup for ext2_free_blocks()
  ext2: fix block range in ext2_data_block_valid()
  udf: support 2048-byte spacing of VRS descriptors on 4K media
  udf: refactor VRS descriptor identification
parents 70cb0d02 6565c182
......@@ -490,9 +490,7 @@ void ext2_free_blocks (struct inode * inode, unsigned long block,
struct ext2_super_block * es = sbi->s_es;
unsigned freed = 0, group_freed;
if (block < le32_to_cpu(es->s_first_data_block) ||
block + count < block ||
block + count > le32_to_cpu(es->s_blocks_count)) {
if (!ext2_data_block_valid(sbi, block, count)) {
ext2_error (sb, "ext2_free_blocks",
"Freeing blocks not in datazone - "
"block = %lu, count = %lu", block, count);
......@@ -1203,13 +1201,13 @@ int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
unsigned int count)
{
if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
(start_blk + count < start_blk) ||
(start_blk > le32_to_cpu(sbi->s_es->s_blocks_count)))
(start_blk + count - 1 < start_blk) ||
(start_blk + count - 1 >= le32_to_cpu(sbi->s_es->s_blocks_count)))
return 0;
/* Ensure we do not step over superblock */
if ((start_blk <= sbi->s_sb_block) &&
(start_blk + count >= sbi->s_sb_block))
(start_blk + count - 1 >= sbi->s_sb_block))
return 0;
return 1;
......
......@@ -162,8 +162,7 @@ static void ext2_put_super (struct super_block * sb)
}
db_count = sbi->s_gdb_count;
for (i = 0; i < db_count; i++)
if (sbi->s_group_desc[i])
brelse (sbi->s_group_desc[i]);
brelse(sbi->s_group_desc[i]);
kfree(sbi->s_group_desc);
kfree(sbi->s_debts);
percpu_counter_destroy(&sbi->s_freeblocks_counter);
......
......@@ -794,7 +794,7 @@ ext2_xattr_delete_inode(struct inode *inode)
if (!EXT2_I(inode)->i_file_acl)
goto cleanup;
if (!ext2_data_block_valid(sbi, EXT2_I(inode)->i_file_acl, 0)) {
if (!ext2_data_block_valid(sbi, EXT2_I(inode)->i_file_acl, 1)) {
ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
"inode %ld: xattr block %d is out of data blocks range",
inode->i_ino, EXT2_I(inode)->i_file_acl);
......
......@@ -2731,7 +2731,7 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
if (check_blim) {
if (!dm->dqb_bsoftlimit ||
dm->dqb_curspace + dm->dqb_rsvspace < dm->dqb_bsoftlimit) {
dm->dqb_curspace + dm->dqb_rsvspace <= dm->dqb_bsoftlimit) {
dm->dqb_btime = 0;
clear_bit(DQ_BLKS_B, &dquot->dq_flags);
} else if (!(di->d_fieldmask & QC_SPC_TIMER))
......@@ -2740,7 +2740,7 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
}
if (check_ilim) {
if (!dm->dqb_isoftlimit ||
dm->dqb_curinodes < dm->dqb_isoftlimit) {
dm->dqb_curinodes <= dm->dqb_isoftlimit) {
dm->dqb_itime = 0;
clear_bit(DQ_INODES_B, &dquot->dq_flags);
} else if (!(di->d_fieldmask & QC_INO_TIMER))
......
......@@ -325,6 +325,17 @@ static udf_pblk_t udf_bitmap_new_block(struct super_block *sb,
newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
(sizeof(struct spaceBitmapDesc) << 3);
if (newblock >= sbi->s_partmaps[partition].s_partition_len) {
/*
* Ran off the end of the bitmap, and bits following are
* non-compliant (not all zero)
*/
udf_err(sb, "bitmap for partition %d corrupted (block %u marked"
" as free, partition length is %u)\n", partition,
newblock, sbi->s_partmaps[partition].s_partition_len);
goto error_return;
}
if (!udf_clear_bit(bit, bh->b_data)) {
udf_debug("bit already cleared for block %d\n", bit);
goto repeat;
......
......@@ -88,6 +88,20 @@ struct regid {
#define ENTITYID_FLAGS_DIRTY 0x00
#define ENTITYID_FLAGS_PROTECTED 0x01
/* OSTA UDF 2.1.5.2 */
#define UDF_ID_COMPLIANT "*OSTA UDF Compliant"
/* OSTA UDF 2.1.5.3 */
struct domainEntityIDSuffix {
uint16_t revision;
uint8_t flags;
uint8_t reserved[5];
};
/* OSTA UDF 2.1.5.3 */
#define ENTITYIDSUFFIX_FLAGS_HARDWRITEPROTECT 0
#define ENTITYIDSUFFIX_FLAGS_SOFTWRITEPROTECT 1
/* Volume Structure Descriptor (ECMA 167r3 2/9.1) */
#define VSD_STD_ID_LEN 5
struct volStructDesc {
......
......@@ -280,6 +280,9 @@ static int udf_setattr(struct dentry *dentry, struct iattr *attr)
return error;
}
if (attr->ia_valid & ATTR_MODE)
udf_update_extra_perms(inode, attr->ia_mode);
setattr_copy(inode, attr);
mark_inode_dirty(inode);
return 0;
......
......@@ -118,6 +118,9 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode)
iinfo->i_lenAlloc = 0;
iinfo->i_use = 0;
iinfo->i_checkpoint = 1;
iinfo->i_extraPerms = FE_PERM_U_CHATTR;
udf_update_extra_perms(inode, mode);
if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
......
......@@ -45,6 +45,13 @@
#define EXTENT_MERGE_SIZE 5
#define FE_MAPPED_PERMS (FE_PERM_U_READ | FE_PERM_U_WRITE | FE_PERM_U_EXEC | \
FE_PERM_G_READ | FE_PERM_G_WRITE | FE_PERM_G_EXEC | \
FE_PERM_O_READ | FE_PERM_O_WRITE | FE_PERM_O_EXEC)
#define FE_DELETE_PERMS (FE_PERM_U_DELETE | FE_PERM_G_DELETE | \
FE_PERM_O_DELETE)
static umode_t udf_convert_permissions(struct fileEntry *);
static int udf_update_inode(struct inode *, int);
static int udf_sync_inode(struct inode *inode);
......@@ -1458,6 +1465,8 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode)
else
inode->i_mode = udf_convert_permissions(fe);
inode->i_mode &= ~sbi->s_umask;
iinfo->i_extraPerms = le32_to_cpu(fe->permissions) & ~FE_MAPPED_PERMS;
read_unlock(&sbi->s_cred_lock);
link_count = le16_to_cpu(fe->fileLinkCount);
......@@ -1485,6 +1494,8 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode)
iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
iinfo->i_lenAlloc = le32_to_cpu(fe->lengthAllocDescs);
iinfo->i_checkpoint = le32_to_cpu(fe->checkpoint);
iinfo->i_streamdir = 0;
iinfo->i_lenStreams = 0;
} else {
inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9);
......@@ -1498,6 +1509,16 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode)
iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
iinfo->i_lenAlloc = le32_to_cpu(efe->lengthAllocDescs);
iinfo->i_checkpoint = le32_to_cpu(efe->checkpoint);
/* Named streams */
iinfo->i_streamdir = (efe->streamDirectoryICB.extLength != 0);
iinfo->i_locStreamdir =
lelb_to_cpu(efe->streamDirectoryICB.extLocation);
iinfo->i_lenStreams = le64_to_cpu(efe->objectSize);
if (iinfo->i_lenStreams >= inode->i_size)
iinfo->i_lenStreams -= inode->i_size;
else
iinfo->i_lenStreams = 0;
}
inode->i_generation = iinfo->i_unique;
......@@ -1619,6 +1640,23 @@ static umode_t udf_convert_permissions(struct fileEntry *fe)
return mode;
}
void udf_update_extra_perms(struct inode *inode, umode_t mode)
{
struct udf_inode_info *iinfo = UDF_I(inode);
/*
* UDF 2.01 sec. 3.3.3.3 Note 2:
* In Unix, delete permission tracks write
*/
iinfo->i_extraPerms &= ~FE_DELETE_PERMS;
if (mode & 0200)
iinfo->i_extraPerms |= FE_PERM_U_DELETE;
if (mode & 0020)
iinfo->i_extraPerms |= FE_PERM_G_DELETE;
if (mode & 0002)
iinfo->i_extraPerms |= FE_PERM_O_DELETE;
}
int udf_write_inode(struct inode *inode, struct writeback_control *wbc)
{
return udf_update_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
......@@ -1691,10 +1729,7 @@ static int udf_update_inode(struct inode *inode, int do_sync)
((inode->i_mode & 0070) << 2) |
((inode->i_mode & 0700) << 4);
udfperms |= (le32_to_cpu(fe->permissions) &
(FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
udfperms |= iinfo->i_extraPerms;
fe->permissions = cpu_to_le32(udfperms);
if (S_ISDIR(inode->i_mode) && inode->i_nlink > 0)
......@@ -1760,9 +1795,19 @@ static int udf_update_inode(struct inode *inode, int do_sync)
iinfo->i_ext.i_data,
inode->i_sb->s_blocksize -
sizeof(struct extendedFileEntry));
efe->objectSize = cpu_to_le64(inode->i_size);
efe->objectSize =
cpu_to_le64(inode->i_size + iinfo->i_lenStreams);
efe->logicalBlocksRecorded = cpu_to_le64(lb_recorded);
if (iinfo->i_streamdir) {
struct long_ad *icb_lad = &efe->streamDirectoryICB;
icb_lad->extLocation =
cpu_to_lelb(iinfo->i_locStreamdir);
icb_lad->extLength =
cpu_to_le32(inode->i_sb->s_blocksize);
}
udf_adjust_time(iinfo, inode->i_atime);
udf_adjust_time(iinfo, inode->i_mtime);
udf_adjust_time(iinfo, inode->i_ctime);
......
This diff is collapsed.
......@@ -38,16 +38,20 @@ struct udf_inode_info {
__u32 i_next_alloc_block;
__u32 i_next_alloc_goal;
__u32 i_checkpoint;
__u32 i_extraPerms;
unsigned i_alloc_type : 3;
unsigned i_efe : 1; /* extendedFileEntry */
unsigned i_use : 1; /* unallocSpaceEntry */
unsigned i_strat4096 : 1;
unsigned reserved : 26;
unsigned i_streamdir : 1;
unsigned reserved : 25;
union {
struct short_ad *i_sad;
struct long_ad *i_lad;
__u8 *i_data;
} i_ext;
struct kernel_lb_addr i_locStreamdir;
__u64 i_lenStreams;
struct rw_semaphore i_data_sem;
struct udf_ext_cache cached_extent;
/* Spinlock for protecting extent cache */
......
......@@ -31,16 +31,8 @@ extern __printf(3, 4) void _udf_warn(struct super_block *sb,
#define udf_info(fmt, ...) \
pr_info("INFO " fmt, ##__VA_ARGS__)
#undef UDFFS_DEBUG
#ifdef UDFFS_DEBUG
#define udf_debug(fmt, ...) \
printk(KERN_DEBUG pr_fmt("%s:%d:%s: " fmt), \
__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
#define udf_debug(fmt, ...) \
no_printk(fmt, ##__VA_ARGS__)
#endif
pr_debug("%s:%d:%s: " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
#define udf_fixed_to_variable(x) ( ( ( (x) >> 5 ) * 39 ) + ( (x) & 0x0000001F ) )
#define udf_variable_to_fixed(x) ( ( ( (x) / 39 ) << 5 ) + ( (x) % 39 ) )
......@@ -178,6 +170,7 @@ extern int8_t udf_next_aext(struct inode *, struct extent_position *,
struct kernel_lb_addr *, uint32_t *, int);
extern int8_t udf_current_aext(struct inode *, struct extent_position *,
struct kernel_lb_addr *, uint32_t *, int);
extern void udf_update_extra_perms(struct inode *inode, umode_t mode);
/* misc.c */
extern struct buffer_head *udf_tgetblk(struct super_block *sb,
......
......@@ -22,7 +22,7 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
/* i_mutex must being held */
static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
{
return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
return (ia->ia_valid & ATTR_SIZE) ||
(ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
(ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment