From patchwork Tue Nov 21 20:15:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13463535 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 21B77C61D85 for ; Tue, 21 Nov 2023 20:16:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.638183.994539 (Exim 4.92) (envelope-from ) id 1r5XAA-0007zR-8S; Tue, 21 Nov 2023 20:16:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 638183.994539; Tue, 21 Nov 2023 20:16:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5XAA-0007zE-4h; Tue, 21 Nov 2023 20:16:02 +0000 Received: by outflank-mailman (input) for mailman id 638183; Tue, 21 Nov 2023 20:16:01 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5XA9-0007Bx-0j for xen-devel@lists.xenproject.org; Tue, 21 Nov 2023 20:16:01 +0000 Received: from esa6.hc3370-68.iphmx.com (esa6.hc3370-68.iphmx.com [216.71.155.175]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c8d1d8ff-88aa-11ee-9b0e-b553b5be7939; Tue, 21 Nov 2023 21:15:59 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c8d1d8ff-88aa-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1700597759; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nNPFHrgxp9pbQ7IeeSDyd3YSSCnHXwpkDDz03xLZZ0Y=; b=eszsf461HSGmtNP+BXu+7/JC0U6e1ftnH+KNlIYDk5NOQfcSjk70uRpf lRb2/NE/OiaQmRkrXWIkYFhdJgBeCn+kbHouusn4Iqes1En2crjemE8nl GF8d+2M1IKXjO6dtPnFJHsbQm9e8v/S/7F9nXSMtMOvWJzlMChgXXGQws 4=; X-CSE-ConnectionGUID: BxdPn14FSKGZsTscOECGPg== X-CSE-MsgGUID: mpsQ+mzbStynQezYRkbRFQ== Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 127464603 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.159.70 X-Policy: $RELAYED X-ThreatScanner-Verdict: Negative IronPort-Data: A9a23:GBbuEq2dKvZbLGtYufbD5TVxkn2cJEfYwER7XKvMYLTBsI5bpzACy mocD2+HP/uDamT2fdt1aozn9UMO7JXUx9RhQQc+pC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliOfQAOK6UbaYUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8teTb9HuDgNyo4GlD5wVkPKgR1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfK3FCz fpBdB42TT+xnN6ty5WWYcZUiZF2RCXrFNt3VnBIyDjYCbAtQIzZQrW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6KPeGxPd5xcGXzZOxrtn0W WtqX2y2oyT99+61zrV3Cvr741bndvnxp95CMPksLlZFhzcziipeaFoUPm6vCk4peGp5BIRjd HQvw1IBbU+11rhOk+0vD7k0E3YyzAs53X+oGXoyEfLkIjWRC8eA8EEvJlecRfS9g4BsbhHoe p29lPcmZpLKBvK2B3n4dvFXQwvr0KooBMZ4KUupk0acYwDbLRW6awzlXkla6vpVErBmf0a+K MHNrCh2N9mNXWHcn/dtm5shPilXnE2FhDueCI/hvA= X-Talos-CUID: 9a23:CErM2G914nEtJqSshCSVv2QEFvgjKyHz91T/EVSEEm1OZZa6cVDFrQ== X-Talos-MUID: 9a23:jOKeQQuah1bq4WNNzc2ngSl5DYRt8a6VFFELqJgUivOHPxZeAmLI X-IronPort-AV: E=Sophos;i="6.04,216,1695700800"; d="scan'208";a="127464603" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Roberto Bagnara , Nicola Vetrini Subject: [PATCH v2 2/5] x86/setup: Rework cmdline_cook() to be compatible with -Wwrite-strings Date: Tue, 21 Nov 2023 20:15:37 +0000 Message-ID: <20231121201540.1528161-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231121201540.1528161-1-andrew.cooper3@citrix.com> References: <20231121201540.1528161-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Rework the logic in __start_xen() to not potentially pass NULL into cmdline_cook(). This makes the logic easier to follow too, and the rest of __start_xen() is safe when initialising cmdline to the empty string. Update cmdline_cook() to take and return const pointers, and write a description of what it does. It now requires a non-NULL input and guarentees to return a pointer somewhere in the 'p' string. Note this only compiles because strstr() launders the const off the pointer when assigning to the mutable kextra, but that logic only mutates the mbi->cmdline buffer. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Roberto Bagnara CC: Nicola Vetrini v2: * create_dom0() changes split out into a previous patch * Remove the logic for a NULL input, now that all callers have been adjusted --- xen/arch/x86/setup.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index c0302c6bdd62..b171a8f4cf84 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -837,10 +837,15 @@ static bool __init loader_is_grub2(const char *loader_name) return (p != NULL) && (p[5] != '0'); } -static char * __init cmdline_cook(char *p, const char *loader_name) +/* + * Clean up a command line string passed to us by a bootloader. Strip leading + * whitespace, and optionally strip the first parameter if our divination of + * the bootloader suggests that it prepended the image name. + * + * Always returns a pointer within @p. + */ +static const char *__init cmdline_cook(const char *p, const char *loader_name) { - p = p ? : ""; - /* Strip leading whitespace. */ while ( *p == ' ' ) p++; @@ -969,8 +974,8 @@ static struct domain *__init create_dom0(const module_t *image, /* SAF-1-safe */ void __init noreturn __start_xen(unsigned long mbi_p) { - const char *memmap_type = NULL, *loader; - char *cmdline, *kextra; + const char *memmap_type = NULL, *loader, *cmdline = ""; + char *kextra; void *bsp_stack; struct cpu_info *info = get_cpu_info(), *bsp_info; unsigned int initrdidx, num_parked = 0; @@ -1025,9 +1030,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) : "unknown"; /* Parse the command-line options. */ - cmdline = cmdline_cook((mbi->flags & MBI_CMDLINE) ? - __va(mbi->cmdline) : NULL, - loader); + if ( mbi->flags & MBI_CMDLINE ) + cmdline = cmdline_cook(__va(mbi->cmdline), loader); + if ( (kextra = strstr(cmdline, " -- ")) != NULL ) { /*