Blame SOURCES/e2fsprogs-1.45.6-filefrag-handle-invalid-st_dev-and-blksize-cases.patch

a77133
From 381bc5d98b2a8a65b1f559e31e67361a761aefee Mon Sep 17 00:00:00 2001
a77133
From: Luis Henriques <lhenriques@suse.de>
a77133
Date: Wed, 28 Oct 2020 15:55:50 +0000
a77133
Subject: [PATCH 14/46] filefrag: handle invalid st_dev and blksize cases
a77133
Content-Type: text/plain
a77133
a77133
It is possible to crash filefrag with a "Floating point exception" in
a77133
two different scenarios:
a77133
a77133
1. When fstat() returns a device ID set to 0
a77133
2. When FIGETBSZ ioctl returns a blocksize of 0
a77133
a77133
In both scenarios a divide-by-zero will occur in frag_report() because
a77133
variable blksize will be set to zero.
a77133
a77133
I've managed to trigger this crash with an old CephFS kernel client,
a77133
using xfstest generic/519.  The first scenario has been fixed by kernel
a77133
commit 75c9627efb72 ("ceph: map snapid to anonymous bdev ID").  The
a77133
second scenario is also fixed with commit 8f97d1e99149 ("vfs: fix
a77133
FIGETBSZ ioctl on an overlayfs file").
a77133
a77133
However, it is desirable to handle these two scenarios gracefully by
a77133
checking these conditions explicitly.
a77133
a77133
Signed-off-by: Luis Henriques <lhenriques@suse.de>
a77133
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
a77133
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
a77133
---
a77133
 misc/filefrag.c | 4 ++--
a77133
 1 file changed, 2 insertions(+), 2 deletions(-)
a77133
a77133
diff --git a/misc/filefrag.c b/misc/filefrag.c
a77133
index 032535f3..a5b9bfe9 100644
a77133
--- a/misc/filefrag.c
a77133
+++ b/misc/filefrag.c
a77133
@@ -418,13 +418,13 @@ static int frag_report(const char *filename)
a77133
 		goto out_close;
a77133
 	}
a77133
 
a77133
-	if (last_device != st.st_dev) {
a77133
+	if ((last_device != st.st_dev) || !st.st_dev) {
a77133
 		if (fstatfs(fd, &fsinfo) < 0) {
a77133
 			rc = -errno;
a77133
 			perror("fstatfs");
a77133
 			goto out_close;
a77133
 		}
a77133
-		if (ioctl(fd, FIGETBSZ, &blksize) < 0)
a77133
+		if ((ioctl(fd, FIGETBSZ, &blksize) < 0) || !blksize)
a77133
 			blksize = fsinfo.f_bsize;
a77133
 		if (verbose)
a77133
 			printf("Filesystem type is: %lx\n",
a77133
-- 
a77133
2.35.1
a77133