|
|
4eb1a6 |
Fix most obvious intel-microcode2ucode buffer overruns.
|
|
|
4eb1a6 |
Index: microcode_ctl-2.1-19/intel-microcode2ucode.c
|
|
|
4eb1a6 |
===================================================================
|
|
|
4eb1a6 |
--- microcode_ctl-2.1-19.orig/intel-microcode2ucode.c 2018-08-20 04:32:26.803450076 +0200
|
|
|
4eb1a6 |
+++ microcode_ctl-2.1-19/intel-microcode2ucode.c 2018-08-20 04:33:49.324661025 +0200
|
|
|
4eb1a6 |
@@ -47,16 +47,25 @@
|
|
|
4eb1a6 |
char c[0];
|
|
|
4eb1a6 |
};
|
|
|
4eb1a6 |
|
|
|
4eb1a6 |
+#define MAX_MICROCODE 4000000
|
|
|
4eb1a6 |
+
|
|
|
4eb1a6 |
int main(int argc, char *argv[])
|
|
|
4eb1a6 |
{
|
|
|
4eb1a6 |
char *filename = "/lib/firmware/microcode.dat";
|
|
|
4eb1a6 |
FILE *input, *f;
|
|
|
4eb1a6 |
char line[LINE_MAX];
|
|
|
4eb1a6 |
- char buf[4000000];
|
|
|
4eb1a6 |
+ char *buf = NULL;
|
|
|
4eb1a6 |
union mcbuf *mc;
|
|
|
4eb1a6 |
size_t bufsize, count, start;
|
|
|
4eb1a6 |
int rc = EXIT_SUCCESS;
|
|
|
4eb1a6 |
|
|
|
4eb1a6 |
+ buf = malloc(MAX_MICROCODE);
|
|
|
4eb1a6 |
+ if (!buf) {
|
|
|
4eb1a6 |
+ printf("can't allocate buffer\n");
|
|
|
4eb1a6 |
+ rc = EXIT_FAILURE;
|
|
|
4eb1a6 |
+ goto out;
|
|
|
4eb1a6 |
+ }
|
|
|
4eb1a6 |
+
|
|
|
4eb1a6 |
if (argv[1] != NULL)
|
|
|
4eb1a6 |
filename = argv[1];
|
|
|
4eb1a6 |
|
|
|
4eb1a6 |
@@ -74,6 +83,12 @@
|
|
|
4eb1a6 |
count = 0;
|
|
|
4eb1a6 |
mc = (union mcbuf *) buf;
|
|
|
4eb1a6 |
while (fgets(line, sizeof(line), input) != NULL) {
|
|
|
4eb1a6 |
+ if ((count + 3) >= (MAX_MICROCODE / sizeof(mc->i[0]))) {
|
|
|
4eb1a6 |
+ printf("input file is too big");
|
|
|
4eb1a6 |
+ rc = EXIT_FAILURE;
|
|
|
4eb1a6 |
+ goto out;
|
|
|
4eb1a6 |
+ }
|
|
|
4eb1a6 |
+
|
|
|
4eb1a6 |
if (sscanf(line, "%x, %x, %x, %x",
|
|
|
4eb1a6 |
&mc->i[count],
|
|
|
4eb1a6 |
&mc->i[count + 1],
|
|
|
4eb1a6 |
@@ -102,6 +117,10 @@
|
|
|
4eb1a6 |
unsigned int family, model, stepping;
|
|
|
4eb1a6 |
unsigned int year, month, day;
|
|
|
4eb1a6 |
|
|
|
4eb1a6 |
+ if ((start > bufsize) ||
|
|
|
4eb1a6 |
+ ((bufsize - start) < sizeof(struct microcode_header_intel)))
|
|
|
4eb1a6 |
+ goto out;
|
|
|
4eb1a6 |
+
|
|
|
4eb1a6 |
mc = (union mcbuf *) &buf[start];
|
|
|
4eb1a6 |
|
|
|
4eb1a6 |
if (mc->hdr.totalsize)
|
|
|
4eb1a6 |
@@ -109,8 +128,12 @@
|
|
|
4eb1a6 |
else
|
|
|
4eb1a6 |
size = 2000 + sizeof(struct microcode_header_intel);
|
|
|
4eb1a6 |
|
|
|
4eb1a6 |
+ if (size > (bufsize - start))
|
|
|
4eb1a6 |
+ goto out;
|
|
|
4eb1a6 |
+
|
|
|
4eb1a6 |
if (mc->hdr.ldrver != 1 || mc->hdr.hdrver != 1) {
|
|
|
4eb1a6 |
- printf("unknown version/format:\n");
|
|
|
4eb1a6 |
+ printf("unknown version/format: %d/%d\n",
|
|
|
4eb1a6 |
+ mc->hdr.ldrver, mc->hdr.hdrver);
|
|
|
4eb1a6 |
rc = EXIT_FAILURE;
|
|
|
4eb1a6 |
break;
|
|
|
4eb1a6 |
}
|
|
|
4eb1a6 |
@@ -135,7 +158,11 @@
|
|
|
4eb1a6 |
month = mc->hdr.date >> 24;
|
|
|
4eb1a6 |
day = (mc->hdr.date >> 16) & 0xff;
|
|
|
4eb1a6 |
|
|
|
4eb1a6 |
- asprintf(&filename, "intel-ucode/%02x-%02x-%02x", family, model, stepping);
|
|
|
4eb1a6 |
+ if (asprintf(&filename, "intel-ucode/%02x-%02x-%02x", family,
|
|
|
4eb1a6 |
+ model, stepping) == -1) {
|
|
|
4eb1a6 |
+ printf("Failed to generate ucode filename\n");
|
|
|
4eb1a6 |
+ goto out;
|
|
|
4eb1a6 |
+ }
|
|
|
4eb1a6 |
printf("\n");
|
|
|
4eb1a6 |
printf("%s\n", filename);
|
|
|
4eb1a6 |
printf("signature: 0x%02x\n", mc->hdr.sig);
|
|
|
4eb1a6 |
@@ -164,6 +191,11 @@
|
|
|
4eb1a6 |
}
|
|
|
4eb1a6 |
printf("\n");
|
|
|
4eb1a6 |
|
|
|
4eb1a6 |
+ if (start != bufsize)
|
|
|
4eb1a6 |
+ printf("Finished parsing at byte %zu of %zu\n", start, bufsize);
|
|
|
4eb1a6 |
+
|
|
|
4eb1a6 |
out:
|
|
|
4eb1a6 |
+ free(buf);
|
|
|
4eb1a6 |
+
|
|
|
4eb1a6 |
return rc;
|
|
|
4eb1a6 |
}
|