All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Sean Hudson <darknighte@darknighte.com>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Yang Shi <yang.shi@linaro.org>, Ingo Molnar <mingo@kernel.org>,
	Prarit Bhargava <prarit@redhat.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Yaowei Bai <baiyaowei@cmss.chinamobile.com>,
	Kees Cook <keescook@chromium.org>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Johannes Weiner <hannes@cmpxchg.org>, Tejun Heo <tj@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Thomas Garnier <thgarnie@google.com>,
	Nicolas Pitre <nicolas.pitre@linaro.org>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Borislav Petkov <bp@suse.de>, Tim Bird <tim.bird@sonymobile.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Grant Likely <grant.likely@secretlab.ca>
Subject: Re: [RFC PATCH v1 2/2] printk: external log buffer (CONFIG_LOGBUFFER)
Date: Tue, 4 Oct 2016 13:27:07 +0200	[thread overview]
Message-ID: <20161004112707.GC13369@pathway.suse.cz> (raw)
In-Reply-To: <5ac629d8-802e-a982-e4e9-f3cba83aef8c@mentor.com>

On Fri 2016-09-30 23:06:49, Sean Hudson wrote:
> On 9/30/2016 7:39 AM, Petr Mladek wrote:
> > On Thu 2016-09-29 19:55:56, Sean Hudson wrote:
> >> +	/* Overwrite the default lcb pointer, buffer pointer, and length. */
> >> +	lcb = new_lcb;
> >> +	lcb->log_buf = (char *)new_lcb->log_buf;
> >> +	lcb->log_buf_len = new_lcb->log_buf_len;
> > 
> > Is the bootloader allowed to write to the shared buffer from this
> > point on? How will be synchronized the writes from the kernel and
> > the bootloader?
> 
> I am a bit confused by this question.  I assume that the kernel and
> bootloader will not be accessing the same log space simultaneously.
> While each one is running, they will utilize the same data structures to
> keep track of current entries.

They both will write new messages at the end of the buffer. Therefore
they both might want to write to exactly the same location. Also if
the buffer is full, the oldest messages are overwritten. Therefore
even reading must be synchronized against writes.

These operations are synchronized using logbuf_lock on the kernel side.
I do not know much about bootloaders but I guess that the bootloader
will not be able to use the logbuf_lock. So the question is how
the bootloader and kernel will synchronize the access to the shared
buffer.

Or did I miss anything?


> > How protected will the address of the shared buffer? Would not
> > it open a security hole? We need to make sure that non-privileged
> > user or non-trusted application must not read sensitive data
> > from the log or break the structure of the log by writing
> > invalid data.
> 
> There is no notion of protection of the address.  However, additional
> checking could be added. Currently, there is potential for corrupt log
> entries from the bootloader causing the kernel to crash.
> I can't think of a way to prevent that from happening.

IMHO, the only way is to revisit all locations when the log buffer
is accessed and add all the needed consistency checks. We must make
sure that we do not access outside of the buffer. Also the log_*_seq
numbers are supposed to grow linearly...


>  Also, as you point out, a bootloader could read log contents from
> the shared region. Of course, in order for either to happen,
> the bootloader would already be compromised and I'm not sure that
>  reading log entries or crashing the kernel is such a big consideration.

The log might contain addresses of some kernel structures, for example
in some error messages. For this reason, only a privileged users are
able to read it. We must make sure that they will not get accessible
for a non-privileged user, for example via an address to the shared
buffer in the bootloader config.

BTW: You did not answered the question about how the bootloader would
know the right version of the log format. I am afraid that we do not
want to maintain backward compatibility on the kernel side. The printk
code already is too complex.

Also you did not answered the question about your plans. I wonder
which bootloader would be able to use such a feature.

Best Regards,
Petr

  reply	other threads:[~2016-10-04 11:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-30  0:55 [RFC PATCH v1 0/2] printk: Shared kernel logging Sean Hudson
2016-09-30  0:55 ` [RFC PATCH v1 1/2] printk: collect offsets into replaceable structure Sean Hudson
2016-09-30  0:55 ` [RFC PATCH v1 2/2] printk: external log buffer (CONFIG_LOGBUFFER) Sean Hudson
2016-09-30 12:39   ` Petr Mladek
2016-10-01  4:06     ` Sean Hudson
2016-10-04 11:27       ` Petr Mladek [this message]
2016-10-04 17:55         ` Sean Hudson
2016-10-05 12:48           ` Petr Mladek
2016-10-12  1:12             ` Sean Hudson
2016-10-14  9:52               ` Petr Mladek
2016-09-30  1:36 ` [RFC PATCH v1 0/2] printk: Shared kernel logging Kees Cook
2016-10-01  1:56   ` Sean Hudson
2016-10-01  2:42     ` Kees Cook
2016-10-04 21:08 ` [RFC PATCH v2 " Sean Hudson
2016-10-04 21:08   ` [RFC PATCH v2 1/2] printk: collect offsets into replaceable structure Sean Hudson
2016-10-04 21:08   ` [RFC PATCH v2 2/2] printk: external log buffer (CONFIG_LOGBUFFER) Sean Hudson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161004112707.GC13369@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=aryabinin@virtuozzo.com \
    --cc=baiyaowei@cmss.chinamobile.com \
    --cc=bp@suse.de \
    --cc=darknighte@darknighte.com \
    --cc=grant.likely@secretlab.ca \
    --cc=hannes@cmpxchg.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mingo@kernel.org \
    --cc=nicolas.pitre@linaro.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=prarit@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=thgarnie@google.com \
    --cc=tim.bird@sonymobile.com \
    --cc=tj@kernel.org \
    --cc=yang.shi@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.