1 Star 0 Fork 98

zjut_zy/grub2

forked from 余诗/grub2 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0186-Allow-chainloading-EFI-apps-from-loop-mounts.patch 4.03 KB
一键复制 编辑 原始数据 按行查看 历史
zhangqiumiao 提交于 2022-03-07 17:05 . update to version 2.06
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dimitri John Ledkov <[email protected]>
Date: Fri, 11 Jun 2021 13:51:20 +0200
Subject: [PATCH] Allow chainloading EFI apps from loop mounts.
Signed-off-by: Dimitri John Ledkov <[email protected]>
Signed-off-by: Robbie Harwood <[email protected]>
---
grub-core/disk/loopback.c | 9 +--------
grub-core/loader/efi/chainloader.c | 23 +++++++++++++++++++++++
include/grub/loopback.h | 30 ++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 8 deletions(-)
create mode 100644 include/grub/loopback.h
diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c
index 41bebd14fe3..99f47924ec2 100644
--- a/grub-core/disk/loopback.c
+++ b/grub-core/disk/loopback.c
@@ -21,20 +21,13 @@
#include <grub/misc.h>
#include <grub/file.h>
#include <grub/disk.h>
+#include <grub/loopback.h>
#include <grub/mm.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
GRUB_MOD_LICENSE ("GPLv3+");
-struct grub_loopback
-{
- char *devname;
- grub_file_t file;
- struct grub_loopback *next;
- unsigned long id;
-};
-
static struct grub_loopback *loopback_list;
static unsigned long last_id = 0;
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
index d41e8ea14a8..3af6b122926 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -24,6 +24,7 @@
#include <grub/err.h>
#include <grub/device.h>
#include <grub/disk.h>
+#include <grub/loopback.h>
#include <grub/misc.h>
#include <grub/charset.h>
#include <grub/mm.h>
@@ -901,6 +902,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
grub_efi_status_t status;
grub_efi_boot_services_t *b;
grub_device_t dev = 0;
+ grub_device_t orig_dev = 0;
grub_efi_device_path_t *dp = 0;
char *filename;
void *boot_image = 0;
@@ -958,6 +960,15 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
if (! dev)
goto fail;
+ /* if device is loopback, use underlying dev */
+ if (dev->disk->dev->id == GRUB_DISK_DEVICE_LOOPBACK_ID)
+ {
+ struct grub_loopback *d;
+ orig_dev = dev;
+ d = dev->disk->data;
+ dev = d->file->device;
+ }
+
if (dev->disk)
dev_handle = grub_efidisk_get_device_handle (dev->disk);
else if (dev->net && dev->net->server)
@@ -1065,6 +1076,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
}
#endif
+ if (orig_dev)
+ {
+ dev = orig_dev;
+ orig_dev = 0;
+ }
+
rc = grub_linuxefi_secure_validate((void *)(unsigned long)address, fsize);
grub_dprintf ("chain", "linuxefi_secure_validate: %d\n", rc);
if (rc > 0)
@@ -1087,6 +1104,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
// -1 fall-through to fail
fail:
+ if (orig_dev)
+ {
+ dev = orig_dev;
+ orig_dev = 0;
+ }
+
if (dev)
grub_device_close (dev);
diff --git a/include/grub/loopback.h b/include/grub/loopback.h
new file mode 100644
index 00000000000..3b9a9e32e80
--- /dev/null
+++ b/include/grub/loopback.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LOOPBACK_HEADER
+#define GRUB_LOOPBACK_HEADER 1
+
+struct grub_loopback
+{
+ char *devname;
+ grub_file_t file;
+ struct grub_loopback *next;
+ unsigned long id;
+};
+
+#endif /* ! GRUB_LOOPBACK_HEADER */
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zjuzy/grub2.git
[email protected]:zjuzy/grub2.git
zjuzy
grub2
grub2
master

搜索帮助