kmsg: allow binary characters 22/80722/3
authorMichal Bloch <m.bloch@samsung.com>
Thu, 21 Jul 2016 11:41:02 +0000 (13:41 +0200)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 27 Jul 2016 05:48:35 +0000 (14:48 +0900)
* do not touch unprintable characters. This is so that logs can have formatting
  such as newlines, tabulation, or colours.
* the textual part is now delimited by \0. This is because \n which used to be
  the delimiter is now available for logs.

Signed-off-by: Michal Bloch <m.bloch@samsung.com>
Change-Id: I030a4eab791f4468897d3dcdc5bb04549f30b2f7
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
kernel/printk_kmsg.c

index ceb15f6..7a209f4 100644 (file)
@@ -1061,15 +1061,19 @@ 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];
 
-               if (c < ' ' || c >= 127 || c == '\\')
-                       p += scnprintf(p, e - p, "\\x%02x", c);
-               else
-                       append_char(&p, e, c);
+               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) {
@@ -1089,11 +1093,6 @@ 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');