[systemd-commits] 5 commits - src/journal src/logs-show.c src/util.c src/util.h

Lennart Poettering lennart at kemper.freedesktop.org
Fri Jan 13 18:38:54 PST 2012


 src/journal/coredump.c     |   59 ++++++++++++++++++++++++++++++++-------------
 src/journal/journal-file.c |    2 -
 src/logs-show.c            |   13 ++++++---
 src/util.c                 |    4 +++
 src/util.h                 |    1 
 5 files changed, 56 insertions(+), 23 deletions(-)

New commits:
commit fee80f695687ab3bfb0590e73d6d97a8a19787cd
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jan 14 03:37:32 2012 +0100

    journal: drop privileges when storing coredump

diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index bbec550..6b88099 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -45,6 +45,8 @@ int main(int argc, char* argv[]) {
         char *p = NULL;
         ssize_t n;
         pid_t pid;
+        uid_t uid;
+        gid_t gid;
         struct iovec iovec[14];
         char *core_pid = NULL, *core_uid = NULL, *core_gid = NULL, *core_signal = NULL,
                 *core_timestamp = NULL, *core_comm = NULL, *core_exe = NULL, *core_unit = NULL,
@@ -63,31 +65,21 @@ int main(int argc, char* argv[]) {
         r = parse_pid(argv[ARG_PID], &pid);
         if (r < 0) {
                 log_error("Failed to parse PID.");
-                r = -EINVAL;
                 goto finish;
         }
 
-        p = malloc(9 + COREDUMP_MAX);
-        if (!p) {
-                log_error("Out of memory");
-                r = -ENOMEM;
+        r = parse_uid(argv[ARG_UID], &uid);
+        if (r < 0) {
+                log_error("Failed to parse UID.");
                 goto finish;
         }
 
-        memcpy(p, "COREDUMP=", 9);
-
-        n = loop_read(STDIN_FILENO, p + 9, COREDUMP_MAX, false);
-        if (n < 0) {
-                log_error("Failed to read core dump data: %s", strerror(-n));
-                r = (int) n;
+        r = parse_gid(argv[ARG_GID], &gid);
+        if (r < 0) {
+                log_error("Failed to parse GID.");
                 goto finish;
         }
 
-        zero(iovec);
-        iovec[j].iov_base = p;
-        iovec[j].iov_len = 9 + n;
-        j++;
-
         core_pid = strappend("COREDUMP_PID=", argv[ARG_PID]);
         if (core_pid)
                 IOVEC_SET_STRING(iovec[j++], core_pid);
@@ -151,6 +143,39 @@ int main(int argc, char* argv[]) {
         if (core_message)
                 IOVEC_SET_STRING(iovec[j++], core_message);
 
+        /* Now, let's drop privileges to become the user who owns the
+         * segfaulted process and allocate the coredump memory under
+         * his uid. This also ensures that the credentials journald
+         * will see are the ones of the coredumping user, thus making
+         * sure the user himself gets access to the core dump. */
+
+        if (setresgid(gid, gid, gid) < 0 ||
+            setresuid(uid, uid, uid) < 0) {
+                log_error("Failed to drop privileges: %m");
+                r = -errno;
+                goto finish;
+        }
+
+        p = malloc(9 + COREDUMP_MAX);
+        if (!p) {
+                log_error("Out of memory");
+                r = -ENOMEM;
+                goto finish;
+        }
+
+        memcpy(p, "COREDUMP=", 9);
+
+        n = loop_read(STDIN_FILENO, p + 9, COREDUMP_MAX, false);
+        if (n < 0) {
+                log_error("Failed to read core dump data: %s", strerror(-n));
+                r = (int) n;
+                goto finish;
+        }
+
+        iovec[j].iov_base = p;
+        iovec[j].iov_len = 9 + n;
+        j++;
+
         r = sd_journal_sendv(iovec, j);
         if (r < 0)
                 log_error("Failed to send coredump: %s", strerror(-r));

commit e6acda19b26e5a8e490b48b15e2ba33d9103b3bd
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jan 14 03:07:47 2012 +0100

    journal: when show blob data show length

diff --git a/src/logs-show.c b/src/logs-show.c
index 8d1c77e..5a00133 100644
--- a/src/logs-show.c
+++ b/src/logs-show.c
@@ -225,9 +225,10 @@ static int output_short(sd_journal *j, unsigned line, bool show_all, bool monoto
 
         if (show_all)
                 printf(": %.*s\n", (int) message_len, message);
-        else if (contains_unprintable(message, message_len))
-                fputs(": [blob data]\n", stdout);
-        else if (message_len + n < columns())
+        else if (contains_unprintable(message, message_len)) {
+                char bytes[FORMAT_BYTES_MAX];
+                printf(": [%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len));
+        } else if (message_len + n < columns())
                 printf(": %.*s\n", (int) message_len, message);
         else if (n < columns()) {
                 char *e;
@@ -298,6 +299,7 @@ static int output_verbose(sd_journal *j, unsigned line, bool show_all) {
                 if (!show_all && (length > PRINT_THRESHOLD ||
                                   contains_unprintable(data, length))) {
                         const char *c;
+                        char bytes[FORMAT_BYTES_MAX];
 
                         c = memchr(data, '=', length);
                         if (!c) {
@@ -305,9 +307,10 @@ static int output_verbose(sd_journal *j, unsigned line, bool show_all) {
                                 return -EINVAL;
                         }
 
-                        printf("\t%.*s=[blob data]\n",
+                        printf("\t%.*s=[%s blob data]\n",
                                (int) (c - (const char*) data),
-                               (const char*) data);
+                               (const char*) data,
+                               format_bytes(bytes, sizeof(bytes), length - (c - (const char *) data) - 1));
                 } else
                         printf("\t%.*s\n", (int) length, (const char*) data);
         }

commit 32895bb39049b7d5c244a2e4201f47077bfa8b12
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jan 14 03:07:29 2012 +0100

    util: support formatting eta and peta bytes with format_bytes()

diff --git a/src/util.c b/src/util.c
index 7450565..b6e490d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -3077,6 +3077,8 @@ int parse_bytes(const char *t, off_t *bytes) {
                 { "M", 1024ULL*1024ULL },
                 { "G", 1024ULL*1024ULL*1024ULL },
                 { "T", 1024ULL*1024ULL*1024ULL*1024ULL },
+                { "P", 1024ULL*1024ULL*1024ULL*1024ULL*1024ULL },
+                { "E", 1024ULL*1024ULL*1024ULL*1024ULL*1024ULL*1024ULL },
                 { "", 1 },
         };
 
@@ -6082,6 +6084,8 @@ char *format_bytes(char *buf, size_t l, off_t t) {
                 const char *suffix;
                 off_t factor;
         } table[] = {
+                { "E", 1024ULL*1024ULL*1024ULL*1024ULL*1024ULL*1024ULL },
+                { "P", 1024ULL*1024ULL*1024ULL*1024ULL*1024ULL },
                 { "T", 1024ULL*1024ULL*1024ULL*1024ULL },
                 { "G", 1024ULL*1024ULL*1024ULL },
                 { "M", 1024ULL*1024ULL },

commit a7bc2c2ac8d26779ed1154841545e8c0efbef31c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jan 14 03:06:57 2012 +0100

    util: introduce FORMAT_BYTES_MAX

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 419e15e..59ad84e 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -2103,7 +2103,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
 void journal_default_metrics(JournalMetrics *m, int fd) {
         uint64_t fs_size = 0;
         struct statvfs ss;
-        char a[64], b[64], c[64], d[64];
+        char a[FORMAT_BYTES_MAX], b[FORMAT_BYTES_MAX], c[FORMAT_BYTES_MAX], d[FORMAT_BYTES_MAX];
 
         assert(m);
         assert(fd >= 0);
diff --git a/src/util.h b/src/util.h
index e6ffad6..5413490 100644
--- a/src/util.h
+++ b/src/util.h
@@ -67,6 +67,7 @@ typedef struct dual_timestamp {
 #define FORMAT_TIMESTAMP_MAX 64
 #define FORMAT_TIMESTAMP_PRETTY_MAX 256
 #define FORMAT_TIMESPAN_MAX 64
+#define FORMAT_BYTES_MAX 8
 
 #define ANSI_HIGHLIGHT_ON "\x1B[1;39m"
 #define ANSI_HIGHLIGHT_RED_ON "\x1B[1;32m"

commit de0229ca36034981f6c380de39bf7ffd3c6b57fa
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jan 14 03:05:34 2012 +0100

    journal: collect coredump up to 24M in size

diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index f160270..bbec550 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -28,7 +28,7 @@
 #include "log.h"
 #include "util.h"
 
-#define COREDUMP_MAX (64*1024)
+#define COREDUMP_MAX (24*1024*1024)
 
 enum {
         ARG_PID = 1,



More information about the systemd-commits mailing list