Blame SOURCES/0224-grub-mkconfig-restore-umask-for-grub.cfg.patch

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