Revert "kmsg: allow binary characters"
authorMarek Szyprowski <m.szyprowski@samsung.com>
Wed, 25 Apr 2018 09:50:49 +0000 (11:50 +0200)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Wed, 25 Apr 2018 09:50:49 +0000 (11:50 +0200)
This reverts commit bae6b52d8704da7e487c26c8f0e40491fe7792da.

kernel/printk/printk.c

index 20ebf827e858562d8b92eedfdf02d168cd7566a4..d6b96136deb4141f07e32f9d768e8e622a518b31 100644 (file)
@@ -989,19 +989,15 @@ static ssize_t kmsg_read(struct log_buffer *log_b, struct file *file,
                       user->seq, ts_usec, cont);
        user->prev = msg->flags;
 
+       /* escape non-printable characters */
        for (i = 0; i < msg->text_len; i++) {
                unsigned char c = log_text(msg)[i];
 
-               append_char(&p, e, c);
+               if (c < ' ' || c >= 127 || c == '\\')
+                       p += scnprintf(p, e - p, "\\x%02x", c);
+               else
+                       append_char(&p, e, c);
        }
-
-       /*
-        * The \0 is delimits the text part, while the newline is for formatting
-        * when catting the device directly. We cannot use \n for delimiting due
-        * to security: else one could forge dictionary tags through the message
-        * such as "text\n _PID=123"
-        */
-       append_char(&p, e, '\0');
        append_char(&p, e, '\n');
 
        if (msg->dict_len) {
@@ -1021,6 +1017,11 @@ static ssize_t kmsg_read(struct log_buffer *log_b, struct file *file,
                                continue;
                        }
 
+                       if (c < ' ' || c >= 127 || c == '\\') {
+                               p += scnprintf(p, e - p, "\\x%02x", c);
+                               continue;
+                       }
+
                        append_char(&p, e, c);
                }
                append_char(&p, e, '\n');