From patchwork Wed Oct 4 08:54:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 148180 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2616584vqb; Wed, 4 Oct 2023 01:55:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAJSHveHVVnk2ynIT2W5DBH/zO+f+5QzxpBflCLhOXkost9ZOIY6LmKvZ4UFJp3DCg1XJ0 X-Received: by 2002:a05:6a20:3251:b0:15d:e68d:a855 with SMTP id hm17-20020a056a20325100b0015de68da855mr1608687pzc.29.1696409745081; Wed, 04 Oct 2023 01:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696409745; cv=none; d=google.com; s=arc-20160816; b=BRoWgv8eUR+aDS3A6W0LFxJH3bhCrTUDK3Qg6JnKIlvtXZhb6CFSTP0KObxnaUwJuP sxR7sosPA3JzWUSfRyePKBFO9Gpc4o9UwS5N7+Vb5GTj5WDWca74mhwWMqzhRd4PMY1I Rg7fPJN8pAaYEQt22uv3iM4hCRKH9XU9/nRlKNu/q0TowtfVZKgmgSP0wbFOOoOKSwHB CRLDs5eNBSHqWBxvbkQEloVoqwqWXBpO6XOB8o+O4GQSThgemooGjiDNDO/mXJRyxbm3 PbNfFbikMZ903BovfO+XEKXAyWk+xpnuNQtA3+7HYSvlu2T57G/YTUamd4pyBxNFbG3T 2EtA== 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:from; bh=QHSDXSZDfLcDWLMe+H5lrfI+IsxykQEocVzwTVa7VEc=; fh=58ImmVCuFle95JFvhXW8TMFJHv6YLSLeJPpTl3/7Lp8=; b=njaQSVRlygRjKjYJbsuREY2OAGZjovSwANM5Pg4X2j8DvPUOFjwr811GLChFcsD5yr OB9Og5bZ3akXpbGFs7uxFm32ikvZ56rTKgXmaRf+86Kok+s/fiv21zOrGvdm6v3A5GqB Nwa9dOPjhH9mzaehZJCL9nTfkWyYIRdlGjDEh694abD3U+7Gp9+xoZxer7G4S7wTh7xe to5OBOTe+pMWF2l1H4/zCFK5ESws840JDaw7Q9ODURSyINjRE5lrjvBB0ENhv4aS18E4 j/fFpczfTtQJAKAQWoSlpAzFBVQp/whWQ6CQaEP40g5zTdQG2KGVEMnctHaGj7OXebK8 0P/w== 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 Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id lo15-20020a170903434f00b001bb9e2c38ecsi3087016plb.264.2023.10.04.01.55.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 01:55:45 -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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B3FD98051BBE; Wed, 4 Oct 2023 01:55: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 S232621AbjJDIzI (ORCPT + 18 others); Wed, 4 Oct 2023 04:55:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232554AbjJDIzH (ORCPT ); Wed, 4 Oct 2023 04:55:07 -0400 Received: from muru.com (unknown [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 95657A6 for ; Wed, 4 Oct 2023 01:55:01 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 459A480BD; Wed, 4 Oct 2023 08:54:45 +0000 (UTC) From: Tony Lindgren To: Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org Subject: [PATCH] printk: Check valid console index for preferred console Date: Wed, 4 Oct 2023 11:54:33 +0300 Message-ID: <20231004085434.42570-1-tony@atomide.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 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, 04 Oct 2023 01:55:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778814544878849423 X-GMAIL-MSGID: 1778814544878849423 Let's check for valid console index values. Signed-off-by: Tony Lindgren --- kernel/printk/printk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2410,6 +2410,10 @@ static int __add_preferred_console(char *name, int idx, char *options, struct console_cmdline *c; int i; + /* See struct console */ + if (idx > SHRT_MAX) + return -EINVAL; + /* * See if this tty is not yet registered, and * if we have a slot free.