From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 086C2C43219 for ; Tue, 22 Nov 2022 10:11:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=j3QaNpoxAOMxfej5eE8t2uUb+7VhJ2iJj2JPaTezg0Q=; b=agQHgCsMJpmKGc wNpQdTZS6nkmhoilclB85FnfZDG+tegiztr4ZNtZN+C6h1GsctC+/hNuUZQ4N95rFVrnZtQrWY2Oy HdNp4jVRi2Gd0bHvQ99RweSFSASlQj1MuHM9KiPmOcfGVsuE2ckYop5mWwkkW5sflZIbBIahycL2q nI4Pv6wbHMnnzHI7Swu/ohEx6NIgqrko5DXmKiqOvv3r9j2PuQk1m4kXMUXaF9hXviXLryDuqYN+h NfnlEBAkEZ/zVUTU5CBFxKXr2DJZDW9U71IqVU6XmPoACBD1bK1gBEjsWsBvnSkyfNhrpGdTAfvb3 IdrUtXShDcTzBAMWTSOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxQF9-007foS-Kc; Tue, 22 Nov 2022 10:11:07 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxQF1-007feO-4D for linux-um@lists.infradead.org; Tue, 22 Nov 2022 10:11:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=5tfpVPJ1YtcOfJWBR0RW/cEAjC/Z2ZT2HTKh6Nb2crs=; t=1669111858; x=1670321458; b=AiqOMlygUFS35PnqFFIi1Q/4jCSlhJICCtjma4E9ACgUVFo bCxBfDQDjpMDpguoO8kLzpWD35TDnnJ0qLZd/GJY1SXp7GzlEPRhDi7hT2zHQkCI0MHNd87Meb9Zu 7EVDZKLUcVW8yaW0Wv8noyD6gOOQtt1HLHOToDPTBB+u9QGDGfd6rDZoIgdS9cQRNKXyny9qZr/Dg f5soq6tQvH7EcSB5AaQ2Fb49kk47awlWDeqS8KjWCKPxk2F5Sgct14ByK7VMVIbq5FofeaE12HBPG 4NWlH33MG2eSG5l1sGumoiXrwt35HLWnJVmOBtQwR/QeG8bBw6UDiAh2bKh0KPXQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1oxQEn-006IGn-1h; Tue, 22 Nov 2022 11:10:45 +0100 From: benjamin@sipsolutions.net To: linux-um@lists.infradead.org Cc: Benjamin Berg Subject: [PATCH v2 06/28] um: Don't use vfprintf() for os_info() Date: Tue, 22 Nov 2022 11:07:37 +0100 Message-Id: <20221122100759.208290-7-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221122100759.208290-1-benjamin@sipsolutions.net> References: <20221122100759.208290-1-benjamin@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221122_021059_215968_2E465B4C X-CRM114-Status: GOOD ( 10.98 ) X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org From: Benjamin Berg 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 --- 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.38.1 _______________________________________________ linux-um mailing list linux-um@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-um