Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp897566rdg; Wed, 11 Oct 2023 08:26:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5mRoPpL4CH58X478ln4kg/QgofVbtAqRAUBl0azhF3sk9M+DZpAT+pfNdfy8zXQ+QMDJ8 X-Received: by 2002:a17:903:248:b0:1c3:6d97:e89e with SMTP id j8-20020a170903024800b001c36d97e89emr24178486plh.58.1697037995102; Wed, 11 Oct 2023 08:26:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697037995; cv=none; d=google.com; s=arc-20160816; b=Dq9BefonlV4AfdxxsD5ZeJECB6gHK5g2WobcGhvw/LlzzT3KLwfPamlm8p7yKo7WsG Qd+1HJlikSbW8t+iZkzm99v0q41xCnSCtf5P7mJs2XUQFfVtEZG24gsgCBvh2REw0h7P FokNfEeJ6N/vXUAcDSKaYzc5IVevu08cN18Kh/lTzfhtEFM4omuW//h7MwOx1rXBYHjX oFrjgeJw/jb8wpb/yV7nbinaZi/vlz/PM/iAehwrbBCsQsofKMrFhU1hZ1xDCVrMYRR+ i9JhCudCt46bmOn+WJxnv+/q6CWvugRIRHku4UOd6JMZfgWLQakSpgAhXEZlg520LWyh m8/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=KH0PWtpRCm05+aAVphimA5nByp40KbySfBeXavs+FAA=; fh=T86+g3eBnFn267DGSTFaeuW2UvczlHn/QNJ2V3/xd28=; b=kCBzrZYB4qZ8Qk+iPFaWA7Ke/Xxd/+DqszbZ3lPeKHQft5Lx/qNQ4O0wNvp9G7Vm0S XTGKUE0Xt63nzvrw2USJw51+TVrOT+sAd94dhdCegR8zJlSJJIPzxn9IEbgxTVyNsynD ix1lKPZeq805abkF763BeFqI2tF2HDr2fsFgIrAe8+xCNkKZ7Lada+eywMi2rWoOC9dg JF3AjN5uDJb9atM2qFOmdoNjzGw5QMBotobF3jo5nBggprDKraSnyte+FS6XjCDvod1b zqOkoHQBjmf6OiXnqpLZCKXIdrWIuCkTcsz54C7OeRm7gb9VOpER8+qmkHsqde38ayet 40FA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id b14-20020a170903228e00b001c5e1816251si1450687plh.497.2023.10.11.08.26.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 08:26:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6432480A13AA; Wed, 11 Oct 2023 08:26:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232805AbjJKP0O (ORCPT + 99 others); Wed, 11 Oct 2023 11:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232673AbjJKP0M (ORCPT ); Wed, 11 Oct 2023 11:26:12 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5355798 for ; Wed, 11 Oct 2023 08:26:10 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id B0E2D21870; Wed, 11 Oct 2023 15:26:08 +0000 (UTC) Received: from suse.cz (pmladek.udp.ovpn2.prg.suse.de [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 2D7A92C710; Wed, 11 Oct 2023 15:26:07 +0000 (UTC) Date: Wed, 11 Oct 2023 17:26:07 +0200 From: Petr Mladek To: Tony Lindgren Cc: Greg Kroah-Hartman , Steven Rostedt , John Ogness , Sergey Senozhatsky , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] printk: Check valid console index for preferred console Message-ID: References: <20231011074330.14487-1-tony@atomide.com> <2023101131-maroon-stubborn-1364@gregkh> <20231011091803.GC34982@atomide.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231011091803.GC34982@atomide.com> X-Spamd-Bar: +++++++++++++++++++++++ Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.com (policy=quarantine); spf=fail (smtp-out1.suse.de: domain of pmladek@suse.com does not designate 149.44.160.134 as permitted sender) smtp.mailfrom=pmladek@suse.com X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [23.60 / 50.00]; ARC_NA(0.00)[]; R_SPF_FAIL(1.00)[-all]; BAYES_SPAM(5.10)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RWL_MAILSPIKE_GOOD(0.00)[149.44.160.134:from]; RCPT_COUNT_FIVE(0.00)[6]; DMARC_POLICY_QUARANTINE(1.50)[suse.com : No valid SPF, No valid DKIM,quarantine]; VIOLATED_DIRECT_SPF(3.50)[]; MX_GOOD(-0.01)[]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; MID_RHS_NOT_FQDN(0.50)[]; R_DKIM_NA(0.20)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+] X-Spam-Score: 23.60 X-Rspamd-Queue-Id: B0E2D21870 X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 11 Oct 2023 08:26:23 -0700 (PDT) X-Spam-Level: ** On Wed 2023-10-11 12:18:03, Tony Lindgren wrote: > * Greg Kroah-Hartman [231011 07:53]: > > On Wed, Oct 11, 2023 at 10:43:25AM +0300, Tony Lindgren wrote: > > > Let's check for valid console index values to avoid bogus console index > > > numbers from kernel command line. While struct console uses short for > > > index, and negative index values are used by some device drivers, we do > > > not want to allow negative values for preferred console. > > > > What drivers use a negative index for the console? > > This is based on grepping with $ git grep "co->index =" drivers/tty/ > > Not sure what all might be stopping making struct console index unsigned. The value -1 is used for initializing struct console, see: $> git grep -A10 "struct console.*=" | \ grep -e "struct console" -e index | \ grep -B1 index [...] drivers/tty/serial/8250/8250_core.c:static struct console univ8250_console = { drivers/tty/serial/8250/8250_core.c- .index = -1, [...] drivers/tty/serial/imx.c:static struct console imx_uart_console = { drivers/tty/serial/imx.c- .index = -1, drivers/tty/serial/ip22zilog.c:static struct console ip22zilog_console = { drivers/tty/serial/ip22zilog.c- .index = -1, drivers/tty/serial/kgdb_nmi.c:static struct console kgdb_nmi_console = { drivers/tty/serial/kgdb_nmi.c- .index = -1, drivers/tty/serial/lantiq.c:static struct console lqasc_console = { drivers/tty/serial/lantiq.c- .index = -1, drivers/tty/serial/liteuart.c:static struct console liteuart_console = { drivers/tty/serial/liteuart.c- .index = -1, drivers/tty/serial/lpc32xx_hs.c:static struct console lpc32xx_hsuart_console = { drivers/tty/serial/lpc32xx_hs.c- .index = -1, drivers/tty/serial/ma35d1_serial.c:static struct console ma35d1serial_console = { drivers/tty/serial/ma35d1_serial.c- .index = -1, drivers/tty/serial/mcf.c:static struct console mcf_console = { drivers/tty/serial/mcf.c- .index = -1, [...] It means that the index still has be get assigned. For example, it is used here: static int try_enable_preferred_console(struct console *newcon, bool user_specified) { [...] if (newcon->index < 0) newcon->index = c->index; [...] Resume: 1. We must either keep signed short in struct console or use another check for non-yet assigned index. 2. We should fix the commit message and the comment. We should explain that negative value is used in struct console to distinguish a non-yet-registered/assigned index/port. Best Regards, Petr