[PATCH v3] volume_id: volume_id_get_buffer with small FSes
Alyssa Ross
hi at alyssa.is
Sat May 27 14:47:26 UTC 2023
I was working with some very small ext4 filesystems, used for
overlaying on immutable VM/container images. If it's only desired to
overlay a single config file, these filesystems can be very small
indeed, and so ran afoul of this length check.
Since 4fc5ec56f ("device matching against UUIDs: do not try
floppies") (from 2009), floppy drives are skipped before this function
is even called. Reading from an unused loop device returns 0, so it
should be fine to drop the minimum length, and be happy with any read
as long as it returns at least one byte.
By initializing read_len to -1, we can handle both lseek() failing and
read_full() failing with the same check.
---
v2: http://lists.busybox.net/pipermail/busybox/2023-May/090340.html
My previous submission omitted the version number in the subject line,
and didn't actually include the updated commit message I referred to
in the changelog; apologies.
util-linux/volume_id/util.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c
index 061545fde..a5844c673 100644
--- a/util-linux/volume_id/util.c
+++ b/util-linux/volume_id/util.c
@@ -180,7 +180,7 @@ void *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len)
{
uint8_t *dst;
unsigned small_off;
- ssize_t read_len;
+ ssize_t read_len = -1;
dbg("get buffer off 0x%llx(%llu), len 0x%zx",
(unsigned long long) off, (unsigned long long) off, len);
@@ -237,13 +237,7 @@ void *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len)
dbg("requested 0x%x bytes, got 0x%x bytes",
(unsigned) len, (unsigned) read_len);
err:
- /* No filesystem can be this tiny. It's most likely
- * non-associated loop device, empty drive and so on.
- * Flag it, making it possible to short circuit future
- * accesses. Rationale:
- * users complained of slow blkid due to empty floppy drives.
- */
- if (off < 64*1024)
+ if (read_len <= 0)
id->error = 1;
/* id->seekbuf_len or id->sbbuf_len is wrong now! Fixing. */
volume_id_free_buffer(id);
base-commit: 6d9427420bab4ef756444fc8800dbf56d7dacf7d
--
2.37.1
More information about the busybox
mailing list