Skip to content

Commit 1500e7e

Browse files
committed
Merge tag 'for_v6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull ext2, quota, and udf updates from Jan Kara: - fixes for possible use-after-free issues with quota when racing with chown - fixes for ext2 crashing when xattr allocation races with another block allocation to the same file from page writeback code - fix for block number overflow in ext2 - marking of reiserfs as obsolete in MAINTAINERS - assorted minor cleanups * tag 'for_v6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: ext2: Fix kernel-doc warnings ext2: improve consistency of ext2_fsblk_t datatype usage ext2: dump current reservation window info ext2: fix race between setxattr and write back ext2: introduce new flags argument for ext2_new_blocks() ext2: remove ext2_new_block() ext2: fix datatype of block number in ext2_xattr_set2() udf: Drop pointless aops assignment quota: use lockdep_assert_held_write in dquot_load_quota_sb MAINTAINERS: change reiserfs status to obsolete udf: Fix -Wstringop-overflow warnings quota: simplify drop_dquot_ref() quota: fix dqput() to follow the guarantees dquot_srcu should provide quota: add new helper dquot_active() quota: rename dquot_active() to inode_quota_active() quota: factor out dquot_write_dquot() ext2: remove redundant assignment to variable desc and variable best_desc
2 parents 63580f6 + df1ae36 commit 1500e7e

File tree

9 files changed

+220
-219
lines changed

9 files changed

+220
-219
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18085,7 +18085,7 @@ F: include/linux/regmap.h
1808518085

1808618086
REISERFS FILE SYSTEM
1808718087
L: reiserfs-devel@vger.kernel.org
18088-
S: Supported
18088+
S: Obsolete
1808918089
F: fs/reiserfs/
1809018090

1809118091
REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM

fs/ext2/balloc.c

