From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08E223446B0 for ; Thu, 4 Jun 2026 10:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568126; cv=none; b=StVcs3kKokvi0frEhegB0Pld8J9ERib8BUviZ/aW1/Xlx3eaIteow4sTb66mUSIkysBhNKNUyNVCRhr30YlxsjBIL2FBCgHO39n0z+uhf55aiZN68mvnaaPVs79mXhQ8oTBJqReC4s1jGasQ4iJo/0zGsKToRzGY4fjWdNF2aK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568126; c=relaxed/simple; bh=AFQJL6JMPp0g4kRGcKLKCroOqihJySTVnJoz6vGPvNE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VFcj/SGlx+2eXCQ2tvrPga2sBJJesYAnTVa7rTTFx6pRnQ92Yor+c6Y6Kg3kCIXHiwgoCwBQ6yhpRaYW5NaQDByrxtIu/S2mbVme4ntcOfMZn8sBCS5DqIQiKLSUYL3VwQX12psHHQGmfuuQv4aMVUS9GNmyHLm3t5/FkYQAQjw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=ArZMYogq; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="ArZMYogq" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-490be03d47bso4054335e9.0 for ; Thu, 04 Jun 2026 03:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568123; x=1781172923; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LK7n+7e/TNvgLbKlTKXmHKU+0NOtPYFviWK45OYGA68=; b=ArZMYogqvEXPp5xBhchp9Dv7gh1lUyre1oX8DRTASHg6A30fb0/BnTk1Uic67BP2TR GHXCC7tokxxplC5sZ9hdNNqctw9U1fW6vaxFmruafV4eiruYYxKNzrMHmiNjhVUWnCsu 5+TAIS2Z6Af3y/v8GsOJVCeZvrSZd2mbfIr4KBsNaxfdxS8g+oleuV9zmhHM+AhZj7xF krTCxbnWaqefRkPtz16AxkMhj2sO6QGqX+kEJPhbVcCQm/8adYbi1V7jgbDswvarPjk3 8uTuohYyMOfVdWT6MQeehY1NyBGuh4Txz72puVDuosuAIIx4ScEEVMVN9WlVbxBRmDAi dsLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568123; x=1781172923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LK7n+7e/TNvgLbKlTKXmHKU+0NOtPYFviWK45OYGA68=; b=T6J6yFhQZ/epHBZH0z6Y/1HgE+Ml3FFtUnibV/8l+zXZuL5OKMY89aiaI2pknDqNZi HTGSk/qAVSVONYTUZOjPPoXFGpcDKzfTW098g8fUjLsSszj9415F50DykCu7pTxZ1nhw Ed3JTKhIAvJihwxD11lNXUGRba7sx70vCltudultsoQrhMkZEBgYTLh9jFqr6V7jzW0d UAf5r8bhWWYI3qb9P2/G8TMQrVgqDaSzVdxsTIvkre2NECN/OvZOcu+43hvuAhgoYrM3 8kudCKuxTITxDwOpRcPxatO83bpOH1B8n0l0hpWBHPBz49QbatcGSoOTg8llzvqcknAG IEEQ== X-Forwarded-Encrypted: i=1; AFNElJ/hnFmbQiUsxw6Yg91W177IdE+A5sRHBTh/RePMcpSU3ZTr77Cj+9R5FVQ9V5AWaxuB8OsPy+c6bYQZqEE=@vger.kernel.org X-Gm-Message-State: AOJu0YzJodfkJOFPx6wnqD+dv8NCFvpk24wKRhIcF5zvqBSQpfPoTe86 9BHPYg9ydj+1PMkExszkCV5CLibIjcm35oweO1Gyj+LOLcTtP22g7EJOWSWU9KbRC33hTzyhTO/ AP3G2 X-Gm-Gg: Acq92OH3ovz8u4c/Pssh4Dv5iNoTyDhMV9PjWvM3O/ZI19CvXCpaQZSeouXf7LpvsJi MdznHIkAn7dl0n4J9MNCSfMvzhIyKUf4nha72uSpNynm8is1iT2SVnfd+Ay6xWVU36s9VN1D9c+ Yi0TzJFOi+dagh6gwwQC4+8P1T20PieDMxoDZOoxb4WLB6AqSRCu1FbOs3JnhYmRBfEHkVprEoz STqaXolyMbYYYy9Akwhep1kbgkxowe7lZoXO9ZWvg8xrxEfvz6ey1BELXgn6/zOYYG8YznSmGto l+eOraWqsuBPT4TogjAgHHVbe9/03758wvxKP+0VMu2sZdUgDDMjOHPC9xVw+vAh9tkyDhS+Ksp NS2RSRqj65e/a6MHd3UT/aXM8xo0pKWlfgpNKI92U3O+d2dKOnl4N1SQWzEld1pjtRZu/JYZvW9 sc4nO4NIZfd81PzxjkpEcUEuJCh1mVtIbF9I+5 X-Received: by 2002:a05:600c:1c1f:b0:490:be9e:fd03 with SMTP id 5b1f17b1804b1-490be9efee6mr27751535e9.7.1780568123432; Thu, 04 Jun 2026 03:15:23 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc39eb04sm63397445e9.6.2026.06.04.03.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:15:22 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , Naveen Kumar Chaudhary , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v4 01/11] printk: Handle pre-enabled consoles in the top-level register_console() Date: Thu, 4 Jun 2026 12:14:48 +0200 Message-ID: <20260604101459.393162-2-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260604101459.393162-1-pmladek@suse.com> References: <20260604101459.393162-1-pmladek@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The function try_enable_preferred_console() currently has the non-obvious side effect of returning success for consoles that are already pre-enabled. This obscures the logic flow during console registration. Move the check for pre-enabled consoles directly into the top-level register_console(). This change makes the handling of pre-enabled consoles explicit and easier to follow. Furthermore, this separation lays the groundwork for future cleanups where try_enable_preferred_console() can be restricted to cases where an entry actually exists in the console_cmdline[] array. Also it fixes a possible out-of-bound access when the console_cmdline[] array is full and no console matched. In fact, the check of c->user_specified did not make much sense. The new console either matched and was handled in the for-cycle. Or it did not match and then *c pointed to an unused entry. Possible behavior change: try_enable_preferred_console() will newly be called also with @user_specified parameter set to "false" when it failed with the "true" variant. But it looks like the right way to do. It will allow to call newcon->setup() when the console was preferred by some platform specific code. Reported-by: Naveen Kumar Chaudhary # out-of-bound access Closes: https://lore.kernel.org/r/7sq4tr2nmlz32tvkf6vpsghv6exvqfghsrlvywjcqihzsqqbf7@bspclmti5xg4 Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 0323149548f6..aa53d57a524b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3890,9 +3890,6 @@ static int console_call_setup(struct console *newcon, char *options) * the newly registered console with any of the ones selected * by either the command line or add_preferred_console() and * setup/enable it. - * - * Care need to be taken with consoles that are statically - * enabled such as netconsole */ static int try_enable_preferred_console(struct console *newcon, bool user_specified) @@ -3933,14 +3930,6 @@ static int try_enable_preferred_console(struct console *newcon, return 0; } - /* - * Some consoles, such as pstore and netconsole, can be enabled even - * without matching. Accept the pre-enabled consoles only when match() - * and setup() had a chance to be called. - */ - if (newcon->flags & CON_ENABLED && c->user_specified == user_specified) - return 0; - return -ENOENT; } @@ -4123,6 +4112,14 @@ void register_console(struct console *newcon) if (err == -ENOENT) err = try_enable_preferred_console(newcon, false); + /* + * Some consoles, such as pstore and netconsole, can be enabled even + * without matching. Accept them at this stage when they had a chance + * to match() and call setup(). + */ + if (err == -ENOENT && (newcon->flags & CON_ENABLED)) + err = 0; + /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) { if (newcon->flags & CON_NBCON) -- 2.54.0