summaryrefslogtreecommitdiff
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c44
1 files changed, 39 insertions, 5 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index a11fcc9e9f50..f643a0520872 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2012,6 +2012,13 @@ static int can_nocow_file_extent(struct btrfs_path *path,
*/
csum_root = btrfs_csum_root(root->fs_info, io_start);
+ if (unlikely(!csum_root)) {
+ btrfs_err(root->fs_info,
+ "missing csum root for extent at bytenr %llu", io_start);
+ ret = -EUCLEAN;
+ goto out;
+ }
+
ret = btrfs_lookup_csums_list(csum_root, io_start,
io_start + args->file_extent.num_bytes - 1,
NULL, nowait);
@@ -2749,10 +2756,17 @@ static int add_pending_csums(struct btrfs_trans_handle *trans,
int ret;
list_for_each_entry(sum, list, list) {
- trans->adding_csums = true;
- if (!csum_root)
+ if (!csum_root) {
csum_root = btrfs_csum_root(trans->fs_info,
sum->logical);
+ if (unlikely(!csum_root)) {
+ btrfs_err(trans->fs_info,
+ "missing csum root for extent at bytenr %llu",
+ sum->logical);
+ return -EUCLEAN;
+ }
+ }
+ trans->adding_csums = true;
ret = btrfs_csum_file_blocks(trans, csum_root, sum);
trans->adding_csums = false;
if (ret)
@@ -6612,6 +6626,25 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
int ret;
bool xa_reserved = false;
+ if (!args->orphan && !args->subvol) {
+ /*
+ * Before anything else, check if we can add the name to the
+ * parent directory. We want to avoid a dir item overflow in
+ * case we have an existing dir item due to existing name
+ * hash collisions. We do this check here before we call
+ * btrfs_add_link() down below so that we can avoid a
+ * transaction abort (which could be exploited by malicious
+ * users).
+ *
+ * For subvolumes we already do this in btrfs_mksubvol().
+ */
+ ret = btrfs_check_dir_item_collision(BTRFS_I(dir)->root,
+ btrfs_ino(BTRFS_I(dir)),
+ name);
+ if (ret < 0)
+ return ret;
+ }
+
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
@@ -9855,6 +9888,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
int compression;
size_t orig_count;
const u32 min_folio_size = btrfs_min_folio_size(fs_info);
+ const u32 blocksize = fs_info->sectorsize;
u64 start, end;
u64 num_bytes, ram_bytes, disk_num_bytes;
struct btrfs_key ins;
@@ -9965,9 +9999,9 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
ret = -EFAULT;
goto out_cb;
}
- if (bytes < min_folio_size)
- folio_zero_range(folio, bytes, min_folio_size - bytes);
- ret = bio_add_folio(&cb->bbio.bio, folio, folio_size(folio), 0);
+ if (!IS_ALIGNED(bytes, blocksize))
+ folio_zero_range(folio, bytes, round_up(bytes, blocksize) - bytes);
+ ret = bio_add_folio(&cb->bbio.bio, folio, round_up(bytes, blocksize), 0);
if (unlikely(!ret)) {
folio_put(folio);
ret = -EINVAL;