User: Password:
|
|
Subscribe / Log in / New account

Re: [Security] [PATCH] kernel: escape non-ASCII and control characters in printk()

From:  Willy Tarreau <w-AT-1wt.eu>
To:  Vasiliy Kulikov <segoon-AT-openwall.com>
Subject:  Re: [Security] [PATCH] kernel: escape non-ASCII and control characters in printk()
Date:  Sat, 25 Jun 2011 22:52:34 +0200
Message-ID:  <20110625205234.GA8743@1wt.eu>
Cc:  Alan Cox <alan-AT-lxorguk.ukuu.org.uk>, security-AT-kernel.org, kernel-hardening-AT-lists.openwall.com, Namhyung Kim <namhyung-AT-gmail.com>, Greg Kroah-Hartman <gregkh-AT-suse.de>, James Morris <jmorris-AT-namei.org>, linux-kernel-AT-vger.kernel.org, Joe Perches <joe-AT-perches.com>, Andrew Morton <akpm-AT-linux-foundation.org>
Archive-link:  Article

Hi Vasiliy,

On Wed, Jun 22, 2011 at 11:07:39PM +0400, Vasiliy Kulikov wrote:
> The final check should be:
> 
>     if (iscntrl(c) && (c != '\n') && (c != '\t'))
> 
> Any comments against this variant?

In fact, I'm not sure we're adding that much protection with such a check
because as long as the '\n' is allowed, it's easy to fake logs. For instance :

$ cd /tmp
$ echo "main() { *(int*)0=0; }" | gcc -xc -o fail -
$ ln -s fail $'Oops: 000\nklogd'
$ ./Oops*
$ dmesg|tail -2
Oops: 000
klogd[1927]: segfault at 0 ip 0000000008048337 sp 00000000ffb54ba4 error 6 in fail[8048000+1000]
$

In an ideal world, only \n should be escaped since it's the only delimitor,
and klogd would get the raw logs with lines correctly sequenced. Other
characters should probably be escaped before going to log files if those
files are supposed to be readable on a terminal.

But I recall it was not possible to escape \n when we worked on the subject
several years ago on 2.4, because some drivers used to send multi-line logs
in a single printk().

The fundamental issue we're facing is that neither inputs nor outputs have
been clearly typed in the past. I tend to consider that a log file is readable
by "tail -f" and a such should not contain dangerous chars, however I also
tend to prefer sending raw logs over the network when they are archived by
different means. In the end it makes sense for the kernel and klogd to
exchange raw logs and syslogd should encode them when pushing them to a
file.

Best regards,
Willy



(Log in to post comments)


Copyright © 2011, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds