From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 96EF93C2F; Wed, 21 Feb 2024 13:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708522824; cv=none; b=t/Q7Rn1YnptmEwWBm/lnTzflhdHf6tUDd+kWfyy4qJoPJzUdpJunyClBkZv8XNQ40irr5H9nDjMRhEb4mpGsbU+4eKfyMjQo45p/sHTbY1Eo11eaZktssRddDelbmANdZidxD0vHUbEjiljUyWBMVzhUOw+a8VhxZvRS9pXqnmg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708522824; c=relaxed/simple; bh=3rG0mKqVoK37sMHRWpg5l51Uc4MBSijRYqEYKB/Fr+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KHGJrUtCgqpXrl0v7FxIsz9XrhhYVte2fb034PYy8zaFn2HnMjiY6ANg6vxyR8RQmL1ii6YNUjlGSABlnqP+/LCze2MUMnm892LV3WInR2dkcrQqk7NnZgjT7YEOPmGUkBgwG2QYt+Ax2uCHL74rWzz9/IBdsh1z/3TxpZ9paUE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DRf8R6zj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="DRf8R6zj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9B66C433F1; Wed, 21 Feb 2024 13:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708522824; bh=3rG0mKqVoK37sMHRWpg5l51Uc4MBSijRYqEYKB/Fr+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DRf8R6zja48yoZkXaFSpQLhVYtxnDNORCQc0D8WZ15tQ9oRe03HcfbPKXnnO53pjW fvUX4AJ9kRfUmYXAp8QDHPJGFgyquzEVHbtAy6u9gue3zBlBnAA3gbNYiU83C0ajt8 TAjiLSPZYK8nLAAABycX7RW5RH5tAPyZRibvDgMg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Benjamin Berg , Richard Weinberger , Sasha Levin Subject: [PATCH 5.15 242/476] um: Dont use vfprintf() for os_info() Date: Wed, 21 Feb 2024 14:04:53 +0100 Message-ID: <20240221130016.819595739@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221130007.738356493@linuxfoundation.org> References: <20240221130007.738356493@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Berg [ Upstream commit 236f9fe39b02c15fa5530b53e9cca48354394389 ] The threads allocated inside the kernel have only a single page of stack. Unfortunately, the vfprintf function in standard glibc may use too much stack-space, overflowing it. To make os_info safe to be used by helper threads, use the kernel vscnprintf function into a smallish buffer and write out the information to stderr. Signed-off-by: Benjamin Berg Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin --- arch/um/os-Linux/util.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/um/os-Linux/util.c b/arch/um/os-Linux/util.c index fc0f2a9dee5a..1dca4ffbd572 100644 --- a/arch/um/os-Linux/util.c +++ b/arch/um/os-Linux/util.c @@ -173,23 +173,38 @@ __uml_setup("quiet", quiet_cmd_param, "quiet\n" " Turns off information messages during boot.\n\n"); +/* + * The os_info/os_warn functions will be called by helper threads. These + * have a very limited stack size and using the libc formatting functions + * may overflow the stack. + * So pull in the kernel vscnprintf and use that instead with a fixed + * on-stack buffer. + */ +int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); + void os_info(const char *fmt, ...) { + char buf[256]; va_list list; + int len; if (quiet_info) return; va_start(list, fmt); - vfprintf(stderr, fmt, list); + len = vscnprintf(buf, sizeof(buf), fmt, list); + fwrite(buf, len, 1, stderr); va_end(list); } void os_warn(const char *fmt, ...) { + char buf[256]; va_list list; + int len; va_start(list, fmt); - vfprintf(stderr, fmt, list); + len = vscnprintf(buf, sizeof(buf), fmt, list); + fwrite(buf, len, 1, stderr); va_end(list); } -- 2.43.0