[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] volume_id: volume_id_get_buffer with small FSes
From:       Alyssa Ross <hi () alyssa ! is>
Date:       2023-05-27 12:02:50
Message-ID: 20230527120249.826781-1-hi () alyssa ! is
[Download RAW message or body]

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.

I tested both the cases mentioned in the comments — an empty floppy
drive, and an unused loop device.  Reading from an empty floppy drive
is ENXIO, and 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.
---

v1: http://lists.busybox.net/pipermail/busybox/2022-May/089740.html

Only change since v1 is updating the commit message to note that
floppies don't even take this code path any more.

 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

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic