]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: Fix for bch2_bkey_pack_pos() not initializing len/version fields
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 17 May 2021 20:43:30 +0000 (16:43 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:03 +0000 (17:09 -0400)
This bug led to push_whiteout() generating whiteouts that failed
bch2_bkey_invalid() due to nonzero length fields - oops.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/bkey.c

index a0379f980f7e806556da76ec246601af8f89163f..5de88a93f33fe5ca7dabe9c73a175e9f55bef6f5 100644 (file)
@@ -446,8 +446,15 @@ enum bkey_pack_pos_ret bch2_bkey_pack_pos_lossy(struct bkey_packed *out,
        struct bpos orig = in;
 #endif
        bool exact = true;
+       unsigned i;
 
-       *w = 0;
+       /*
+        * bch2_bkey_pack_key() will write to all of f->key_u64s, minus the 3
+        * byte header, but pack_pos() won't if the len/version fields are big
+        * enough - we need to make sure to zero them out:
+        */
+       for (i = 0; i < f->key_u64s; i++)
+               w[i] = 0;
 
        if (unlikely(in.snapshot <
                     le64_to_cpu(f->field_offset[BKEY_FIELD_SNAPSHOT]))) {