forked from pool/grub2
be3181b1eb
- VUL-0: grub2,shim: implement new SBAT method (bsc#1182057) * 0031-util-mkimage-Remove-unused-code-to-add-BSS-section.patch * 0032-util-mkimage-Use-grub_host_to_target32-instead-of-gr.patch * 0033-util-mkimage-Always-use-grub_host_to_target32-to-ini.patch * 0034-util-mkimage-Unify-more-of-the-PE32-and-PE32-header-.patch * 0035-util-mkimage-Reorder-PE-optional-header-fields-set-u.patch * 0036-util-mkimage-Improve-data_size-value-calculation.patch * 0037-util-mkimage-Refactor-section-setup-to-use-a-helper.patch * 0038-util-mkimage-Add-an-option-to-import-SBAT-metadata-i.patch * 0039-grub-install-common-Add-sbat-option.patch - Fix CVE-2021-20225 (bsc#1182262) * 0022-lib-arg-Block-repeated-short-options-that-require-an.patch - Fix CVE-2020-27749 (bsc#1179264) * 0024-kern-parser-Fix-resource-leak-if-argc-0.patch * 0025-kern-parser-Fix-a-memory-leak.patch * 0026-kern-parser-Introduce-process_char-helper.patch * 0027-kern-parser-Introduce-terminate_arg-helper.patch * 0028-kern-parser-Refactor-grub_parser_split_cmdline-clean.patch * 0029-kern-buffer-Add-variable-sized-heap-buffer.patch * 0030-kern-parser-Fix-a-stack-buffer-overflow.patch - Fix CVE-2021-20233 (bsc#1182263) * 0023-commands-menuentry-Fix-quoting-in-setparams_prefix.patch - Fix CVE-2020-25647 (bsc#1177883) * 0021-usb-Avoid-possible-out-of-bound-accesses-caused-by-m.patch - Fix CVE-2020-25632 (bsc#1176711) * 0020-dl-Only-allow-unloading-modules-that-are-not-depende.patch - Fix CVE-2020-27779, CVE-2020-14372 (bsc#1179265) (bsc#1175970) * 0001-include-grub-i386-linux.h-Include-missing-grub-types.patch * 0002-efi-Make-shim_lock-GUID-and-protocol-type-public.patch * 0003-efi-Return-grub_efi_status_t-from-grub_efi_get_varia.patch OBS-URL: https://build.opensuse.org/request/show/876326 OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=374
88 lines
2.8 KiB
Diff
88 lines
2.8 KiB
Diff
From 01df3544dd3ea226e2832735c0284fc6d9157347 Mon Sep 17 00:00:00 2001
|
|
From: Javier Martinez Canillas <javierm@redhat.com>
|
|
Date: Tue, 29 Sep 2020 14:08:55 +0200
|
|
Subject: [PATCH 20/46] dl: Only allow unloading modules that are not
|
|
dependencies
|
|
|
|
When a module is attempted to be removed its reference counter is always
|
|
decremented. This means that repeated rmmod invocations will cause the
|
|
module to be unloaded even if another module depends on it.
|
|
|
|
This may lead to a use-after-free scenario allowing an attacker to execute
|
|
arbitrary code and by-pass the UEFI Secure Boot protection.
|
|
|
|
While being there, add the extern keyword to some function declarations in
|
|
that header file.
|
|
|
|
Fixes: CVE-2020-25632
|
|
|
|
Reported-by: Chris Coulson <chris.coulson@canonical.com>
|
|
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
|
|
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
---
|
|
grub-core/commands/minicmd.c | 7 +++++--
|
|
grub-core/kern/dl.c | 9 +++++++++
|
|
include/grub/dl.h | 8 +++++---
|
|
3 files changed, 19 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c
|
|
index 6bbce3128..fa498931e 100644
|
|
--- a/grub-core/commands/minicmd.c
|
|
+++ b/grub-core/commands/minicmd.c
|
|
@@ -140,8 +140,11 @@ grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)),
|
|
if (grub_dl_is_persistent (mod))
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, "cannot unload persistent module");
|
|
|
|
- if (grub_dl_unref (mod) <= 0)
|
|
- grub_dl_unload (mod);
|
|
+ if (grub_dl_ref_count (mod) > 1)
|
|
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "cannot unload referenced module");
|
|
+
|
|
+ grub_dl_unref (mod);
|
|
+ grub_dl_unload (mod);
|
|
|
|
return 0;
|
|
}
|
|
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
|
|
index 2a8372e14..e02f2afc5 100644
|
|
--- a/grub-core/kern/dl.c
|
|
+++ b/grub-core/kern/dl.c
|
|
@@ -553,6 +553,15 @@ grub_dl_unref (grub_dl_t mod)
|
|
return --mod->ref_count;
|
|
}
|
|
|
|
+int
|
|
+grub_dl_ref_count (grub_dl_t mod)
|
|
+{
|
|
+ if (mod == NULL)
|
|
+ return 0;
|
|
+
|
|
+ return mod->ref_count;
|
|
+}
|
|
+
|
|
static void
|
|
grub_dl_flush_cache (grub_dl_t mod)
|
|
{
|
|
diff --git a/include/grub/dl.h b/include/grub/dl.h
|
|
index f03c03561..b3753c9ca 100644
|
|
--- a/include/grub/dl.h
|
|
+++ b/include/grub/dl.h
|
|
@@ -203,9 +203,11 @@ grub_dl_t EXPORT_FUNC(grub_dl_load) (const char *name);
|
|
grub_dl_t grub_dl_load_core (void *addr, grub_size_t size);
|
|
grub_dl_t EXPORT_FUNC(grub_dl_load_core_noinit) (void *addr, grub_size_t size);
|
|
int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod);
|
|
-void grub_dl_unload_unneeded (void);
|
|
-int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod);
|
|
-int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod);
|
|
+extern void grub_dl_unload_unneeded (void);
|
|
+extern int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod);
|
|
+extern int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod);
|
|
+extern int EXPORT_FUNC(grub_dl_ref_count) (grub_dl_t mod);
|
|
+
|
|
extern grub_dl_t EXPORT_VAR(grub_dl_head);
|
|
|
|
#ifndef GRUB_UTIL
|
|
--
|
|
2.26.2
|
|
|