From: Kent Overstreet Date: Mon, 20 May 2024 07:13:57 +0000 (-0400) Subject: bcachefs: Fix stack oob in __bch2_encrypt_bio() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=2ba24864d2f61b52210ba645ee5af1d0422a7ea9;p=linux.git bcachefs: Fix stack oob in __bch2_encrypt_bio() Reported-by: syzbot+fff6b0fb00259873576a@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/checksum.c b/fs/bcachefs/checksum.c index 4b3d6f0137f65..3bd3aba90d8f5 100644 --- a/fs/bcachefs/checksum.c +++ b/fs/bcachefs/checksum.c @@ -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,