[OE-core] [daisy][PATCH 1/1] systemd: do not use alloca() function in case of uclibc

Chen Qi Qi.Chen at windriver.com
Tue Jun 3 07:42:08 UTC 2014


The alloca() function allocates space in the stack frame of the caller,
so using alloca(new_size - old_size) would possibly crash the stack,
causing a segment fault error.

This patch fixes the above problem by avoiding using this function in
journal-file.c.

[YOCTO #6201]

Signed-off-by: Chen Qi <Qi.Chen at windriver.com>
---
 .../0001-journal-file.c-do-not-use-alloca.patch    |   54 ++++++++++++++++++++
 meta/recipes-core/systemd/systemd_211.bb           |    1 +
 2 files changed, 55 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/0001-journal-file.c-do-not-use-alloca.patch

diff --git a/meta/recipes-core/systemd/systemd/0001-journal-file.c-do-not-use-alloca.patch b/meta/recipes-core/systemd/systemd/0001-journal-file.c-do-not-use-alloca.patch
new file mode 100644
index 0000000..a638d58
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0001-journal-file.c-do-not-use-alloca.patch
@@ -0,0 +1,54 @@
+Upstream-Status: Inappropriate [oe specific]
+
+journal-file.c: do not use alloca
+
+Using alloca(new_size - old_size) would possibly cause a segment fault
+error. Note that the alloca function allocates space in the stack frame
+of the caller. So it's possible that the allocated size exceeds the stack
+size limit.
+
+There's actually no need to allocate stack here, we only need to write some
+bytes to the block to make sure the needed block space is available, just like
+eglibc does in posix_fallocate.
+
+Signed-off-by: Chen Qi <Qi.Chen at windriver.com>
+
+---
+ src/journal/journal-file.c |   21 +++++++++------------
+ 1 file changed, 9 insertions(+), 12 deletions(-)
+
+diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
+index cef8bba..e364298 100644
+--- a/src/journal/journal-file.c
++++ b/src/journal/journal-file.c
+@@ -371,18 +371,15 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
+         if (r != 0)
+                 return -r;
+ #else
+-       /* Use good old method to write zeros into the journal file
+-          perhaps very inefficient yet working. */
+-       if(new_size > old_size) {
+-               char *buf = alloca(new_size - old_size);
+-               off_t oldpos = lseek(f->fd, 0, SEEK_CUR);
+-               bzero(buf, new_size - old_size);
+-               lseek(f->fd, old_size, SEEK_SET);
+-               r = write(f->fd, buf, new_size - old_size);
+-               lseek(f->fd, oldpos, SEEK_SET);
+-       }
+-       if (r < 0)
+-               return -errno;
++        /* Write something every 512 bytes to make sure the block is allocated */
++        uint64_t len = new_size - old_size;
++        uint64_t offset = old_size;
++        for (offset += (len-1) % 512; len > 0; offset += 512) {
++                len -= 512;
++                if (pwrite(f->fd, "", 1, offset) != 1)
++                        return -errno;
++        }
++
+ #endif /* HAVE_POSIX_FALLOCATE */
+ 
+         if (fstat(f->fd, &f->last_stat) < 0)
+-- 
+1.7.9.5
+
diff --git a/meta/recipes-core/systemd/systemd_211.bb b/meta/recipes-core/systemd/systemd_211.bb
index 44b1965..3eb3778 100644
--- a/meta/recipes-core/systemd/systemd_211.bb
+++ b/meta/recipes-core/systemd/systemd_211.bb
@@ -32,6 +32,7 @@ SRC_URI = "git://anongit.freedesktop.org/systemd/systemd;branch=master;protocol=
            file://uclibc-sysinfo_h.patch \
            file://uclibc-get-physmem.patch \
            file://sd-bus-don-t-use-assert_return-to-check-for-disconne.patch \
+           file://0001-journal-file.c-do-not-use-alloca.patch \
            \
            file://touchscreen.rules \
            file://00-create-volatile.conf \
-- 
1.7.9.5




More information about the Openembedded-core mailing list