summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-05-20 09:13:57 +0200
committerKent Overstreet <kent.overstreet@linux.dev>2024-05-23 01:01:17 +0200
commit2ba24864d2f61b52210ba645ee5af1d0422a7ea9 (patch)
treeeba93e99ffddc7639eb8f7f9a29599db93d1d54a
parentbcachefs: Fix btree_trans leak in bch2_readahead() (diff)
downloadlinux-2ba24864d2f61b52210ba645ee5af1d0422a7ea9.tar.xz
linux-2ba24864d2f61b52210ba645ee5af1d0422a7ea9.zip
bcachefs: Fix stack oob in __bch2_encrypt_bio()
Reported-by: syzbot+fff6b0fb00259873576a@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/checksum.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/fs/bcachefs/checksum.c b/fs/bcachefs/checksum.c
index 4b3d6f0137f6..3bd3aba90d8f 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,