zbyszek / rpms / grub2

Forked from rpms/grub2 5 years ago
Clone
e602a06
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d90546c
From: Michael Chang via Grub-devel <grub-devel@gnu.org>
d90546c
Date: Fri, 3 Dec 2021 16:13:28 +0800
d90546c
Subject: [PATCH] grub-mkconfig: restore umask for grub.cfg
d90546c
d90546c
Since commit:
d90546c
d90546c
  ab2e53c8a grub-mkconfig: Honor a symlink when generating configuration
d90546c
by grub-mkconfig
d90546c
d90546c
has inadvertently discarded umask for creating grub.cfg in the process
d90546c
of grub-mkconfig. The resulting wrong permission (0644) would allow
d90546c
unprivileged users to read grub's configuration file content. This
d90546c
presents a low confidentiality risk as grub.cfg may contain non-secured
d90546c
plain-text passwords.
d90546c
d90546c
This patch restores the missing umask and set the file mode of creation
d90546c
to 0600 preventing unprivileged access.
d90546c
d90546c
Fixes: CVE-2021-3981
d90546c
d90546c
Signed-off-by: Michael Chang <mchang@suse.com>
d90546c
---
d90546c
 util/grub-mkconfig.in | 2 ++
d90546c
 1 file changed, 2 insertions(+)
d90546c
d90546c
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
e622855
index f55339a3f6..520a672cd2 100644
d90546c
--- a/util/grub-mkconfig.in
d90546c
+++ b/util/grub-mkconfig.in
d90546c
@@ -311,7 +311,9 @@ and /etc/grub.d/* files or please file a bug report with
d90546c
     exit 1
d90546c
   else
d90546c
     # none of the children aborted with error, install the new grub.cfg
d90546c
+    oldumask=$(umask); umask 077
d90546c
     cat ${grub_cfg}.new > ${grub_cfg}
d90546c
+    umask $oldumask
d90546c
     rm -f ${grub_cfg}.new
d90546c
   fi
d90546c
 fi