Skip to content

Commit

Permalink
Merge tag 'for_v5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/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
  • Loading branch information
torvalds committed Sep 21, 2019
2 parents 70cb0d0 + 6565c18 commit 7ce1e15
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 136 deletions.
10 changes: 4 additions & 6 deletions fs/ext2/balloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions fs/ext2/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions fs/quota/dquot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions fs/udf/balloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions fs/udf/ecma_167.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions fs/udf/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions fs/udf/ialloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
55 changes: 50 additions & 5 deletions fs/udf/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 7ce1e15

Please sign in to comment.