Skip to contentSkip to conversation

erofs-utils: lib: fix global-buffer-overflow due to invalid device

PATCH In review Gao Xiang 3 participants 4 messages Aug 8, 2024 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: lib: fix global-buffer-overflow due to invalid device

Fuzzer generates an image with crafted chunks of some invalid device. Also refine the printed message of EOD.

---
 lib/io.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/io.c +6 -1
index 6bfae69..fbeff03 100644
@@ -342,6 +342,10 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id,
 	ssize_t read;
 
 	if (device_id) {
+		if (device_id >= sbi->nblobs) {
+			erofs_err("invalid device id %u", device_id);
+			return -EIO;
+		}
 		read = erofs_io_pread(&((struct erofs_vfile) {
 				.fd = sbi->blobfd[device_id - 1],
 			}), buf, offset, len);
@@ -352,7 +356,8 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id,
 	if (read < 0)
 		return read;
 	if (read < len) {
-		erofs_info("reach EOF of device, pading with zeroes");
+		erofs_info("reach EOF of device @ %llu, pading with zeroes",
+			   offset | 0ULL);
 		memset(buf + read, 0, len - read);
 	}
 	return 0;
Signature · 1 line
2.43.5
Reviewed-by Sandeep Dhavale on v1 1/1
#1 lore raw
Quoted 27 lines · Gao Xiang

Fuzzer generates an image with crafted chunks of some invalid device. Also refine the printed message of EOD.

---
 lib/io.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/io.c +4 -0
index 6bfae69..fbeff03 100644
@@ -342,6 +342,10 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id,
        ssize_t read;
 
        if (device_id) {
+               if (device_id >= sbi->nblobs) {
+                       erofs_err("invalid device id %u", device_id);
+                       return -EIO;
+               }
                read = erofs_io_pread(&((struct erofs_vfile) {
                                .fd = sbi->blobfd[device_id - 1],
                        }), buf, offset, len);

lib/io.c ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id, · line 360

Quoted 6 lines
lib/io.c +2 -1
@@ -352,7 +356,8 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id,
        if (read < 0)
                return read;
        if (read < len) {
-               erofs_info("reach EOF of device, pading with zeroes");
+               erofs_info("reach EOF of device @ %llu, pading with zeroes",
+                          offset | 0ULL);

nit: typo carried over from previous log. s/pading/padding

Quoted 6 lines
lib/io.c +0 -1
                memset(buf + read, 0, len - read);
        }
        return 0;
--

2.43.5

Thanks,
Sandeep.

#2 lore raw

Hi Sandeep,

Quoted 19 lines · Sandeep Dhavale via Linux-erofs
Quoted 18 lines · Gao Xiang

Fuzzer generates an image with crafted chunks of some invalid device. Also refine the printed message of EOD.

---
 lib/io.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/io.c +0 -0
index 6bfae69..fbeff03 100644
@@ -342,6 +342,10 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id,
        ssize_t read;
 
Quoted 16 lines
Quoted 9 lines
lib/io.c +4 -0
        if (device_id) {
+               if (device_id >= sbi->nblobs) {
+                       erofs_err("invalid device id %u", device_id);
+                       return -EIO;
+               }
                read = erofs_io_pread(&((struct erofs_vfile) {
                                .fd = sbi->blobfd[device_id - 1],
                        }), buf, offset, len);

lib/io.c ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id, · line 360

Quoted 6 lines
lib/io.c +2 -1
@@ -352,7 +356,8 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id,
        if (read < 0)
                return read;
        if (read < len) {
-               erofs_info("reach EOF of device, pading with zeroes");
+               erofs_info("reach EOF of device @ %llu, pading with zeroes",
+                          offset | 0ULL);

nit: typo carried over from previous log. s/pading/padding

Thanks for catching this!

Quoted 9 lines
Quoted 7 lines
lib/io.c +0 -1
                memset(buf + read, 0, len - read);
        }
        return 0;
--

2.43.5

I'm about to releasing erofs-utils 1.8 today (it already takes much long time than expected, I don't want to hold it anymore), so the code is freezed for now.

I will tag v1.8 soon, and write an announcement mail hours later.

Thanks,
Gao Xiang

Quoted 3 lines

Thanks,
Sandeep.

#3 lore raw
Quoted 50 lines · Gao Xiang

Hi Sandeep,

Quoted 19 lines · Sandeep Dhavale via Linux-erofs
Quoted 18 lines · Gao Xiang

Fuzzer generates an image with crafted chunks of some invalid device. Also refine the printed message of EOD.

---
 lib/io.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/io.c +0 -0
index 6bfae69..fbeff03 100644
@@ -342,6 +342,10 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id,
        ssize_t read;
 
Quoted 16 lines
Quoted 9 lines
lib/io.c +4 -0
        if (device_id) {
+               if (device_id >= sbi->nblobs) {
+                       erofs_err("invalid device id %u", device_id);
+                       return -EIO;
+               }
                read = erofs_io_pread(&((struct erofs_vfile) {
                                .fd = sbi->blobfd[device_id - 1],
                        }), buf, offset, len);

lib/io.c ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id, · line 360

Quoted 6 lines
lib/io.c +2 -1
@@ -352,7 +356,8 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id,
        if (read < 0)
                return read;
        if (read < len) {
-               erofs_info("reach EOF of device, pading with zeroes");
+               erofs_info("reach EOF of device @ %llu, pading with zeroes",
+                          offset | 0ULL);

nit: typo carried over from previous log. s/pading/padding

Thanks for catching this!

Quoted 8 lines
Quoted 7 lines
lib/io.c +0 -1
                memset(buf + read, 0, len - read);
        }
        return 0;
--

2.43.5

Quoted 6 lines
Quoted 1 line

I'm about to releasing erofs-utils 1.8 today (it already takes much long time than expected, I don't want to hold it anymore), so the code is freezed for now.

Hi Gao,
No problem. Just caught my eyes, it's only cosmetic anyways.

Quoted 2 lines

I will tag v1.8 soon, and write an announcement mail hours later.

Thank you!

Regards,
Sandeep.

Quoted 6 lines

Thanks,
Gao Xiang

Quoted 3 lines

Thanks,
Sandeep.