Skip to content

Commit 66fcf74

Browse files
committed
Merge tag 'for-6.2-rc7-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - explicitly initialize zlib work memory to fix a KCSAN warning - limit number of send clones by maximum memory allocated - limit device size extent in case it device shrink races with chunk allocation - raid56 fixes: - fix copy&paste error in RAID6 stripe recovery - make error bitmap update atomic * tag 'for-6.2-rc7-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: raid56: make error_bitmap update atomic btrfs: send: limit number of clones and allocated memory size btrfs: zlib: zero-initialize zlib workspace btrfs: limit device extents to the device size btrfs: raid56: fix stripes if vertical errors are found
2 parents d2d11f3 + a9ad4d8 commit 66fcf74

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

fs/btrfs/raid56.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,12 +1426,20 @@ static void rbio_update_error_bitmap(struct btrfs_raid_bio *rbio, struct bio *bi
14261426
u32 bio_size = 0;
14271427
struct bio_vec *bvec;
14281428
struct bvec_iter_all iter_all;
1429+
int i;
14291430

14301431
bio_for_each_segment_all(bvec, bio, iter_all)
14311432
bio_size += bvec->bv_len;
14321433

1433-
bitmap_set(rbio->error_bitmap, total_sector_nr,
1434-
bio_size >> rbio->bioc->fs_info->sectorsize_bits);
1434+
/*
1435+
* Since we can have multiple bios touching the error_bitmap, we cannot
1436+
* call bitmap_set() without protection.
1437+
*
1438+
* Instead use set_bit() for each bit, as set_bit() itself is atomic.
1439+
*/
1440+
for (i = total_sector_nr; i < total_sector_nr +
1441+
(bio_size >> rbio->bioc->fs_info->sectorsize_bits); i++)
1442+
set_bit(i, rbio->error_bitmap);
14351443
}
14361444

14371445
/* Verify the data sectors at read time. */
@@ -1886,7 +1894,7 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
18861894
sector->uptodate = 1;
18871895
}
18881896
if (failb >= 0) {
1889-
ret = verify_one_sector(rbio, faila, sector_nr);
1897+
ret = verify_one_sector(rbio, failb, sector_nr);
18901898
if (ret < 0)
18911899
goto cleanup;
18921900

fs/btrfs/send.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8073,10 +8073,10 @@ long btrfs_ioctl_send(struct inode *inode, struct btrfs_ioctl_send_args *arg)
80738073
/*
80748074
* Check that we don't overflow at later allocations, we request
80758075
* clone_sources_count + 1 items, and compare to unsigned long inside
8076-
* access_ok.
8076+
* access_ok. Also set an upper limit for allocation size so this can't
8077+
* easily exhaust memory. Max number of clone sources is about 200K.
80778078
*/
8078-
if (arg->clone_sources_count >
8079-
ULONG_MAX / sizeof(struct clone_root) - 1) {
8079+
if (arg->clone_sources_count > SZ_8M / sizeof(struct clone_root)) {
80808080
ret = -EINVAL;
80818081
goto out;
80828082
}

fs/btrfs/volumes.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ static int find_free_dev_extent_start(struct btrfs_device *device,
16001600
if (ret < 0)
16011601
goto out;
16021602

1603-
while (1) {
1603+
while (search_start < search_end) {
16041604
l = path->nodes[0];
16051605
slot = path->slots[0];
16061606
if (slot >= btrfs_header_nritems(l)) {
@@ -1623,6 +1623,9 @@ static int find_free_dev_extent_start(struct btrfs_device *device,
16231623
if (key.type != BTRFS_DEV_EXTENT_KEY)
16241624
goto next;
16251625

1626+
if (key.offset > search_end)
1627+
break;
1628+
16261629
if (key.offset > search_start) {
16271630
hole_size = key.offset - search_start;
16281631
dev_extent_hole_check(device, &search_start, &hole_size,
@@ -1683,6 +1686,7 @@ static int find_free_dev_extent_start(struct btrfs_device *device,
16831686
else
16841687
ret = 0;
16851688

1689+
ASSERT(max_hole_start + max_hole_size <= search_end);
16861690
out:
16871691
btrfs_free_path(path);
16881692
*start = max_hole_start;

fs/btrfs/zlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct list_head *zlib_alloc_workspace(unsigned int level)
6363

6464
workspacesize = max(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL),
6565
zlib_inflate_workspacesize());
66-
workspace->strm.workspace = kvmalloc(workspacesize, GFP_KERNEL);
66+
workspace->strm.workspace = kvzalloc(workspacesize, GFP_KERNEL);
6767
workspace->level = level;
6868
workspace->buf = NULL;
6969
/*

0 commit comments

Comments
 (0)