|
|
531551 |
From 55540ea3dfdc707dc998333fd0715549522464fb Mon Sep 17 00:00:00 2001
|
|
|
531551 |
From: Sebastian Krahmer <krahmer@suse.de>
|
|
|
531551 |
Date: Fri, 5 Dec 2014 10:06:42 +0100
|
|
|
531551 |
Subject: [PATCH 095/116] libblkid: fix potential bufer overflows
|
|
|
531551 |
|
|
|
531551 |
While digging deeper into libblk probing, I found that some
|
|
|
531551 |
computations might wrap and allocate too few buffer space which then
|
|
|
531551 |
overflows. In particular on 32bit systems (chromebook) where size_t is
|
|
|
531551 |
32bit, this is problematic (for 64bit the result fits into the calloc
|
|
|
531551 |
size_t).
|
|
|
531551 |
|
|
|
531551 |
Upstream: Upstream: https://github.com/karelzak/util-linux/commit/109df14fad4e9570e26950913ebace6c79289400
|
|
|
531551 |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1392656
|
|
|
531551 |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
531551 |
---
|
|
|
531551 |
libblkid/src/partitions/gpt.c | 12 ++++++++----
|
|
|
531551 |
libblkid/src/probe.c | 7 +++++++
|
|
|
531551 |
libblkid/src/superblocks/zfs.c | 3 +++
|
|
|
531551 |
3 files changed, 18 insertions(+), 4 deletions(-)
|
|
|
531551 |
|
|
|
531551 |
diff --git a/libblkid/src/partitions/gpt.c b/libblkid/src/partitions/gpt.c
|
|
|
531551 |
index 6ab0dc6..e801ea3 100644
|
|
|
531551 |
--- a/libblkid/src/partitions/gpt.c
|
|
|
531551 |
+++ b/libblkid/src/partitions/gpt.c
|
|
|
531551 |
@@ -17,6 +17,7 @@
|
|
|
531551 |
#include <stdlib.h>
|
|
|
531551 |
#include <stdint.h>
|
|
|
531551 |
#include <stddef.h>
|
|
|
531551 |
+#include <limits.h>
|
|
|
531551 |
|
|
|
531551 |
#include "partitions.h"
|
|
|
531551 |
#include "crc32.h"
|
|
|
531551 |
@@ -266,14 +267,17 @@ static struct gpt_header *get_gpt_header(
|
|
|
531551 |
return NULL;
|
|
|
531551 |
}
|
|
|
531551 |
|
|
|
531551 |
- /* Size of blocks with GPT entries */
|
|
|
531551 |
- esz = le32_to_cpu(h->num_partition_entries) *
|
|
|
531551 |
- le32_to_cpu(h->sizeof_partition_entry);
|
|
|
531551 |
- if (!esz) {
|
|
|
531551 |
+ if (le32_to_cpu(h->num_partition_entries) == 0 ||
|
|
|
531551 |
+ le32_to_cpu(h->sizeof_partition_entry) == 0 ||
|
|
|
531551 |
+ ULONG_MAX / le32_to_cpu(h->num_partition_entries) < le32_to_cpu(h->sizeof_partition_entry)) {
|
|
|
531551 |
DBG(LOWPROBE, blkid_debug("GPT entries undefined"));
|
|
|
531551 |
return NULL;
|
|
|
531551 |
}
|
|
|
531551 |
|
|
|
531551 |
+ /* Size of blocks with GPT entries */
|
|
|
531551 |
+ esz = le32_to_cpu(h->num_partition_entries) *
|
|
|
531551 |
+ le32_to_cpu(h->sizeof_partition_entry);
|
|
|
531551 |
+
|
|
|
531551 |
/* The header seems valid, save it
|
|
|
531551 |
* (we don't care about zeros in hdr->reserved2 area) */
|
|
|
531551 |
memcpy(hdr, h, sizeof(*h));
|
|
|
531551 |
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
|
|
|
531551 |
index f9fab5b..9cf099a 100644
|
|
|
531551 |
--- a/libblkid/src/probe.c
|
|
|
531551 |
+++ b/libblkid/src/probe.c
|
|
|
531551 |
@@ -103,6 +103,7 @@
|
|
|
531551 |
#include <inttypes.h>
|
|
|
531551 |
#include <stdint.h>
|
|
|
531551 |
#include <stdarg.h>
|
|
|
531551 |
+#include <limits.h>
|
|
|
531551 |
|
|
|
531551 |
#ifdef HAVE_LIBUUID
|
|
|
531551 |
# include <uuid.h>
|
|
|
531551 |
@@ -565,6 +566,12 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr,
|
|
|
531551 |
return NULL;
|
|
|
531551 |
}
|
|
|
531551 |
|
|
|
531551 |
+ /* someone trying to overflow some buffers? */
|
|
|
531551 |
+ if (len > ULONG_MAX - sizeof(struct blkid_bufinfo)) {
|
|
|
531551 |
+ errno = ENOMEM;
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
/* allocate info and space for data by why call */
|
|
|
531551 |
bf = calloc(1, sizeof(struct blkid_bufinfo) + len);
|
|
|
531551 |
if (!bf) {
|
|
|
531551 |
diff --git a/libblkid/src/superblocks/zfs.c b/libblkid/src/superblocks/zfs.c
|
|
|
531551 |
index 406ba2b..56ee472 100644
|
|
|
531551 |
--- a/libblkid/src/superblocks/zfs.c
|
|
|
531551 |
+++ b/libblkid/src/superblocks/zfs.c
|
|
|
531551 |
@@ -12,6 +12,7 @@
|
|
|
531551 |
#include <errno.h>
|
|
|
531551 |
#include <ctype.h>
|
|
|
531551 |
#include <inttypes.h>
|
|
|
531551 |
+#include <limits.h>
|
|
|
531551 |
|
|
|
531551 |
#include "superblocks.h"
|
|
|
531551 |
|
|
|
531551 |
@@ -108,6 +109,8 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
|
|
|
531551 |
|
|
|
531551 |
nvs->nvs_type = be32_to_cpu(nvs->nvs_type);
|
|
|
531551 |
nvs->nvs_strlen = be32_to_cpu(nvs->nvs_strlen);
|
|
|
531551 |
+ if (nvs->nvs_strlen > UINT_MAX - sizeof(*nvs))
|
|
|
531551 |
+ break;
|
|
|
531551 |
avail -= nvs->nvs_strlen + sizeof(*nvs);
|
|
|
531551 |
nvdebug("nvstring: type %u string %*s\n", nvs->nvs_type,
|
|
|
531551 |
nvs->nvs_strlen, nvs->nvs_string);
|
|
|
531551 |
--
|
|
|
531551 |
2.9.3
|
|
|
531551 |
|