|
Anton Arapov |
0a7886 |
From c081fa410e7c466df4b3b257e7b974b71fb7f250 Mon Sep 17 00:00:00 2001
|
|
Anton Arapov |
0a7886 |
From: Jean Delvare <jdelvare@suse.de>
|
|
Anton Arapov |
0a7886 |
Date: Wed, 14 Oct 2015 14:37:04 +0200
|
|
Anton Arapov |
0a7886 |
Subject: [PATCH 2/9] Avoid SIGBUS on mmap failure
|
|
Anton Arapov |
0a7886 |
|
|
Anton Arapov |
0a7886 |
mmap will fail with SIGBUS if trying to map a non-existent portion of
|
|
Anton Arapov |
0a7886 |
a file. While this should never happen with /dev/mem, it can happen if
|
|
Anton Arapov |
0a7886 |
passing a regular file with option -d. While people should no longer
|
|
Anton Arapov |
0a7886 |
do that, failure gracefully seems better than crashing. So check for
|
|
Anton Arapov |
0a7886 |
the file size before calling mmap.
|
|
Anton Arapov |
0a7886 |
|
|
Anton Arapov |
0a7886 |
This closes bug #46066:
|
|
Anton Arapov |
0a7886 |
http://savannah.nongnu.org/bugs/?46066
|
|
Anton Arapov |
0a7886 |
---
|
|
Anton Arapov |
0a7886 |
CHANGELOG | 6 ++++++
|
|
Anton Arapov |
0a7886 |
util.c | 21 +++++++++++++++++++++
|
|
Anton Arapov |
0a7886 |
2 files changed, 27 insertions(+)
|
|
Anton Arapov |
0a7886 |
|
|
Anton Arapov |
0a7886 |
diff --git a/CHANGELOG b/CHANGELOG
|
|
Anton Arapov |
0a7886 |
index 42d815c..aa1c28f 100644
|
|
Anton Arapov |
0a7886 |
--- a/CHANGELOG
|
|
Anton Arapov |
0a7886 |
+++ b/CHANGELOG
|
|
Anton Arapov |
0a7886 |
@@ -1,3 +1,9 @@
|
|
Anton Arapov |
0a7886 |
+2015-10-14 Jean Delvare <jdelvare@suse.de>
|
|
Anton Arapov |
0a7886 |
+
|
|
Anton Arapov |
0a7886 |
+ * util.c: Avoid SIGBUS on mmap failure.
|
|
Anton Arapov |
0a7886 |
+ This fixes Savannah bug #46066:
|
|
Anton Arapov |
0a7886 |
+ https://savannah.nongnu.org/bugs/?46066
|
|
Anton Arapov |
0a7886 |
+
|
|
Anton Arapov |
0a7886 |
2015-10-01 Roy Franz <roy.franz@linaro.org>
|
|
Anton Arapov |
0a7886 |
|
|
Anton Arapov |
0a7886 |
* dmiopt.c: Add "--no-sysfs" option description to -h output.
|
|
Anton Arapov |
0a7886 |
diff --git a/util.c b/util.c
|
|
Anton Arapov |
0a7886 |
index 8cafe5c..5795d02 100644
|
|
Anton Arapov |
0a7886 |
--- a/util.c
|
|
Anton Arapov |
0a7886 |
+++ b/util.c
|
|
Anton Arapov |
0a7886 |
@@ -152,6 +152,7 @@ void *mem_chunk(off_t base, size_t len, const char *devmem)
|
|
Anton Arapov |
0a7886 |
void *p;
|
|
Anton Arapov |
0a7886 |
int fd;
|
|
Anton Arapov |
0a7886 |
#ifdef USE_MMAP
|
|
Anton Arapov |
0a7886 |
+ struct stat statbuf;
|
|
Anton Arapov |
0a7886 |
off_t mmoffset;
|
|
Anton Arapov |
0a7886 |
void *mmp;
|
|
Anton Arapov |
0a7886 |
#endif
|
|
Anton Arapov |
0a7886 |
@@ -169,6 +170,26 @@ void *mem_chunk(off_t base, size_t len, const char *devmem)
|
|
Anton Arapov |
0a7886 |
}
|
|
Anton Arapov |
0a7886 |
|
|
Anton Arapov |
0a7886 |
#ifdef USE_MMAP
|
|
Anton Arapov |
0a7886 |
+ if (fstat(fd, &statbuf) == -1)
|
|
Anton Arapov |
0a7886 |
+ {
|
|
Anton Arapov |
0a7886 |
+ fprintf(stderr, "%s: ", devmem);
|
|
Anton Arapov |
0a7886 |
+ perror("stat");
|
|
Anton Arapov |
0a7886 |
+ free(p);
|
|
Anton Arapov |
0a7886 |
+ return NULL;
|
|
Anton Arapov |
0a7886 |
+ }
|
|
Anton Arapov |
0a7886 |
+
|
|
Anton Arapov |
0a7886 |
+ /*
|
|
Anton Arapov |
0a7886 |
+ * mmap() will fail with SIGBUS if trying to map beyond the end of
|
|
Anton Arapov |
0a7886 |
+ * the file.
|
|
Anton Arapov |
0a7886 |
+ */
|
|
Anton Arapov |
0a7886 |
+ if (S_ISREG(statbuf.st_mode) && base + (off_t)len > statbuf.st_size)
|
|
Anton Arapov |
0a7886 |
+ {
|
|
Anton Arapov |
0a7886 |
+ fprintf(stderr, "mmap: Can't map beyond end of file %s\n",
|
|
Anton Arapov |
0a7886 |
+ devmem);
|
|
Anton Arapov |
0a7886 |
+ free(p);
|
|
Anton Arapov |
0a7886 |
+ return NULL;
|
|
Anton Arapov |
0a7886 |
+ }
|
|
Anton Arapov |
0a7886 |
+
|
|
Anton Arapov |
0a7886 |
#ifdef _SC_PAGESIZE
|
|
Anton Arapov |
0a7886 |
mmoffset = base % sysconf(_SC_PAGESIZE);
|
|
Anton Arapov |
0a7886 |
#else
|
|
Anton Arapov |
0a7886 |
--
|
|
Anton Arapov |
0a7886 |
2.5.0
|
|
Anton Arapov |
0a7886 |
|