From: benjamin@sipsolutions.net
To: linux-um@lists.infradead.org
Cc: Benjamin Berg <benjamin@sipsolutions.net>
Subject: [PATCH v3 04/11] um: Don't use vfprintf() for os_info()
Date: Fri, 10 Nov 2023 12:03:41 +0100 [thread overview]
Message-ID: <20231110110348.1815612-5-benjamin@sipsolutions.net> (raw)
In-Reply-To: <20231110110348.1815612-1-benjamin@sipsolutions.net>
From: Benjamin Berg <benjamin@sipsolutions.net>
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>
---
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.41.0
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
next prev parent reply other threads:[~2023-11-10 11:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 11:03 [PATCH v3 00/11] General cleanups and fixes from SECCOMP patchset benjamin
2023-11-10 11:03 ` [PATCH v3 01/11] um: Drop support for hosts without SYSEMU_SINGLESTEP support benjamin
2023-11-10 11:03 ` [PATCH v3 02/11] um: Drop NULL check from start_userspace benjamin
2023-11-10 11:03 ` [PATCH v3 03/11] um: Make errors to stop ptraced child fatal during startup benjamin
2023-11-10 11:03 ` benjamin [this message]
2024-01-04 22:37 ` [PATCH v3 04/11] um: Don't use vfprintf() for os_info() Richard Weinberger
2024-01-05 8:12 ` Benjamin Berg
2024-01-05 8:56 ` Johannes Berg
2024-01-05 9:16 ` Richard Weinberger
2023-11-10 11:03 ` [PATCH v3 05/11] um: Do not use printk in SIGWINCH helper thread benjamin
2023-11-10 11:03 ` [PATCH v3 06/11] um: Reap winch thread if it fails benjamin
2023-11-10 11:03 ` [PATCH v3 07/11] um: Do not use printk in userspace trampoline benjamin
2023-11-10 11:03 ` [PATCH v3 08/11] um: Always inline stub functions benjamin
2023-11-10 11:03 ` [PATCH v3 09/11] um: Rely on PTRACE_SETREGSET to set FS/GS base registers benjamin
2024-01-04 23:05 ` Richard Weinberger
2024-01-04 23:34 ` Richard Weinberger
2024-01-05 9:54 ` Benjamin Berg
2024-01-05 13:29 ` Richard Weinberger
2023-11-10 11:03 ` [PATCH v3 10/11] um: Remove unused register save/restore functions benjamin
2023-11-10 11:03 ` [PATCH v3 11/11] um: Mark 32bit syscall helpers as clobbering memory benjamin
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=20231110110348.1815612-5-benjamin@sipsolutions.net \
--to=benjamin@sipsolutions.net \
--cc=linux-um@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.