Lines changed: 63 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ void ext2_discard_reservation(struct inode *inode)
472472
* @block: start physical block to free
473473
* @count: number of blocks to free
474474
*/
475-
void ext2_free_blocks (struct inode * inode, unsigned long block,
476-
unsigned long count)
475+
void ext2_free_blocks(struct inode * inode, ext2_fsblk_t block,
476+
unsigned long count)
477477
{
478478
struct buffer_head *bitmap_bh = NULL;
479479
struct buffer_head * bh2;
@@ -716,36 +716,34 @@ ext2_try_to_allocate(struct super_block *sb, int group,
716716
}
717717

718718
/**
719-
* find_next_reservable_window():
720-
* find a reservable space within the given range.
721-
* It does not allocate the reservation window for now:
722-
* alloc_new_reservation() will do the work later.
719+
* find_next_reservable_window - Find a reservable space within the given range.
720+
* @search_head: The list to search.
721+
* @my_rsv: The reservation we're currently using.
722+
* @sb: The super block.
723+
* @start_block: The first block we consider to start the real search from
724+
* @last_block: The maximum block number that our goal reservable space
725+
* could start from.
723726
*
724-
* @search_head: the head of the searching list;
725-
* This is not necessarily the list head of the whole filesystem
727+
* It does not allocate the reservation window: alloc_new_reservation()
728+
* will do the work later.
726729
*
727-
* We have both head and start_block to assist the search
728-
* for the reservable space. The list starts from head,
729-
* but we will shift to the place where start_block is,
730-
* then start from there, when looking for a reservable space.
730+
* We search the given range, rather than the whole reservation double
731+
* linked list, (start_block, last_block) to find a free region that is
732+
* of my size and has not been reserved.
731733
*
732-
* @sb: the super block.
734+
* @search_head is not necessarily the list head of the whole filesystem.
735+
* We have both head and @start_block to assist the search for the
736+
* reservable space. The list starts from head, but we will shift to
737+
* the place where start_block is, then start from there, when looking
738+
* for a reservable space.
733739
*
734-
* @start_block: the first block we consider to start the real search from
735-
*
736-
* @last_block:
737-
* the maximum block number that our goal reservable space
738-
* could start from. This is normally the last block in this
739-
* group. The search will end when we found the start of next
740-
* possible reservable space is out of this boundary.
741-
* This could handle the cross boundary reservation window
742-
* request.
743-
*
744-
* basically we search from the given range, rather than the whole
745-
* reservation double linked list, (start_block, last_block)
746-
* to find a free region that is of my size and has not
747-
* been reserved.
740+
* @last_block is normally the last block in this group. The search will end
741+
* when we found the start of next possible reservable space is out
742+
* of this boundary. This could handle the cross boundary reservation
743+
* window request.
748744
*
745+
* Return: -1 if we could not find a range of sufficient size. If we could,
746+
* return 0 and fill in @my_rsv with the range information.
749747
*/
750748
static int find_next_reservable_window(
751749
struct ext2_reserve_window_node *search_head,
@@ -833,41 +831,34 @@ static int find_next_reservable_window(
833831
}
834832

835833
/**
836-
* alloc_new_reservation()--allocate a new reservation window
837-
*
838-
* To make a new reservation, we search part of the filesystem
839-
* reservation list (the list that inside the group). We try to
840-
* allocate a new reservation window near the allocation goal,
841-
* or the beginning of the group, if there is no goal.
842-
*
843-
* We first find a reservable space after the goal, then from
844-
* there, we check the bitmap for the first free block after
845-
* it. If there is no free block until the end of group, then the
846-
* whole group is full, we failed. Otherwise, check if the free
847-
* block is inside the expected reservable space, if so, we
848-
* succeed.
849-
* If the first free block is outside the reservable space, then
850-
* start from the first free block, we search for next available
851-
* space, and go on.
834+
* alloc_new_reservation - Allocate a new reservation window.
835+
* @my_rsv: The reservation we're currently using.
836+
* @grp_goal: The goal block relative to the start of the group.
837+
* @sb: The super block.
838+
* @group: The group we are trying to allocate in.
839+
* @bitmap_bh: The block group block bitmap.
852840
*
853-
* on succeed, a new reservation will be found and inserted into the list
854-
* It contains at least one free block, and it does not overlap with other
855-
* reservation windows.
841+
* To make a new reservation, we search part of the filesystem reservation
842+
* list (the list inside the group). We try to allocate a new
843+
* reservation window near @grp_goal, or the beginning of the
844+
* group, if @grp_goal is negative.
856845
*
857-
* failed: we failed to find a reservation window in this group
846+
* We first find a reservable space after the goal, then from there,
847+
* we check the bitmap for the first free block after it. If there is
848+
* no free block until the end of group, then the whole group is full,
849+
* we failed. Otherwise, check if the free block is inside the expected
850+
* reservable space, if so, we succeed.
858851
*
859-
* @my_rsv: the reservation
852+
* If the first free block is outside the reservable space, then start
853+
* from the first free block, we search for next available space, and
854+
* go on.
860855
*
861-
* @grp_goal: The goal (group-relative). It is where the search for a
862-
* free reservable space should start from.
863-
* if we have a goal(goal >0 ), then start from there,
864-
* no goal(goal = -1), we start from the first block
865-
* of the group.
866-
*
867-
* @sb: the super block
868-
* @group: the group we are trying to allocate in
869-
* @bitmap_bh: the block group block bitmap
856+
* on succeed, a new reservation will be found and inserted into the
857+
* list. It contains at least one free block, and it does not overlap
858+
* with other reservation windows.
870859
*
860+
* Return: 0 on success, -1 if we failed to find a reservation window
861+
* in this group
871862
*/
872863
static int alloc_new_reservation(struct ext2_reserve_window_node *my_rsv,
873864
ext2_grpblk_t grp_goal, struct super_block *sb,
@@ -1131,8 +1122,13 @@ ext2_try_to_allocate_with_rsv(struct super_block *sb, unsigned int group,
11311122

11321123
if ((my_rsv->rsv_start > group_last_block) ||
11331124
(my_rsv->rsv_end < group_first_block)) {
1125+
ext2_error(sb, __func__,
1126+
"Reservation out of group %u range goal %d fsb[%lu,%lu] rsv[%lu, %lu]",
1127+
group, grp_goal, group_first_block,
1128+
group_last_block, my_rsv->rsv_start,
1129+
my_rsv->rsv_end);
11341130
rsv_window_dump(&EXT2_SB(sb)->s_rsv_window_root, 1);
1135-
BUG();
1131+
return -1;
11361132
}
11371133
ret = ext2_try_to_allocate(sb, group, bitmap_bh, grp_goal,
11381134
&num, &my_rsv->rsv_window);
@@ -1193,6 +1189,7 @@ int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
11931189
* @goal: given target block(filesystem wide)
11941190
* @count: target number of blocks to allocate
11951191
* @errp: error code
1192+
* @flags: allocate flags
11961193
*
11971194
* ext2_new_blocks uses a goal block to assist allocation. If the goal is
11981195
* free, or there is a free block within 32 blocks of the goal, that block
@@ -1202,7 +1199,7 @@ int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
12021199
* This function also updates quota and i_blocks field.
12031200
*/
12041201
ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
1205-
unsigned long *count, int *errp)
1202+
unsigned long *count, int *errp, unsigned int flags)
12061203
{
12071204
struct buffer_head *bitmap_bh = NULL;
12081205
struct buffer_head *gdp_bh;
@@ -1241,15 +1238,15 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
12411238
es = EXT2_SB(sb)->s_es;
12421239
ext2_debug("goal=%lu.\n", goal);
12431240
/*
1244-
* Allocate a block from reservation only when
1245-
* filesystem is mounted with reservation(default,-o reservation), and
1246-
* it's a regular file, and
1247-
* the desired window size is greater than 0 (One could use ioctl
1248-
* command EXT2_IOC_SETRSVSZ to set the window size to 0 to turn off
1249-
* reservation on that particular file)
1241+
* Allocate a block from reservation only when the filesystem is
1242+
* mounted with reservation(default,-o reservation), and it's a regular
1243+
* file, and the desired window size is greater than 0 (One could use
1244+
* ioctl command EXT2_IOC_SETRSVSZ to set the window size to 0 to turn
1245+
* off reservation on that particular file). Also do not use the
1246+
* reservation window if the caller asked us not to do it.
12501247
*/
12511248
block_i = EXT2_I(inode)->i_block_alloc_info;
1252-
if (block_i) {
1249+
if (!(flags & EXT2_ALLOC_NORESERVE) && block_i) {
12531250
windowsz = block_i->rsv_window_node.rsv_goal_size;
12541251
if (windowsz > 0)
12551252
my_rsv = &block_i->rsv_window_node;
@@ -1429,13 +1426,6 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
14291426
return 0;
14301427
}
14311428

1432-
ext2_fsblk_t ext2_new_block(struct inode *inode, unsigned long goal, int *errp)
1433-
{
1434-
unsigned long count = 1;
1435-
1436-
return ext2_new_blocks(inode, goal, &count, errp);
1437-
}
1438-
14391429
#ifdef EXT2FS_DEBUG
14401430

14411431
unsigned long ext2_count_free(struct buffer_head *map, unsigned int numchars)

fs/ext2/ext2.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ struct ext2_inode {
398398
#define EXT2_ERRORS_PANIC 3 /* Panic */
399399
#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
400400

401+
/*
402+
* Allocation flags
403+
*/
404+
#define EXT2_ALLOC_NORESERVE 0x1 /* Do not use reservation
405+
* window for allocation */
406+
401407
/*
402408
* Structure of the super block
403409
*/
@@ -695,13 +701,11 @@ static inline struct ext2_inode_info *EXT2_I(struct inode *inode)
695701
/* balloc.c */
696702
extern int ext2_bg_has_super(struct super_block *sb, int group);
697703
extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
698-
extern ext2_fsblk_t ext2_new_block(struct inode *, unsigned long, int *);
699-
extern ext2_fsblk_t ext2_new_blocks(struct inode *, unsigned long,
700-
unsigned long *, int *);
704+
extern ext2_fsblk_t ext2_new_blocks(struct inode *, ext2_fsblk_t,
705+
unsigned long *, int *, unsigned int);
701706
extern int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
702707
unsigned int count);
703-
extern void ext2_free_blocks (struct inode *, unsigned long,
704-
unsigned long);
708+
extern void ext2_free_blocks(struct inode *, ext2_fsblk_t, unsigned long);
705709
extern unsigned long ext2_count_free_blocks (struct super_block *);
706710
extern unsigned long ext2_count_dirs (struct super_block *);
707711
extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,

fs/ext2/ialloc.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
273273

274274
if ((parent == d_inode(sb->s_root)) ||
275275
(EXT2_I(parent)->i_flags & EXT2_TOPDIR_FL)) {
276-
struct ext2_group_desc *best_desc = NULL;
277276
int best_ndir = inodes_per_group;
278277
int best_group = -1;
279278

@@ -291,10 +290,8 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
291290
continue;
292291
best_group = group;
293292
best_ndir = le16_to_cpu(desc->bg_used_dirs_count);
294-
best_desc = desc;
295293
}
296294
if (best_group >= 0) {
297-
desc = best_desc;
298295
group = best_group;
299296
goto found;
300297
}

fs/ext2/inode.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,16 @@ ext2_blks_to_allocate(Indirect * branch, int k, unsigned long blks,
385385
}
386386

387387
/**
388-
* ext2_alloc_blocks: multiple allocate blocks needed for a branch
389-
* @indirect_blks: the number of blocks need to allocate for indirect
390-
* blocks
391-
* @blks: the number of blocks need to allocate for direct blocks
392-
* @new_blocks: on return it will store the new block numbers for
393-
* the indirect blocks(if needed) and the first direct block,
388+
* ext2_alloc_blocks: Allocate multiple blocks needed for a branch.
389+
* @inode: Owner.
390+
* @goal: Preferred place for allocation.
391+
* @indirect_blks: The number of blocks needed to allocate for indirect blocks.
392+
* @blks: The number of blocks need to allocate for direct blocks.
393+
* @new_blocks: On return it will store the new block numbers for
394+
* the indirect blocks(if needed) and the first direct block.
395+
* @err: Error pointer.
396+
*
397+
* Return: Number of blocks allocated.
394398
*/
395399
static int ext2_alloc_blocks(struct inode *inode,
396400
ext2_fsblk_t goal, int indirect_blks, int blks,
@@ -415,7 +419,7 @@ static int ext2_alloc_blocks(struct inode *inode,
415419
while (1) {
416420
count = target;
417421
/* allocating blocks for indirect blocks and direct blocks */
418-
current_block = ext2_new_blocks(inode,goal,&count,err);
422+
current_block = ext2_new_blocks(inode, goal, &count, err, 0);
419423
if (*err)
420424
goto failed_out;
421425

@@ -1082,8 +1086,8 @@ static Indirect *ext2_find_shared(struct inode *inode,
10821086
*/
10831087
static inline void ext2_free_data(struct inode *inode, __le32 *p, __le32 *q)
10841088
{
1085-
unsigned long block_to_free = 0, count = 0;
1086-
unsigned long nr;
1089+
ext2_fsblk_t block_to_free = 0, count = 0;
1090+
ext2_fsblk_t nr;
10871091

10881092
for ( ; p < q ; p++) {
10891093
nr = le32_to_cpu(*p);
@@ -1123,7 +1127,7 @@ static inline void ext2_free_data(struct inode *inode, __le32 *p, __le32 *q)
11231127
static void ext2_free_branches(struct inode *inode, __le32 *p, __le32 *q, int depth)
11241128
{
11251129
struct buffer_head * bh;
1126-
unsigned long nr;
1130+
ext2_fsblk_t nr;
11271131

11281132
if (depth--) {
11291133
int addr_per_block = EXT2_ADDR_PER_BLOCK(inode->i_sb);

fs/ext2/xattr.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,13 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
742742
/* We need to allocate a new block */
743743
ext2_fsblk_t goal = ext2_group_first_block_no(sb,
744744
EXT2_I(inode)->i_block_group);
745-
int block = ext2_new_block(inode, goal, &error);
745+
unsigned long count = 1;
746+
ext2_fsblk_t block = ext2_new_blocks(inode, goal,
747+
&count, &error,
748+
EXT2_ALLOC_NORESERVE);
746749
if (error)
747750
goto cleanup;
748-
ea_idebug(inode, "creating block %d", block);
751+
ea_idebug(inode, "creating block %lu", block);
749752

750753
new_bh = sb_getblk(sb, block);
751754
if (unlikely(!new_bh)) {

0 commit comments

Comments
 (0)