Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jEpxU-0000Cj-UQ for mharc-grub-devel@gnu.org; Thu, 19 Mar 2020 03:51:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35701) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEpxR-0000BF-K9 for grub-devel@gnu.org; Thu, 19 Mar 2020 03:51:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEpxO-0003yd-IG for grub-devel@gnu.org; Thu, 19 Mar 2020 03:51:11 -0400 Received: from m4a0072g.houston.softwaregrp.com ([15.124.2.130]:45768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1jEpxO-0003sA-AV for grub-devel@gnu.org; Thu, 19 Mar 2020 03:51:10 -0400 Received: FROM m4a0072g.houston.softwaregrp.com (15.120.17.147) BY m4a0072g.houston.softwaregrp.com WITH ESMTP; Thu, 19 Mar 2020 07:49:54 +0000 Received: from M9W0068.microfocus.com (2002:f79:bf::f79:bf) by M4W0335.microfocus.com (2002:f78:1193::f78:1193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Thu, 19 Mar 2020 07:48:41 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (15.124.72.11) by M9W0068.microfocus.com (15.121.0.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10 via Frontend Transport; Thu, 19 Mar 2020 07:48:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LIy9fGCFfKPnPvG21CZz5RIIr/XL7sXRt5xEJq+A4tzR+A2MbD7RWP6BCD48YAGkjJ/GKnZVwKPQdpWrr4AvNZQ8zZ3d4Hdg2TPlzGKslXTA0KcVdnRZt+KD03bYQXVXlQsPhvmWDkSu5JULvzelouEcyohS3FFICVncZIK30dtIz5QluQ8ZNxApmwtAGu5oKeJWTaPmTsnX6d0gYImEv6Tr+LkiyEMki3WsOfTYJvYhK9o0R1xYIKrS01rNKzLbpnjyUYoBxgnxcROu2zm+iMzgHp+uPDoKP+KXlr3SDaPylZlMFRPmFsNZFYoOnxl74s6AVFeS6WLnK8vcy/GI/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gtrkbVxhvR5ziPzGdqJGsdAJRunk67PJWLu+jM3GQLE=; b=h27x4lELMjmH88tuEQoZgjcgMFRY02WCGg9799LVY/JFZiW26FS4mbjAeKidP9pqFBRogRvgQIbf/dwdCjLarzfXYFJsZVEQT0fKLofvCyI1afGf0+TR6Cu8mbmBcJhpqeAnruf3EY4blTA4KFu9+lJVQiSXR04MmfjQYo/KstPIvzlc7ojKRv6lQqS1h+/cpg/fgejesaYhOTmjmtAMNFOFNXCBXpXt0RRven0K8g3fKwHN/nM9vXfrhWJka6I+cQ0bcYiyhbrOcAZeNIMNEprb79BeJJdzb/MvzwKhU44JyHj2eLX5aM06ZYfL3YCpCNSfRxN/5oQ+KDiMvuNqlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=MChang@suse.com; Received: from BY5PR18MB3140.namprd18.prod.outlook.com (2603:10b6:a03:1a1::17) by BY5PR18MB3155.namprd18.prod.outlook.com (2603:10b6:a03:1a6::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.22; Thu, 19 Mar 2020 07:48:40 +0000 Received: from BY5PR18MB3140.namprd18.prod.outlook.com ([fe80::a404:f256:fbe8:c2d]) by BY5PR18MB3140.namprd18.prod.outlook.com ([fe80::a404:f256:fbe8:c2d%4]) with mapi id 15.20.2814.025; Thu, 19 Mar 2020 07:48:40 +0000 Date: Thu, 19 Mar 2020 15:48:28 +0800 From: Michael Chang To: The development of GNU GRUB CC: Olaf Hering Subject: Re: [PATCH v1] fix kernel cmdline corruption Message-ID: <20200319074828.GA3325@mazu> References: <20200318111312.21684-1-olaf@aepfle.de> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20200318111312.21684-1-olaf@aepfle.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-ClientProxiedBy: HK2PR04CA0048.apcprd04.prod.outlook.com (2603:1096:202:14::16) To BY5PR18MB3140.namprd18.prod.outlook.com (2603:10b6:a03:1a1::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mazu (60.251.47.115) by HK2PR04CA0048.apcprd04.prod.outlook.com (2603:1096:202:14::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.20 via Frontend Transport; Thu, 19 Mar 2020 07:48:35 +0000 X-Originating-IP: [60.251.47.115] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 058ccd47-6bb6-4d83-1f14-08d7cbd9ee2b X-MS-TrafficTypeDiagnostic: BY5PR18MB3155: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-Forefront-PRVS: 0347410860 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4636009)(376002)(136003)(39860400002)(396003)(366004)(346002)(199004)(81166006)(2906002)(8676002)(6666004)(956004)(6916009)(86362001)(26005)(16526019)(6496006)(52116002)(55236004)(4326008)(8936002)(5660300002)(81156014)(66946007)(316002)(66476007)(66556008)(55016002)(1076003)(478600001)(186003)(9686003)(9576002)(33716001)(966005)(33656002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY5PR18MB3155; H:BY5PR18MB3140.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: suse.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EP8w78+6VdzNvVhhtRS6QmAhhx3qOActQcu7mRBzBDIb/L+02nrRecfrc52u+874tLj0c5joSH35AvLjok8+kSR+zH1X2fk8rQMsLaT5yUO7ky3X86S3TdbmA1jG78emdrMvDSsSIOXPwDqY70pfQnOPbq2QfCYS0v4fz4R6Y3FO5JUe6OaoHBgB/yxHSWvLATw5n2TvT+A4ewpih8xhPuuPdM6vVD0umWPL9f8Xuc1WP0C2rUW92GFro81dkMJcb/9opzgpvFzkhvWlZbqLRawaWN7XoIomriri3GQ+z4a9Bl6sg0bAfvDIsHRkO+7IPgsi84QN37MGuhfbF7zI9+/UVDNa3d/W08lY5A1aOTciw0FTuDERDhRnmvU4G+J9VOLDPEBhgycAQ3HOsGQ/HjLCFvRZ2anhYcOcEgDfwDhnlWXd5+n5plOXy+aes6uEHxVfS7zeVziIbLcw6FGaVM7kR6PRW48CPHdSzQPQ4wqfH4rL1+62glUYOlhbh9acOpGgrzO6wbT/kYiqL9u5Sw== X-MS-Exchange-AntiSpam-MessageData: IirTPEh3d4kkiTfOHLoRutphPtZHNFC7Ej64e6hD6gc7IioXuBnLBqJikWeOSG4++geDw4MM0323hriiBWv2CLCehJPYJjP8gyIi7BeUV19X38igoKdLipX1tYjLwOY0jK1grSE0leQaR7di/HP2kg== X-MS-Exchange-CrossTenant-Network-Message-Id: 058ccd47-6bb6-4d83-1f14-08d7cbd9ee2b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2020 07:48:40.1985 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: e9TVHR3+sLEmcYvbksYz8gbE3zr/09nJHzMA+UnxCZRdwGK0jRONyUKbVPeEHQ0K X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR18MB3155 X-OriginatorOrg: suse.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 15.124.2.130 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2020 07:51:15 -0000 Hi Olaf, The patch rang a bell to me and eventually I figured out that I had similar patch posted. https://lists.gnu.org/archive/html/grub-devel/2018-04/msg00038.html In short, the issue is not only in the fix itself, but also to take care and provide a measure to avoid incompatible grub.cfg before and after the patch. To recap, there were two options provided to deal with the compatibilty issue. 1. Introduce a shell variable to disable the change, whenever anything goes wrong. 2. Use readonly feature variable similar to $feature_menuentry_id that can be used to detect capability and apply settings accordingly, thus still fulfill the requirement of one grub.cfg can work for all versions IMHO. I am in favour of #2, but still they didn't seem to have upstream's consent yet. Thanks, Michael On Wed, Mar 18, 2020 at 12:13:12PM +0100, Olaf Hering wrote: > The functions grub_create_loader_cmdline and its sibling > grub_loader_cmdline_size add extra, unexpected characters to the kernel > cmdline. Both functions are supposed to copy each argv[] element > verbatim. It is up to the caller of the kernel command ('linux' for > example) to add desired quoting or escaping characters for the consumers > of the kernel command line. The built-in grub shell gives enough > opportunities to construct such argv[] elements. > > After this change, these arguments result in the following kernel cmdline: > > var='val' var="val" var=\'v1 v2\' var=\"v1 v2\" var=\\\"v1 v2\\\" x > var=val var=val var='v1 v2' var="v1 v2" var=\"v1 v2\" x > > Fixes commit 25953e10553dad2e378541a68686fc094603ec54 > > Signed-off-by: Olaf Hering > --- > grub-core/lib/cmdline.c | 58 ++++++++----------------------------------------- > 1 file changed, 9 insertions(+), 49 deletions(-) > > diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c > index ed0b149dc..b572a367f 100644 > --- a/grub-core/lib/cmdline.c > +++ b/grub-core/lib/cmdline.c > @@ -20,31 +20,6 @@ > #include > #include > > -static unsigned int check_arg (char *c, int *has_space) > -{ > - int space = 0; > - unsigned int size = 0; > - > - while (*c) > - { > - if (*c == '\\' || *c == '\'' || *c == '"') > - size++; > - else if (*c == ' ') > - space = 1; > - > - size++; > - c++; > - } > - > - if (space) > - size += 2; > - > - if (has_space) > - *has_space = space; > - > - return size; > -} > - > unsigned int grub_loader_cmdline_size (int argc, char *argv[]) > { > int i; > @@ -52,7 +27,7 @@ unsigned int grub_loader_cmdline_size (int argc, char *argv[]) > > for (i = 0; i < argc; i++) > { > - size += check_arg (argv[i], 0); > + size += grub_strlen(argv[i]); > size++; /* Separator space or NULL. */ > } > > @@ -66,36 +41,21 @@ grub_err_t > grub_create_loader_cmdline (int argc, char *argv[], char *buf, > grub_size_t size, enum grub_verify_string_type type) > { > - int i, space; > + int i; > unsigned int arg_size; > - char *c, *orig_buf = buf; > + char *orig_buf = buf; > > for (i = 0; i < argc; i++) > { > - c = argv[i]; > - arg_size = check_arg(argv[i], &space); > - arg_size++; /* Separator space or NULL. */ > + arg_size = grub_strlen(argv[i]); > > - if (size < arg_size) > + /* Separator space or NULL. */ > + if (size < arg_size + 1) > break; > > - size -= arg_size; > - > - if (space) > - *buf++ = '"'; > - > - while (*c) > - { > - if (*c == '\\' || *c == '\'' || *c == '"') > - *buf++ = '\\'; > - > - *buf++ = *c; > - c++; > - } > - > - if (space) > - *buf++ = '"'; > - > + grub_memcpy(buf, argv[i], arg_size); > + size -= arg_size + 1; > + buf += arg_size; > *buf++ = ' '; > } > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel