Commit c40b1994 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'bcachefs-2024-05-24' of https://evilpiepirate.org/git/bcachefs

Pull bcachefs fixes from Kent Overstreet:
 "Nothing exciting, just syzbot fixes (except for the one
  FMODE_CAN_ODIRECT patch).

  Looks like syzbot reports have slowed down; this is all catch up from
  two weeks of conferences.

  Next hardening project is using Thomas's error injection tooling to
  torture test repair"

* tag 'bcachefs-2024-05-24' of https://evilpiepirate.org/git/bcachefs:
  bcachefs: Fix race path in bch2_inode_insert()
  bcachefs: Ensure we're RW before journalling
  bcachefs: Fix shutdown ordering
  bcachefs: Fix unsafety in bch2_dirent_name_bytes()
  bcachefs: Fix stack oob in __bch2_encrypt_bio()
  bcachefs: Fix btree_trans leak in bch2_readahead()
  bcachefs: Fix bogus verify_replicas_entry() assert
  bcachefs: Check for subvolues with bogus snapshot/inode fields
  bcachefs: bch2_checksum() returns 0 for unknown checksum type
  bcachefs: Fix bch2_alloc_ciphers()
  bcachefs: Add missing guard in bch2_snapshot_has_children()
  bcachefs: Fix missing parens in drop_locks_do()
  bcachefs: Improve bch2_assert_pos_locked()
  bcachefs: Fix shift overflows in replicas.c
  bcachefs: Fix shift overflow in btree_lost_data()
  bcachefs: Fix ref in trans_mark_dev_sbs() error path
  bcachefs: set FMODE_CAN_ODIRECT instead of a dummy direct_IO method
  bcachefs: Fix rcu splat in check_fix_ptrs()
parents 9ea370f3 d93ff5fa
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1555,6 +1555,12 @@ enum btree_id {
	BTREE_ID_NR
};

/*
 * Maximum number of btrees that we will _ever_ have under the current scheme,
 * where we refer to them with bitfields
 */
#define BTREE_ID_NR_MAX		64

static inline bool btree_id_is_alloc(enum btree_id id)
{
	switch (id) {
+2 −0
Original line number Diff line number Diff line
@@ -332,6 +332,8 @@ static int bch2_btree_iter_verify_ret(struct btree_iter *iter, struct bkey_s_c k
void bch2_assert_pos_locked(struct btree_trans *trans, enum btree_id id,
			    struct bpos pos, bool key_cache)
{
	bch2_trans_verify_not_unlocked(trans);

	struct btree_path *path;
	struct trans_for_each_path_inorder_iter iter;
	struct printbuf buf = PRINTBUF;
+1 −1
Original line number Diff line number Diff line
@@ -838,7 +838,7 @@ __bch2_btree_iter_peek_and_restart(struct btree_trans *trans,
#define drop_locks_do(_trans, _do)					\
({									\
	bch2_trans_unlock(_trans);					\
	_do ?: bch2_trans_relock(_trans);				\
	(_do) ?: bch2_trans_relock(_trans);				\
})

#define allocate_dropping_locks_errcode(_trans, _do)			\
+7 −6
Original line number Diff line number Diff line
@@ -479,9 +479,8 @@ int bch2_check_fix_ptrs(struct btree_trans *trans,

	percpu_down_read(&c->mark_lock);

	rcu_read_lock();
	bkey_for_each_ptr_decode(k.k, ptrs_c, p, entry_c) {
		struct bch_dev *ca = bch2_dev_rcu(c, p.ptr.dev);
		struct bch_dev *ca = bch2_dev_tryget(c, p.ptr.dev);
		if (!ca) {
			if (fsck_err(c, ptr_to_invalid_device,
				     "pointer to missing device %u\n"
@@ -558,7 +557,7 @@ int bch2_check_fix_ptrs(struct btree_trans *trans,
			do_update = true;

		if (data_type != BCH_DATA_btree && p.ptr.gen != g->gen)
			continue;
			goto next;

		if (fsck_err_on(bucket_data_type_mismatch(g->data_type, data_type),
				c, ptr_bucket_data_type_mismatch,
@@ -601,8 +600,9 @@ int bch2_check_fix_ptrs(struct btree_trans *trans,
					 bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
				do_update = true;
		}
next:
		bch2_dev_put(ca);
	}
	rcu_read_unlock();

	if (do_update) {
		if (flags & BTREE_TRIGGER_is_root) {
@@ -638,9 +638,10 @@ int bch2_check_fix_ptrs(struct btree_trans *trans,
		} else {
			struct bkey_ptrs ptrs;
			union bch_extent_entry *entry;

			rcu_read_lock();
restart_drop_ptrs:
			ptrs = bch2_bkey_ptrs(bkey_i_to_s(new));
			rcu_read_lock();
			bkey_for_each_ptr_decode(bkey_i_to_s(new).k, ptrs, p, entry) {
				struct bch_dev *ca = bch2_dev_rcu(c, p.ptr.dev);
				struct bucket *g = PTR_GC_BUCKET(ca, &p.ptr);
@@ -1464,7 +1465,7 @@ int bch2_trans_mark_dev_sbs_flags(struct bch_fs *c,
	for_each_online_member(c, ca) {
		int ret = bch2_trans_mark_dev_sb(c, ca, flags);
		if (ret) {
			bch2_dev_put(ca);
			percpu_ref_put(&ca->io_ref);
			return ret;
		}
	}
+21 −16
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ struct bch_csum bch2_checksum(struct bch_fs *c, unsigned type,
		return ret;
	}
	default:
		BUG();
		return (struct bch_csum) {};
	}
}

@@ -307,7 +307,7 @@ static struct bch_csum __bch2_checksum_bio(struct bch_fs *c, unsigned type,
		return ret;
	}
	default:
		BUG();
		return (struct bch_csum) {};
	}
}

@@ -352,10 +352,14 @@ int __bch2_encrypt_bio(struct bch_fs *c, unsigned type,
		bytes += bv.bv_len;
	}

	if (sg != sgl) {
		sg_mark_end(sg - 1);
		return do_encrypt_sg(c->chacha20, nonce, sgl, bytes);
	}

	return ret;
}

struct bch_csum bch2_checksum_merge(unsigned type, struct bch_csum a,
				    struct bch_csum b, size_t b_len)
{
@@ -648,26 +652,26 @@ int bch2_decrypt_sb_key(struct bch_fs *c,

static int bch2_alloc_ciphers(struct bch_fs *c)
{
	int ret;

	if (!c->chacha20)
		c->chacha20 = crypto_alloc_sync_skcipher("chacha20", 0, 0);
	ret = PTR_ERR_OR_ZERO(c->chacha20);
	if (c->chacha20)
		return 0;

	struct crypto_sync_skcipher *chacha20 = crypto_alloc_sync_skcipher("chacha20", 0, 0);
	int ret = PTR_ERR_OR_ZERO(chacha20);
	if (ret) {
		bch_err(c, "error requesting chacha20 module: %s", bch2_err_str(ret));
		return ret;
	}

	if (!c->poly1305)
		c->poly1305 = crypto_alloc_shash("poly1305", 0, 0);
	ret = PTR_ERR_OR_ZERO(c->poly1305);

	struct crypto_shash *poly1305 = crypto_alloc_shash("poly1305", 0, 0);
	ret = PTR_ERR_OR_ZERO(poly1305);
	if (ret) {
		bch_err(c, "error requesting poly1305 module: %s", bch2_err_str(ret));
		crypto_free_sync_skcipher(chacha20);
		return ret;
	}

	c->chacha20	= chacha20;
	c->poly1305	= poly1305;
	return 0;
}

@@ -762,11 +766,11 @@ int bch2_enable_encryption(struct bch_fs *c, bool keyed)

void bch2_fs_encryption_exit(struct bch_fs *c)
{
	if (!IS_ERR_OR_NULL(c->poly1305))
	if (c->poly1305)
		crypto_free_shash(c->poly1305);
	if (!IS_ERR_OR_NULL(c->chacha20))
	if (c->chacha20)
		crypto_free_sync_skcipher(c->chacha20);
	if (!IS_ERR_OR_NULL(c->sha256))
	if (c->sha256)
		crypto_free_shash(c->sha256);
}

@@ -779,6 +783,7 @@ int bch2_fs_encryption_init(struct bch_fs *c)
	c->sha256 = crypto_alloc_shash("sha256", 0, 0);
	ret = PTR_ERR_OR_ZERO(c->sha256);
	if (ret) {
		c->sha256 = NULL;
		bch_err(c, "error requesting sha256 module: %s", bch2_err_str(ret));
		goto out;
	}
Loading