Skip to content

Commit 236f9fe

Browse files
benzearichardweinberger
authored andcommitted
um: Don't use vfprintf() for os_info()
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>
1 parent 9e16fb9 commit 236f9fe

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

arch/um/os-Linux/util.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,38 @@ __uml_setup("quiet", quiet_cmd_param,
173173
"quiet\n"
174174
" Turns off information messages during boot.\n\n");
175175

176+
/*
177+
* The os_info/os_warn functions will be called by helper threads. These
178+
* have a very limited stack size and using the libc formatting functions
179+
* may overflow the stack.
180+
* So pull in the kernel vscnprintf and use that instead with a fixed
181+
* on-stack buffer.
182+
*/
183+
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
184+
176185
void os_info(const char *fmt, ...)
177186
{
187+
char buf[256];
178188
va_list list;
189+
int len;
179190

180191
if (quiet_info)
181192
return;
182193

183194
va_start(list, fmt);
184-
vfprintf(stderr, fmt, list);
195+
len = vscnprintf(buf, sizeof(buf), fmt, list);
196+
fwrite(buf, len, 1, stderr);
185197
va_end(list);
186198
}
187199

188200
void os_warn(const char *fmt, ...)
189201
{
202+
char buf[256];
190203
va_list list;
204+
int len;
191205

192206
va_start(list, fmt);
193-
vfprintf(stderr, fmt, list);
207+
len = vscnprintf(buf, sizeof(buf), fmt, list);
208+
fwrite(buf, len, 1, stderr);
194209
va_end(list);
195210
}

0 commit comments

Comments
 (0)