Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1533026rdb; Wed, 20 Sep 2023 11:45:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZHtqq1EQKaF6EvdebHEPjKNanJLU+4+WOSI4Sr4to88299nr81E2OLuvyrBtEN0iiW0z/ X-Received: by 2002:a05:6300:808b:b0:152:cb38:5b47 with SMTP id ap11-20020a056300808b00b00152cb385b47mr3095445pzc.55.1695235555502; Wed, 20 Sep 2023 11:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695235555; cv=none; d=google.com; s=arc-20160816; b=MEBdYavNwLg2HqVW2IqCOmx5qqfRF2Jw1TQ/5ZwFfYbCeeB/XIte1aocfNVqb6E5oz 7pDGvPIBKIo5lKbhsLoLi/mfIH3VDcw1kjatAMMBEiVlnmOFdWBHbJjLomdyUp5a7ePr 6XKgS1G104kp7WI6pc5P09MNdyAZ84QwUSz9VbEpXMqNm9/YtpUQUj1aEvIqFYFI/g/w PCWNTso7lC5eaDp1FGOwZb9/RQ/EobNJq4B/uaZqeEBCQ9vhGw8JYCz8CtukkNEzBS/q aLRVNQWr18vQurC0rPo0F5hbeJXD8pZ82UJq/CMigAP2Ed0LaQrNPxdYPZuLbn6qeqyr lDxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:dkim-signature:dkim-signature:from; bh=RiToQxeJYRNFsLus3AGdgJigY3Zsm0XtXndlOR433v4=; fh=W4PKebZaLrMP8FFHUvQos3RnGssN3HyxFo8MtXxbkio=; b=zHqFFimpuRqUNqisQXJqmooWdtw1vAZ8e8KwRMJSC9Z5WBZry/jswioy/n+ARAVJM0 snAFXiT0nYDF+26nO0NdU4RLty6rX4gGfLR52LWLDJjh2mT1BZjauowNfuZBPr3q+oPY EdXmf5OP4t6OgZC7r0C6/rZDq4DdtQQ6b38a5+azaESU5C5F+heg99yGf5Cfx4StAGHg NwiLpCDLWGhgtJhSmyy1Tkm/Tm+MCjrOzKAHqPNnH/FJgV9IdpxFazw4oSOiDShUjBSx u5Nn8AuNSkdcmXLkUyDzP40/CIghl8iTqslvrhLb8ZaUXeWuDdN6ar4yTS7UG8TT7QfC Vd7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hZzpfqlT; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id k20-20020aa788d4000000b006880a2ca0fasi12604344pff.312.2023.09.20.11.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 11:45:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hZzpfqlT; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 7DD8C80D7F7C; Wed, 20 Sep 2023 08:53:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235501AbjITPw5 (ORCPT + 99 others); Wed, 20 Sep 2023 11:52:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235495AbjITPw4 (ORCPT ); Wed, 20 Sep 2023 11:52:56 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7032EA3 for ; Wed, 20 Sep 2023 08:52:50 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695225168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=RiToQxeJYRNFsLus3AGdgJigY3Zsm0XtXndlOR433v4=; b=hZzpfqlTsGHjMNsLOX11qxft14ghonOKPS1ASHK8MOZj6Bm0N9bAaZk2ilWQUMjItJnZSm lDM469p5C5RFvqdm011M7zqGR4Pid/NL0cam5zUndBgaKCRog6yjVgzHxAxbagOqGTDinB RPZSaphBXR/+OZf5TQ4b9yflgMcwu5nn42Sog8G0wq00hla2Roe50cImPXnKlyw/t5pIB5 h10gxIxOhEO/FQMiFbJyTcOzaf64NkcWd84MhHnNgx6toryXeifWolyTI6YzD/Hr1lNhsS sVi1kdQdWZg1cXQE9YOMfjGX1CRjksnBlxnyl98C6dEGndeoeLPzTXmdHm2RmA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695225168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=RiToQxeJYRNFsLus3AGdgJigY3Zsm0XtXndlOR433v4=; b=k0iGd7BEEgYfQcGIWKBPEk5kEL/c2Gn/pBCPkAac0tfEGQtX1ExB1839tn2JuSGH0d29Yn 2Yl7QRdupNP7ajAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, kernel test robot Subject: [PATCH printk v1] printk: fix illegal pbufs access for !CONFIG_PRINTK Date: Wed, 20 Sep 2023 17:58:38 +0206 Message-Id: <20230920155238.670439-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 20 Sep 2023 08:53:05 -0700 (PDT) When CONFIG_PRINTK is not set, PRINTK_MESSAGE_MAX is 0. This leads to a zero-sized array @outbuf in @printk_shared_pbufs. In console_flush_all() a pointer to the first element of the array is assigned with: char *outbuf = &printk_shared_pbufs.outbuf[0]; For !CONFIG_PRINTK this leads to a compiler warning: warning: array subscript 0 is outside array bounds of 'char[0]' [-Warray-bounds] This is not really dangerous because printk_get_next_message() always returns false for !CONFIG_PRINTK, which leads to @outbuf never being used. However, it makes no sense to even compile these functions for !CONFIG_PRINTK. Extend the existing '#ifdef CONFIG_PRINTK' block to contain the formatting and emitting functions since these have no purpose in !CONFIG_PRINTK. This also allows removing several more !CONFIG_PRINTK dummies as well as moving @suppress_panic_printk into a CONFIG_PRINTK block. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202309201724.M9BMAQIh-lkp@intel.com/ Signed-off-by: John Ogness --- kernel/printk/printk.c | 44 +++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 778359b21761..7f40d9122caa 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -102,12 +102,6 @@ DEFINE_STATIC_SRCU(console_srcu); */ int __read_mostly suppress_printk; -/* - * During panic, heavy printk by other CPUs can delay the - * panic and risk deadlock on console resources. - */ -static int __read_mostly suppress_panic_printk; - #ifdef CONFIG_LOCKDEP static struct lockdep_map console_lock_dep_map = { .name = "console_lock" @@ -445,6 +439,12 @@ static int console_msg_format = MSG_FORMAT_DEFAULT; static DEFINE_MUTEX(syslog_lock); #ifdef CONFIG_PRINTK +/* + * During panic, heavy printk by other CPUs can delay the + * panic and risk deadlock on console resources. + */ +static int __read_mostly suppress_panic_printk; + DECLARE_WAIT_QUEUE_HEAD(log_wait); /* All 3 protected by @syslog_lock. */ /* the next printk record to read by syslog(READ) or /proc/kmsg */ @@ -2346,22 +2346,6 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre static u64 syslog_seq; -static size_t record_print_text(const struct printk_record *r, - bool syslog, bool time) -{ - return 0; -} -static ssize_t info_print_ext_header(char *buf, size_t size, - struct printk_info *info) -{ - return 0; -} -static ssize_t msg_print_ext_body(char *buf, size_t size, - char *text, size_t text_len, - struct dev_printk_info *dev_info) { return 0; } -static void console_lock_spinning_enable(void) { } -static int console_lock_spinning_disable_and_check(int cookie) { return 0; } -static bool suppress_message_printing(int level) { return false; } static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; } static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; } @@ -2715,6 +2699,8 @@ static void __console_unlock(void) up_console_sem(); } +#ifdef CONFIG_PRINTK + /* * Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". This * is achieved by shifting the existing message over and inserting the dropped @@ -2729,7 +2715,6 @@ static void __console_unlock(void) * * If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated. */ -#ifdef CONFIG_PRINTK void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) { struct printk_buffers *pbufs = pmsg->pbufs; @@ -2761,9 +2746,6 @@ void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) memcpy(outbuf, scratchbuf, len); pmsg->outbuf_len += len; } -#else -#define console_prepend_dropped(pmsg, dropped) -#endif /* CONFIG_PRINTK */ /* * Read and format the specified record (or a later record if the specified @@ -2921,6 +2903,16 @@ static bool console_emit_next_record(struct console *con, bool *handover, int co return true; } +#else + +static bool console_emit_next_record(struct console *con, bool *handover, int cookie) +{ + *handover = false; + return false; +} + +#endif /* CONFIG_PRINTK */ + /* * Print out all remaining records to all consoles. * base-commit: 9757acd0a700ba4a0d16dde4ba820eb052aba1a7 -- 2.39.2