bcachefs: Fix a transaction path overflow
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 22 Oct 2021 21:33:38 +0000 (17:33 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:14 +0000 (17:09 -0400)
readdir() in a directory with many subvolumes could overflow transaction
paths - this is a simple hack around the issue.

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

index 2ab9cbaf71f2f308a9a3e8ee72ede8ae26303621..6be3ec4ec4a63709a1299941fc237c7a434a52aa 100644 (file)
@@ -529,6 +529,15 @@ retry:
                              vfs_d_type(dirent.v->d_type)))
                        break;
                ctx->pos = dirent.k->p.offset + 1;
+
+               /*
+                * read_target looks up subvolumes, we can overflow paths if the
+                * directory has many subvolumes in it
+                */
+               if (hweight64(trans.paths_allocated) > BTREE_ITER_MAX / 2) {
+                       ret = -EINTR;
+                       break;
+               }
        }
        bch2_trans_iter_exit(&trans, &iter);
 err: