From patchwork Fri Feb 17 08:47:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 58428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp775435wrn; Fri, 17 Feb 2023 00:53:37 -0800 (PST) X-Google-Smtp-Source: AK7set+fGL84sD221S20gOdi5sbbMg5cdjDkvyFiDPiBoXqHHYi6TTQ6PQ706SU7f5Sxa/ZiauWy X-Received: by 2002:a17:906:1d1b:b0:8b1:2dd3:cb45 with SMTP id n27-20020a1709061d1b00b008b12dd3cb45mr9557633ejh.42.1676624016828; Fri, 17 Feb 2023 00:53:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676624016; cv=none; d=google.com; s=arc-20160816; b=YQha/hn63VAhlwMoIbYyhMDngLBqzgCMAVTS8f85ZiD8yeX7VGGLwrPMLbRcUxN/HX ttuApCJck9JzCPAaFAztx2Uwq77hlEIuYflow0eN3LjjikcznR2oI6lHxUqs0/ayxtlS /LvGiffU+/0Ora/wHWqFn17QMdKv/FM5EAsyVu23t+QOEPbZriOqM6lvfRe+eyCsIqea WCIK42DXClgTkMkNTK4GN74yoX6yJHoe0uOTP9bnwQIZR1cTp9PqxQt0g2ffhr8OvrjG gax18AQwVgOFCvSblVrKZBs2SLq0Tnp85e1ESYmMBEWYqt9HrMYhQN6QjnhpWAnlQd+P 8Wvg== 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:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=Czz+UHh2RKqC0X5s5ts/z+bv6kppSAX6QrGQ9OL6ABY=; b=cEZZIZuzy0ZcdjwN04gZHt14go/P2Ouw6XlFzHNd5vqKXTuOOf4oNPRvm+RFgivsJd yZaA5PC6hW73Lis9nawR3mjHiGDb6WcKyuCWQJ2A3uAqLIfcyctMk4pQET7T7nXJqr2e ZyrbwqYnk68DT16Z2TY39YLHg82Lee9z3e/laCeJKnpf8OfefVHE3b/YbMTG6fm6ccAK dDErZbqsHsnELcJjY8xEZgAUHdhRKZNadFXc2K0AmIRfWAF6KUHzkMqqexHS1KSjctNC bXq0zlMhlDQNeKaeVzs4lwl0pHq21/He9Q++nMcIHcbxRtwdWF3x+WPmypD6ZIzXYHLA vKOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wvuqpxkI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=tEJu6DkB; 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 fe17-20020a1709072a5100b00882aebb981asi4187887ejc.444.2023.02.17.00.53.14; Fri, 17 Feb 2023 00:53:36 -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=wvuqpxkI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=tEJu6DkB; 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 S229595AbjBQItj (ORCPT + 99 others); Fri, 17 Feb 2023 03:49:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjBQIth (ORCPT ); Fri, 17 Feb 2023 03:49:37 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D94B360FBC; Fri, 17 Feb 2023 00:49:06 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1676623739; 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=Czz+UHh2RKqC0X5s5ts/z+bv6kppSAX6QrGQ9OL6ABY=; b=wvuqpxkIB0VrV2LcTVU2Wi30d5sSFvifaNA+3Xd88OiaEXcI5Rt51oaNY+pvldLFFaDHQz blAphOBmB3Nb2EUj9G0song9CoAoQdnSDugsBm9TVVmjy10MQvT0ZY2xYRsrtzouqr8M8R htf2cwsOOIXCXEfjU9ZZoDW9iJK/t8LAPxoljBDAuR003/hchocIFLRCWMkPaNAC9Z2XCT 06i1j5yksQ6SWp4NAvI42/FESx/lXSYrqUxqeOFCIVOR1ruiaitfUbkxhAxrUG0xv1rHYn KUqSNDWgp/bcEh6veB+3uACjTkW69kZ/3eLIebbIqv5rdHCeoHPWZbLmk7oULA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1676623739; 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=Czz+UHh2RKqC0X5s5ts/z+bv6kppSAX6QrGQ9OL6ABY=; b=tEJu6DkB9Ss4EirYoTFw2klYU/t8BT4+cyusElaV0JHdVXXUKxOCsExKE/ha8/CAQkJ1YH PAfRzkN736E5AcCw== To: Sebastian Siewior Cc: Clark Williams , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Michael Thalmeier , Vincent Whitchurch , linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, "Luis Claudio R. Goncalves" Subject: [PATCH 5.10-rt] printk: ignore consoles without write() callback In-Reply-To: <87bkls65pf.fsf@jogness.linutronix.de> References: <87zg9d99mp.fsf@jogness.linutronix.de> <87bkls65pf.fsf@jogness.linutronix.de> Date: Fri, 17 Feb 2023 09:53:44 +0106 Message-ID: <878rgw65lb.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?1758067704748134815?= 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/1831554214.546921.1676479103702.JavaMail.zimbra@hale.at Reported-by: Michael Thalmeier Signed-off-by: John Ogness --- kernel/printk/printk.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index d2205872304d..64747c72fbea 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2267,6 +2267,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)) { @@ -3566,6 +3570,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 = atomic64_read(&con->printk_seq); if (printk_seq < seq) diff += seq - printk_seq;