From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJEag-0002Ls-35 for kexec@lists.infradead.org; Fri, 18 Sep 2020 11:30:11 +0000 From: John Ogness Subject: Re: [PATCH printk 1/3] printk: move printk_info into separate array In-Reply-To: <20200918100602.GB14605@alley> References: <20200917131644.25838-1-john.ogness@linutronix.de> <20200917131644.25838-2-john.ogness@linutronix.de> <20200918100602.GB14605@alley> Date: Fri, 18 Sep 2020 13:36:06 +0206 Message-ID: <87k0wrb9vl.fsf@jogness.linutronix.de> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: Petr Mladek Cc: Sergey Senozhatsky , Greg Kroah-Hartman , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Steven Rostedt , Sergey Senozhatsky , Thomas Gleixner , Linus Torvalds On 2020-09-18, Petr Mladek 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 _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=3.0 tests=BAYES_00, BUG6152_INVALID_DATE_TZ_ABSURD,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C755C43464 for ; Fri, 18 Sep 2020 11:32:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00ADA2311A for ; Fri, 18 Sep 2020 11:32:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hZ2vQvKy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xw89RIR3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726476AbgIRLcJ (ORCPT ); Fri, 18 Sep 2020 07:32:09 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:33838 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726239AbgIRLa0 (ORCPT ); Fri, 18 Sep 2020 07:30:26 -0400 X-Greylist: delayed 80002 seconds by postgrey-1.27 at vger.kernel.org; Fri, 18 Sep 2020 07:30:25 EDT From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1600428606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=X8efSfSmWaNbeYbeXyDKLA+gUx+Kn3kVHQX4V3piCYI=; b=hZ2vQvKy3SsAvSsP5u6L6uh4RCjF9TTilJjTnHRlYQMpniz49lLtJus3K3YZrZpqzPiNjL q6sjxyF4EhLeccI7WbmICPjGZIK/PloNiBDq1SLZ+IDiL9cRvmlpyJAI7vWuTeHKuFUaSd QqtkWLCaD1UOSoMy4zIbUFFKugvBNeoF1jQQ4On0KeZy7HHROk5VFg/gRP4EiShFp9KSVC o0Ky8lNNBErh2tePouP8goWez5bAyQKSTvn9V3Wn/f0nWBTkgH8T0rm0i2vPu63i/j2g6I jnXL6DrhxP1+qgAU6SaKDCAfRPEknXxW6lgRdeFJlVpt5e72ycoCDECVl++D4Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1600428606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=X8efSfSmWaNbeYbeXyDKLA+gUx+Kn3kVHQX4V3piCYI=; b=xw89RIR38MEmhGSYjel2Ruz1PQC2IWwp/zIQQ++7r0w8DqLucqBaL/qUYBQJYl9/Pdsexq wgYqSf6xEEhmIoAg== To: Petr Mladek Cc: Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Thomas Gleixner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH printk 1/3] printk: move printk_info into separate array In-Reply-To: <20200918100602.GB14605@alley> References: <20200917131644.25838-1-john.ogness@linutronix.de> <20200917131644.25838-2-john.ogness@linutronix.de> <20200918100602.GB14605@alley> Date: Fri, 18 Sep 2020 13:36:06 +0206 Message-ID: <87k0wrb9vl.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-09-18, Petr Mladek 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