Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ch9mB-0005cy-9t for mharc-grub-devel@gnu.org; Fri, 24 Feb 2017 01:54:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ch9m8-0005bR-Pl for grub-devel@gnu.org; Fri, 24 Feb 2017 01:54:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ch9m5-0005D1-H4 for grub-devel@gnu.org; Fri, 24 Feb 2017 01:54:44 -0500 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:35812) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ch9m5-0005Ce-AS for grub-devel@gnu.org; Fri, 24 Feb 2017 01:54:41 -0500 Received: by mail-lf0-x243.google.com with SMTP id z127so825764lfa.2 for ; Thu, 23 Feb 2017 22:54:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=cCCBBeF05ZpctQ1jFfaS+FKazmzmbIi328DPPQ7y/OE=; b=a3sIvK6DBP4CahEJbfgzVeuD7FCN6eddWj9/P519lN8MRDJMiwWxyPSiBHcyWcRmUE v8AESdICfFYBPBZsADts608M+8FgD0EbhxIWqPyUXd/jj/xXE6pysdybnuhG/uLE+AIb GkKHj/rNUCry/2dJSnAk3TpTJwqDpbManZqugCA+ZLb8G5gCspk+WpIUGqPCw761zJJm /Wqtb3qek129duTonCpom85p6UXBQ6+ph1Oht5xYLOWQ3gMDYUumVKBJbPZTtab4w+rD NA0yQ+UllHuptPFRSSew7I1+0/EE9mTQ3xd9o4bd2YCEyxgP43vnEkJfpQmFDWd89XdM 3POg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=cCCBBeF05ZpctQ1jFfaS+FKazmzmbIi328DPPQ7y/OE=; b=kV4lktwo5G/ZRcg7MtERJwM6P2oiSFrt0kHWeZtKrJ3y0g4DJmKL6fCuBycrCmUBO0 aHrBMhok+r5R/ue+yIBjflsTpAHSrLTNTVE71NFJyL43VPWQa6vf/1Js7qXdBNSv1kL1 iF8kZ68NxkegX9RS35N8crJ95wDGxOKA3AbZsv2WuqclO5rtq1smCr/N5O6ZBr25lH3z fJSrqjZSpabx3nmXRPLJCs/vTvpF6933mVW38V3Bj5npl8aKTcAhIfRHw8BkzLRFBxD5 kdXk6N+sLwvC0tdQUIwS4EqSACoaGpHEHAfEF55g9ZweUBpttGNACiGoy2LNe3KhWURh cOvw== X-Gm-Message-State: AMke39kOp9W5zcG+n/TpydPMEPHlWeE85A+oG0tB3fuhWDrbB2k3wHRyzNpiVxPUZpTFAA== X-Received: by 10.46.69.137 with SMTP id s131mr254737lja.71.1487919279832; Thu, 23 Feb 2017 22:54:39 -0800 (PST) Received: from localhost.localdomain (ppp109-252-90-129.pppoe.spdop.ru. [109.252.90.129]) by smtp.gmail.com with ESMTPSA id r18sm1823288lff.4.2017.02.23.22.54.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Feb 2017 22:54:39 -0800 (PST) From: Andrei Borzenkov To: grub-devel@gnu.org Cc: mchang@suse.com Subject: [PATCH RFC] efi/chainloader: build image path as single File Path Date: Fri, 24 Feb 2017 09:54:30 +0300 Message-Id: <1487919270-26971-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::243 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Feb 2017 06:54:46 -0000 According to EFI 9.3.6.4 File Path Media Device Path, Path Name is A NULL-terminated Path string including directory and file names. EFI chainloader is using two File Path nodes for image name - directory and file. It appears that at least some firmware implementations interpret NULL terminated directory path as end of full pathname, thus truncating it. OTOH leaving path names non-NULL terminated caused other errors (see commit ce95549cc54b5d6f494608a7c390dba3aab4fba7) Use single File Path node containing both directory and file name to avoid it. See also https://bugzilla.opensuse.org/show_bug.cgi?id=1026344 --- Anyone remembers why we build complete path using two nodes? As far as I can tell no other bootloader does it. I am really uneasy to do it now, but we have known bugs both with and without ce95549cc54b5d6f494608a7c390dba3aab4fba7 and this looks like the most straightforward fix. grub-core/loader/efi/chainloader.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index adc8563..329dd57 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -158,29 +158,23 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) d = GRUB_EFI_NEXT_DEVICE_PATH (d); } - /* File Path is NULL terminated. Allocate space for 2 extra characters */ - /* FIXME why we split path in two components? */ + /* File Path is NULL terminated. Allocate space for extra character */ file_path = grub_malloc (size - + ((grub_strlen (dir_start) + 2) + + ((grub_strlen (dir_start) + 1) * GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_efi_char16_t)) - + sizeof (grub_efi_file_path_device_path_t) * 2); + + sizeof (grub_efi_file_path_device_path_t)); if (! file_path) return 0; grub_memcpy (file_path, dp, size); - /* Fill the file path for the directory. */ + /* Fill the complete file path. */ d = (grub_efi_device_path_t *) ((char *) file_path + ((char *) d - (char *) dp)); grub_efi_print_device_path (d); copy_file_path ((grub_efi_file_path_device_path_t *) d, - dir_start, dir_end - dir_start); - - /* Fill the file path for the file. */ - d = GRUB_EFI_NEXT_DEVICE_PATH (d); - copy_file_path ((grub_efi_file_path_device_path_t *) d, - dir_end + 1, grub_strlen (dir_end + 1)); + dir_start, grub_strlen (dir_start)); /* Fill the end of device path nodes. */ d = GRUB_EFI_NEXT_DEVICE_PATH (d); -- tg: (2fb8cd2..) u/use-single-file-path-in-efi-chainloader (depends on: master)