bcachefs: Fix out of bounds read in fs usage ioctl
authorDan Robertson <dan@dlrobertson.com>
Wed, 5 May 2021 11:09:43 +0000 (07:09 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:03 +0000 (17:09 -0400)
Fix a possible read out of bounds if bch2_ioctl_fs_usage is called when
replica_entries_bytes is set to a value that is smaller than the size
of bch_replicas_usage.

Signed-off-by: Dan Robertson <dan@dlrobertson.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/chardev.c

index b0cbbb70161d04957c96678c4c4ffbe87ab99b74..99f112072ae5208fbea24450cf2cfb07b57ef8e4 100644 (file)
@@ -414,7 +414,8 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c,
                struct bch_replicas_entry *src_e =
                        cpu_replicas_entry(&c->replicas, i);
 
-               if (replicas_usage_next(dst_e) > dst_end) {
+               /* check that we have enough space for one replicas entry */
+               if (dst_e + 1 > dst_end) {
                        ret = -ERANGE;
                        break;
                }