From nobody Fri Apr 17 11:39:10 2026 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 819AA3EBF1E for ; Sun, 22 Feb 2026 14:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771769361; cv=none; b=OB4/PY8752MgcllUCdEW4Lrqh+/P3Z6ZJMgXTIvFk+ImYtjhXHi24HmPDMJ8aiRbohLj+bjNaYjda/lh5TDza1u3MhYT55Z2mly0vpXVy8Dbrluhgll0oQ36L13R2G3Zfl0yjL5NRpnSU6bb6JQsWqPoM/8xunCMGPOU8pqJ/ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771769361; c=relaxed/simple; bh=f1XYIQ7uiIJINlB78FRcqJoApUcrxmIttECkmZh8ZOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DuoPxDxaL742FSLvWumBIpXgMyRbF21AFOKj4oN46afCLynZ6OXh/LeS+V5BciyBxKvDX9lpVpvXHuP8nWHKEvBKgnsB8Nko4Y84mNpDTsUbppaQbCF2Nagp9ys+blmS8LMrvNYCI3oDVgig+Stl9l0jh1FueqyzYxpL9saOWvk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LDP+TAHc; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LDP+TAHc" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-82318b640beso1801021b3a.0 for ; Sun, 22 Feb 2026 06:09:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771769360; x=1772374160; 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=hViuE2LQZNKp9ZU9MiVSa8kD4FYitWUGldKHEfq1RDk=; b=LDP+TAHcZ18wPUIEB3foptmG9orhX9owwZtHc975bzBrdev4ZkxF0P1ii+e3kGBUFP OoHs137+wUHHU0B5XAW7sUOr8kLJMFNp6PnaIoRQjVj/+HGnQ75W3UZpE3g/cHJNeYp7 7HCb+yf8u7uzhykEc3ykGlQyW2Tvz9pyNqpNjYwSEXHJAurM2BQ7hCaJUMAIHx9B1uEu 98ZxxnNvyBzf/j1PhGHPcYwETMnoLvlI9aloVR4M2DMWrSkW7p1c7lGOIDDQf+ErrZpL gLShFbP4wWuU82tEN/935LASZYZPun63AtwhSRJVo70AD4nrVP8katXpQ9lFpBnf5S90 b1Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771769360; x=1772374160; 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=hViuE2LQZNKp9ZU9MiVSa8kD4FYitWUGldKHEfq1RDk=; b=nL53QVdcg1TpayGV36myFKNRNoDKXKsVbnWx3otY/GKIBffYHZ6t+jXk8NsK9ADa/t GF5MSYcucoPwgdON7VARS/hhVT9RgSItS/Zj4d8D4ZcTiiSMgc2JeEbokei0Y+fTBbvI M3nJgCLLwRo9MC4JeBW3s8G7bwiH+pEUoH5h6RJ5GUudgRLlktuM49O7dYKe4Sk+8rWt t1wAqxCMPwITQ/HuDjrLcnUFz4RpMdyljSQn55nvmv1A/iu6ijIMzEXAX7g+kpFsGhza Tg0nTQTahE53gj4SFqthw4owkrWl6SgZQc/cuF0Rx6VNQlB7KjSmbTt8l+WhqI4tolMY owxw== X-Forwarded-Encrypted: i=1; AJvYcCWVY8mrigQHdkgd8raI+9tJwWTA0+K3AGocwakV4IZGDV1I99jg6EwgZ/jobD7/ZgXcnc6w6i6CN7idsQQ=@vger.kernel.org X-Gm-Message-State: AOJu0YztrR4tVvXwYqwUHdMEKcHwexp+4HSM2inAcM50JPEpEKCdcMvP ex+/sXBY8J6YJbYvH+gs/Kf6UcLwP7JnOENNvk3BK3iRCimmSuztbTkE X-Gm-Gg: AZuq6aKlrT4PLENhakPrdtRjsMKeQ7yHfD+f+sfbLgbsXKnJa7CQg/U1mgSeLK6IH1T FK1U37YFLRayb9SNSv7+Sy1vXmeuRRoC8h9ik+1cnABy2txeBNaIu/Y+Hiez+RJw/a/+GCvqY0q PITRIFXl/rSAnkjkstQp2Y1ZF4Ml6+20aA41ewCX8PWpja41mQH+z0KF9RAnnddnemnMmSG98am MSzBZF+eU6ZnK0BOaV9LVwI9ZY+rEs2K5pdcOHRj/iidh3/Qvft2/E+ol1fK28Yy/G1zm14IEfg V+kyPmtnOyDHCIqgCH6ZC+Z3A8LmPDmA6D2e6F31s7+p7yabcBVXusyxTzfADWMAlzWedMO2bwh fSGu5fC3P98gDT3nDMbb8O78+8ZTLoLebIVg/+Emxp12xw7Mh5TTvRF070GHa0wTSi3E8lY0oZb xG0A540L1TShwts639X6BvW7MeHo/RrM+dKoHsBDqBBa5h+f+TmXFvBg== X-Received: by 2002:a05:6a00:4214:b0:81e:4476:f67c with SMTP id d2e1a72fcca58-826da8d7d54mr4957805b3a.3.1771769359725; Sun, 22 Feb 2026 06:09:19 -0800 (PST) Received: from localhost.localdomain ([103.235.0.244]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-826dd86c5c1sm5303487b3a.39.2026.02.22.06.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Feb 2026 06:09:19 -0800 (PST) From: Rio To: akpm@linux-foundation.org Cc: feng.tang@linux.alibaba.com, joel.granados@kernel.org, linux-kernel@vger.kernel.org, pmladek@suse.com, pnina.feder@mobileye.com, wangjinchao600@gmail.com, Rio Subject: [PATCHv2] kernel/panic: allocate taint string buffer dynamically Date: Sun, 22 Feb 2026 19:38:04 +0530 Message-ID: <20260222140804.22225-1-rioo.tsukatsukii@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260220151500.13585-1-rioo.tsukatsukii@gmail.com> References: <20260220151500.13585-1-rioo.tsukatsukii@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The buffer used to hold the taint string is statically allocated, which requires updating whenever a new taint flag is added. Instead, allocate the exact required length at boot once the allocator is available in an init function. The allocation sums the string lengths in taint_flags[], along with space for separators and formatting. print_tainted() is switched to use this dynamically allocated buffer. If allocation fails, print_tainted() warns about the failure and continues to use the original static buffer as a fallback. Signed-off-by: Rio --- V1 -> V2: Allocate taint string buffer dynamically during init v1: https://lore.kernel.org/all/20260220151500.13585-1-rioo.tsukatsukii@gma= il.com/ kernel/panic.c | 51 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/kernel/panic.c b/kernel/panic.c index 75368738d32d..5d498ff8a18b 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -802,7 +802,7 @@ EXPORT_SYMBOL(panic); * small shell script that prints the TAINT_FLAGS_COUNT bits of * /proc/sys/kernel/tainted. * - * Also, update TAINT_BUF_MAX below. + * Also, update INIT_TAINT_BUF_MAX below. */ const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] =3D { TAINT_FLAG(PROPRIETARY_MODULE, 'P', 'G'), @@ -856,17 +856,58 @@ static void print_tainted_seq(struct seq_buf *s, bool= verbose) } } =20 -/* 350 can accommodate all taint flags in verbose mode, with some headroom= */ -#define TAINT_BUF_MAX 350 +/* The initial buffer can accommodate all taint flags in verbose + * mode, with some headroom. Once the allocator is available, the + * exact size is allocated dynamically; the initial buffer remains + * as a fallback if allocation fails. + * + * The verbose taint string currently requires up to 327 characters. + */ +#define INIT_TAINT_BUF_MAX 350 + +static char init_taint_buf[INIT_TAINT_BUF_MAX]; +static char *taint_buf =3D init_taint_buf; +static size_t taint_buf_size =3D INIT_TAINT_BUF_MAX; + +static __init int alloc_taint_buf(void) +{ + int i; + char *buf; + size_t size =3D 0; + + size +=3D sizeof("Tainted: ") - 1; + for (i =3D 0; i < TAINT_FLAGS_COUNT; i++) { + size +=3D 2; /* For ", " */ + size +=3D 4; /* For "[%c]=3D" */ + size +=3D strlen(taint_flags[i].desc); + } + + size +=3D 1; /* For NULL terminator */ + + buf =3D kmalloc(size, GFP_KERNEL); + + if (!buf) { + /* Allocation may fail; this warning explains possibly + * truncated taint strings + */ + pr_warn_once("taint string buffer allocation failed, using fallback buff= er\n"); + return 0; + } + + taint_buf =3D buf; + taint_buf_size =3D size; + + return 0; +} +postcore_initcall(alloc_taint_buf); =20 static const char *_print_tainted(bool verbose) { - static char buf[TAINT_BUF_MAX]; struct seq_buf s; =20 BUILD_BUG_ON(ARRAY_SIZE(taint_flags) !=3D TAINT_FLAGS_COUNT); =20 - seq_buf_init(&s, buf, sizeof(buf)); + seq_buf_init(&s, taint_buf, taint_buf_size); =20 print_tainted_seq(&s, verbose); =20 --=20 2.52.0