public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Benjamin Berg <benjamin@sipsolutions.net>,
	Richard Weinberger <richard@nod.at>,
	Sasha Levin <sashal@kernel.org>,
	anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net,
	linux-um@lists.infradead.org
Subject: [PATCH AUTOSEL 6.6 04/11] um: Don't use vfprintf() for os_info()
Date: Wed, 24 Jan 2024 09:28:47 -0500	[thread overview]
Message-ID: <20240124142907.1283546-4-sashal@kernel.org> (raw)
In-Reply-To: <20240124142907.1283546-1-sashal@kernel.org>

From: Benjamin Berg <benjamin@sipsolutions.net>

[ 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 <benjamin@sipsolutions.net>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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


  parent reply	other threads:[~2024-01-24 14:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24 14:28 [PATCH AUTOSEL 6.6 01/11] pinctrl: baytrail: Fix types of config value in byt_pin_config_set() Sasha Levin
2024-01-24 14:28 ` [PATCH AUTOSEL 6.6 02/11] leds: trigger: panic: Don't register panic notifier if creating the trigger failed Sasha Levin
2024-01-24 14:28 ` [PATCH AUTOSEL 6.6 03/11] um: Fix naming clash between UML and scheduler Sasha Levin
2024-01-24 14:28 ` Sasha Levin [this message]
2024-01-24 14:28 ` [PATCH AUTOSEL 6.6 05/11] um: net: Fix return type of uml_net_start_xmit() Sasha Levin
2024-01-24 14:28 ` [PATCH AUTOSEL 6.6 06/11] um: time-travel: fix time corruption Sasha Levin
2024-01-24 14:28 ` [PATCH AUTOSEL 6.6 07/11] i3c: master: cdns: Update maximum prescaler value for i2c clock Sasha Levin
2024-01-24 14:28 ` [PATCH AUTOSEL 6.6 08/11] riscv: Make XIP bootable again Sasha Levin
2024-01-24 14:28 ` [PATCH AUTOSEL 6.6 09/11] xen/gntdev: Fix the abuse of underlying struct page in DMA-buf import Sasha Levin
2024-01-24 14:28 ` [PATCH AUTOSEL 6.6 10/11] mfd: ti_am335x_tscadc: Fix TI SoC dependencies Sasha Levin
2024-01-24 14:28 ` [PATCH AUTOSEL 6.6 11/11] mailbox: arm_mhuv2: Fix a bug for mhuv2_sender_interrupt Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240124142907.1283546-4-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=benjamin@sipsolutions.net \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox