bcachefs: Fix stack oob in __bch2_encrypt_bio()
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 20 May 2024 07:13:57 +0000 (03:13 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 22 May 2024 23:01:17 +0000 (19:01 -0400)
Reported-by: syzbot+fff6b0fb00259873576a@syzkaller.appspotmail.com
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/checksum.c

index 4b3d6f0137f658a4f6ad5277048c0312683fc35d..3bd3aba90d8f5c51c0d6853f9f1849f5b4f334dd 100644 (file)
@@ -352,8 +352,12 @@ int __bch2_encrypt_bio(struct bch_fs *c, unsigned type,
                bytes += bv.bv_len;
        }
 
-       sg_mark_end(sg - 1);
-       return do_encrypt_sg(c->chacha20, nonce, sgl, bytes);
+       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,