aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Bright <dab@FreeBSD.org>2021-05-24 17:12:15 +0000
committerDavid Bright <dab@FreeBSD.org>2021-06-09 16:15:33 +0000
commit80a5d786a3cdee6b6d2dbf6c2d8037a19d2fd9be (patch)
tree83d90f3782b5a2254ab2a751ab6d114d15e15782
parentf29323c94f5874f10d440dc43380ff17fb39d44f (diff)
downloadsrc-80a5d786a3cdee6b6d2dbf6c2d8037a19d2fd9be.tar.gz
src-80a5d786a3cdee6b6d2dbf6c2d8037a19d2fd9be.zip
libsa: Fix infinite loop in bzipfs & gzipfs
A bug in the loader's bzipfs & gzipfs filesystems caused compressed kernel and modules not to work on EFI systems with a veriexec-enabled loader. Since the size of files in these filesystems are not known _a priori_ `stat` would initialize the size to -1 and the loader would then hang in an infinite loop while trying to seek (read) to the end of file since the loop termination condition compares the current offset to that negative target position. Sponsored by: Dell EMC Isilon (cherry picked from commit 3df4c387d2e3ca4c2391fb837540b048f60a11c2)
-rw-r--r--stand/libsa/bzipfs.c3
-rw-r--r--stand/libsa/gzipfs.c3
2 files changed, 6 insertions, 0 deletions
diff --git a/stand/libsa/bzipfs.c b/stand/libsa/bzipfs.c
index 47380ae72e5e..bb67bda2aa19 100644
--- a/stand/libsa/bzipfs.c
+++ b/stand/libsa/bzipfs.c
@@ -340,6 +340,9 @@ bzf_seek(struct open_file *f, off_t offset, int where)
target - bzf->bzf_bzstream.total_out_lo32), NULL);
if (errno)
return(-1);
+ /* Break out of loop if end of file has been reached. */
+ if (bzf->bzf_endseen)
+ break;
}
/* This is where we are (be honest if we overshot) */
return(bzf->bzf_bzstream.total_out_lo32);
diff --git a/stand/libsa/gzipfs.c b/stand/libsa/gzipfs.c
index 39e2f98eb1e0..8154b0f95a9a 100644
--- a/stand/libsa/gzipfs.c
+++ b/stand/libsa/gzipfs.c
@@ -315,6 +315,9 @@ zf_seek(struct open_file *f, off_t offset, int where)
target - zf->zf_zstream.total_out), NULL);
if (errno)
return(-1);
+ /* Break out of loop if end of file has been reached. */
+ if (zf->zf_endseen)
+ break;
}
/* This is where we are (be honest if we overshot) */
return(zf->zf_zstream.total_out);