From patchwork Thu Feb 16 10:39:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 57974 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp226893wrn; Thu, 16 Feb 2023 02:48:43 -0800 (PST) X-Google-Smtp-Source: AK7set8er38Hvl7SxggdnFhI6eco6zooa0ZM+Hohz6tltDEv9S553aXF/2e/XF96uOVFokNEQXWt X-Received: by 2002:a05:6a20:4405:b0:bd:a50:e274 with SMTP id ce5-20020a056a20440500b000bd0a50e274mr6397506pzb.28.1676544522753; Thu, 16 Feb 2023 02:48:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676544522; cv=none; d=google.com; s=arc-20160816; b=OjamIILJz8K31L7HR33+OaHOXKvzAVUUSM/P89+jJ8GUhEY5sO+S69YPgy2T3SRJYa pN0yOr2cG7+UqogqrVJnBaEv/EZAu/BfyFf0KTo9PMcITxJ+b6AX19/62qGuocjzly0C tJowzE3cZ5P8XiLkuSGH7blXgCF+UO9ZVJK/UlEYNHNLqB6MAROZVB8ibenyJPexC8ER Q5NVpuGsORgtkjOAQNvPKKwM7cklA0VGz7RVYvCiRdurBFnxGI7qx+H4VG+JeMFmS8DC g3Ssj+H8HR3InvCyxBGbtugcazuXA3g35OHQ0HbrWbVjschzvpyG6JloLeT9xDtKMUfJ oQZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to :dkim-signature:dkim-signature:from; bh=FGPeHUbLlmmqkr0P1pwps1dugoZJJLLHDOT/GDe1Nmo=; b=j+TcbISgrBoZ3q6p2F+k3WXSlEvUQhzQr/mQFqAbvz//A+/vSPrZb3yDiufwwsJsym wo+CS6cca0s8IoO7pG1ECseoM2/WLuTBAUnygdtxYEYZjUVjMTPbHOO/Tuf3RMqix/XV ERh8nDX2jMOG9qjj9nQDhy+u8yTVLU1WRWUhfpG+bpTZY65BJrGoCw6pqIo5x9hZuj/1 RwvfKASeQp3uQLlj1btvQrf18a+g8r8FmdBFU+SnBUzFbtg8MauiUpZ8F7Xl0PIj0WY7 mK9gDj82191DBFO+r+Th1Dp2K3zeegQ3Y9Py1BdN/kWVw0XBfV+1/OqsiFkHF+Lv9vAT Zzbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LtIBgBC8; dkim=neutral (no key) header.i=@linutronix.de header.b=K07MjVO9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e20-20020a656894000000b004fbc41d5416si1181236pgt.581.2023.02.16.02.48.30; Thu, 16 Feb 2023 02:48:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LtIBgBC8; dkim=neutral (no key) header.i=@linutronix.de header.b=K07MjVO9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229687AbjBPKmP (ORCPT + 99 others); Thu, 16 Feb 2023 05:42:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbjBPKmJ (ORCPT ); Thu, 16 Feb 2023 05:42:09 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77D61552A9; Thu, 16 Feb 2023 02:41:43 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1676544072; 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; bh=FGPeHUbLlmmqkr0P1pwps1dugoZJJLLHDOT/GDe1Nmo=; b=LtIBgBC83GPPA9ZI9wLPFWhXnDuEWCAubVFEJ4Ik+5pPtrsAI+F7oDr0cdKteV+IuTk6ch r9NQ819jtF4NcydIV/hmAsnMeQen5uWKMVrLIzgqRIt5uRsf4Ai6IhrhytTW1Fg6ESq41A 1MwdYRJxVB8DwWL9weS4tvPzXXmJuFe28AQMw+L6jUCW45PaVm8hasrizXMIqBwSUdNrIj GjEF08SCPdjjaPnOIwTN2AaPsHkYyfQrHVKHKEfFM98318SeWs9U61j/UlPhTYTYl2ja3a 61SyBIow5rl/FVxuhIknpd7N80wf+Cg8dfkYT0oOhiyEQ3T4LMinzMioDAYURA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1676544072; 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; bh=FGPeHUbLlmmqkr0P1pwps1dugoZJJLLHDOT/GDe1Nmo=; b=K07MjVO9TDdxC5rio4jkaV41qIqL8XVvHEx5EbLxcDWj0LOtAXRI6Y2tCOuDa6wk9ON1oo 4ZRvHMhJhGW3jJCg== To: Clark Williams Cc: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Michael Thalmeier , Vincent Whitchurch , Sebastian Siewior , linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org Subject: [PATCH 5.15-rt] printk: ignore consoles without write() callback Date: Thu, 16 Feb 2023 11:45:58 +0106 Message-ID: <87zg9d99mp.fsf@jogness.linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757984349017328671?= X-GMAIL-MSGID: =?utf-8?q?1757984349017328671?= The ttynull driver does not provide an implementation for the write() callback. This leads to a NULL pointer dereference in the related printing kthread, which assumes it can call that callback. Do not create kthreads for consoles that do not implement the write() callback. Also, for pr_flush(), ignore consoles that do not implement write() or write_atomic() since there is no way those consoles can flush their output. Link: https://lore.kernel.org/lkml/878rgy37f5.fsf@jogness.linutronix.de Fixes: 8782b1ef4125 ("printk: move console printing to kthreads") Reported-by: Michael Thalmeier Signed-off-by: John Ogness --- This is only a problem for the PREEMPT_RT tree. Mainline does not have this problem. kernel/printk/printk.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 7f27cfee283e..752afe88b5b4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2343,6 +2343,10 @@ static int printk_kthread_func(void *data) /* Must be called within console_lock(). */ static void start_printk_kthread(struct console *con) { + /* No need to start a printing thread if the console cannot print. */ + if (!con->write) + return; + con->thread = kthread_run(printk_kthread_func, con, "pr/%s%d", con->name, con->index); if (IS_ERR(con->thread)) { @@ -3737,6 +3741,8 @@ bool pr_flush(int timeout_ms, bool reset_on_progress) for_each_console(con) { if (!(con->flags & CON_ENABLED)) continue; + if (!con->write && !con->write_atomic) + continue; printk_seq = read_console_seq(con); if (printk_seq < seq) diff += seq - printk_seq;