From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF09C36F429 for ; Sat, 11 Apr 2026 15:35:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775921742; cv=none; b=kndLXmLLmOGxSMQ+ZGDg/LX7TZZY3glWz5WUQeimKwIzkLhPduH5+jkm8oFlA4UWLuAX4YZmWPlzY9n4fQ/y2li8EsJLXfXvCTvorIILVRfTeWW083eJP25M7lrHn6YwVKpCL+zyaa7MuQtxiEvaM3DICOxnEEW2Eqt7TjY019o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775921742; c=relaxed/simple; bh=YQXib7EnNku6ugmoNT8BQMzQNpgj44p+g6Xn3GmICpg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oEYP9GIh5obg7C6CbxECXMnVzFFq2bMCtLtYtDf33IlrrUVp/YWSye0QT3rwK/O1kM1hn1Bmad9appXrORQ6Jt+st8pdqbj+D2fvnl4+OeuiBPRCGc3PURvP/bak4SrJYK6w0rfbuiusYqwo8QEAt3/MPvNhZW0Wt/lCk0+fPPc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Nq7KH7om; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Nq7KH7om" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1775921736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VJfbET5d5Ht1wXDqj78ZOGi3GG22W+qpDia5Zu5+H2w=; b=Nq7KH7omkcQUB093wWY5ATGK1JRXTHJUk2nWPE4rJR90klqlpwdzZBj9MM0QFIbqzwCBPQ 2dsSDdkFgyRZucjK9FNyxyebU5VtQVAad88mHpe7PGcJ9/kjZJpPLiCKRqDBif8XDVAMRc sc597IpvhBeDRbfyHnXw7tSROzawcDA= From: Thorsten Blum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: Thorsten Blum , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] x86/boot: validate earlyprintk= baud rate Date: Sat, 11 Apr 2026 17:34:49 +0200 Message-ID: <20260411153449.69384-4-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2041; i=thorsten.blum@linux.dev; h=from:subject; bh=YQXib7EnNku6ugmoNT8BQMzQNpgj44p+g6Xn3GmICpg=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJm3siSNls719DLO/eJiJjy71V01dKfs4luCJnxrJoab3 vla+HFlRykLgxgXg6yYIsuDWT9m+JbWVG4yidgJM4eVCWQIAxenAEzEm5WR4dLXmFwZ6Xlf9cK5 LsdvsNXx3S+wRqVbZRHzVKfNQmVNFowMk62e3mmz5E86ec0rb+flqx9TFHPWhAq+eeK/dVvqHHl NLgA= X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT parse_earlyprintk() parses the baud rate from the earlyprintk= boot parameter with simple_strtoull(), stores it in an int, and passes it to early_serial_init() without validating its range first. Large rates can then be truncated to a non-zero int, after which early_serial_init() computes the UART divisor from a potentially corrupted baud rate. Validate the parsed baud rate before narrowing it to int and only accept rates from 2 to BASE_BAUD, which fit in the 16-bit divisor written to DLL/DLH. Values greater than BASE_BAUD would produce divisor 0, and baud 1 would produce divisor BASE_BAUD, which exceeds 16 bits. Only parse the baud rate when a usable port has been selected, since 'baud' is not used otherwise. Fall back to DEFAULT_BAUD for out-of-range values. Signed-off-by: Thorsten Blum --- arch/x86/boot/early_serial_console.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c index 023bf1c3de8b..fe0c8c1022f4 100644 --- a/arch/x86/boot/early_serial_console.c +++ b/arch/x86/boot/early_serial_console.c @@ -22,6 +22,7 @@ #define DLH 1 /* Divisor latch High */ #define DEFAULT_BAUD 9600 +#define BASE_BAUD (1843200/16) static void early_serial_init(int port, int baud) { @@ -89,16 +90,20 @@ static void parse_earlyprintk(void) if (arg[pos] == ',') pos++; - baud = simple_strtoull(arg + pos, &e, 0); - if (baud == 0 || arg + pos == e) - baud = DEFAULT_BAUD; + /* Parse the baud rate only if a usable port is selected. */ + if (port) { + unsigned long long parsed_baud; + + parsed_baud = simple_strtoull(arg + pos, NULL, 0); + if (parsed_baud >= 2 && parsed_baud <= BASE_BAUD) + baud = (int)parsed_baud; + } } if (port) early_serial_init(port, baud); } -#define BASE_BAUD (1843200/16) static unsigned int probe_baud(int port) { unsigned char lcr, dll, dlh;