linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	kexec@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH printk 1/3] printk: move printk_info into separate array
Date: Fri, 18 Sep 2020 13:36:06 +0206	[thread overview]
Message-ID: <87k0wrb9vl.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20200918100602.GB14605@alley>

On 2020-09-18, Petr Mladek <pmladek@suse.com> wrote:
>> --- a/kernel/printk/printk.c
>> +++ b/kernel/printk/printk.c
>> @@ -1097,6 +1097,7 @@ static char setup_dict_buf[CONSOLE_EXT_LOG_MAX] __initdata;
>>  
>>  void __init setup_log_buf(int early)
>>  {
>> +	struct printk_info *new_infos;
>>  	unsigned int new_descs_count;
>>  	struct prb_desc *new_descs;
>>  	struct printk_info info;
>> @@ -1156,6 +1157,17 @@ void __init setup_log_buf(int early)
>>  		return;
>>  	}
>>  
>> +	new_descs_size = new_descs_count * sizeof(struct printk_info);
>
> Must be stored into new variable, e.g.  new_infos_size.=

Ack.

>> +	new_infos = memblock_alloc(new_descs_size, LOG_ALIGN);
>> +	if (unlikely(!new_infos)) {
>> +		pr_err("log_buf_len: %zu info bytes not available\n",
>> +		       new_descs_size);
>> +		memblock_free(__pa(new_descs), new_log_buf_len);
>> +		memblock_free(__pa(new_dict_buf), new_log_buf_len);
>
> The above two calls have wrong size.
>
> The same problem is there also in the error path when new_descs
> allocation fail. It might be better to handle this using some
> goto err_* tagrets.
>
> Please, fix the old problem in a separate patch.

The "old problem" didn't exist. The problem is introduced with this
series. I will fix it with appropriate goto err_* targets for v2.

>> --- a/kernel/printk/printk_ringbuffer.c
>> +++ b/kernel/printk/printk_ringbuffer.c
>> @@ -1726,12 +1762,12 @@ static bool copy_data(struct prb_data_ring *data_ring,
>>  	/*
>>  	 * Actual cannot be less than expected. It can be more than expected
>>  	 * because of the trailing alignment padding.
>> +	 *
>> +	 * Note that invalid @len values can occur because the caller loads
>> +	 * the value during an allowed data race.
>
> I hope that this will not bite us in the future. The fact is that
> copying the entire struct printk_info in get_desc() is ugly and
> copy_data() has to be careful anyway.

It isn't an issue because the state is verified again at the end of
prb_read(). I added the comment because if all you are looking at is
copy_data(), you may not know that @len was read on a data-race. Whereas
inside of prb_read(), it is obvious that the memcpy() is a data-race.

John Ogness

  reply	other threads:[~2020-09-18 11:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17 13:16 [PATCH printk 0/3] printk: move dictionaries to meta data John Ogness
2020-09-17 13:16 ` [PATCH printk 1/3] printk: move printk_info into separate array John Ogness
2020-09-18 10:06   ` Petr Mladek
2020-09-18 11:30     ` John Ogness [this message]
2020-09-17 13:16 ` [PATCH printk 2/3] printk: move dictionary keys to dev_printk_info John Ogness
2020-09-18  6:16   ` Rasmus Villemoes
2020-09-18 12:13     ` Petr Mladek
2020-09-18 12:32       ` Rasmus Villemoes
2020-09-18 14:24         ` Petr Mladek
2020-09-18 11:39   ` Petr Mladek
2020-09-17 13:16 ` [PATCH printk 3/3] printk: remove dict ring John Ogness
2020-09-17 17:59   ` Linus Torvalds
2020-09-18 14:56   ` Petr Mladek

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=87k0wrb9vl.fsf@jogness.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).