Blame SOURCES/0002-init-Don-t-allocate-modules-on-the-stack-RHBZ-133969.patch

c431b2
From 557952500a10513120e90e5118c53030363a778e Mon Sep 17 00:00:00 2001
c431b2
From: "Richard W.M. Jones" <rjones@redhat.com>
c431b2
Date: Wed, 25 May 2016 17:29:16 +0100
c431b2
Subject: [PATCH 2/7] init: Don't allocate modules on the stack (RHBZ#1339691).
c431b2
c431b2
If the modules are unstripped and/or especially large, then the stack
c431b2
can overflow.
c431b2
c431b2
Thanks: Luiz Capitulino for testing.
c431b2
---
c431b2
 init/init.c | 8 +++++++-
c431b2
 1 file changed, 7 insertions(+), 1 deletion(-)
c431b2
c431b2
diff --git a/init/init.c b/init/init.c
c431b2
index 106be02..733d66e 100644
c431b2
--- a/init/init.c
c431b2
+++ b/init/init.c
c431b2
@@ -314,7 +314,11 @@ insmod (const char *filename)
c431b2
     exit (EXIT_FAILURE);
c431b2
   }
c431b2
   size = st.st_size;
c431b2
-  char buf[size];
c431b2
+  char *buf = malloc (size);
c431b2
+  if (buf == NULL) {
c431b2
+    fprintf (stderr, "insmod: malloc (%s, %zu bytes): %m\n", filename, size);
c431b2
+    exit (EXIT_FAILURE);
c431b2
+  }
c431b2
   size_t offset = 0;
c431b2
   do {
c431b2
     ssize_t rc = read (fd, buf + offset, size - offset);
c431b2
@@ -332,6 +336,8 @@ insmod (const char *filename)
c431b2
      * of a missing device.
c431b2
      */
c431b2
   }
c431b2
+
c431b2
+  free (buf);
c431b2
 }
c431b2
 
c431b2
 /* Mount /proc unless it's mounted already. */
c431b2
-- 
c431b2
2.7.4
c431b2