Skip to contentSkip to conversation

chmod of generated grub.cfg

DISCUSSION Felix Zielcke 5 participants 16 messages Sep 6, 2009 – Sep 10, 2009

lore
Share & tools
lore
#0 lore raw

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

Else I'd need to add a /etc/grub.d/999_chmod file in grub-installer which changes the mode of grub.cfg.new if the user wants to have a password.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer
#1 lore raw
Quoted 5 lines · Felix Zielcke

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

I'd prefer to see this done only if they set a password. A GRUB_CHMOD variable seems overkill, though.

Quoted 3 lines

Else I'd need to add a /etc/grub.d/999_chmod file in grub-installer which changes the mode of grub.cfg.new if the user wants to have a password.

I think it'd be more sensible to do this in grub-mkconfig itself - it doesn't really fit well into the /etc/grub.d/ hook system, which is really just for generating output.

Signature · 1 line
Colin Watson                                       [[email protected]]
#2 lore raw

Am Sonntag, den 06.09.2009, 14:38 +0100 schrieb Colin Watson:

Quoted 10 lines · Felix Zielcke
Quoted 5 lines

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

I'd prefer to see this done only if they set a password. A GRUB_CHMOD variable seems overkill, though.

Quoted 7 lines
Quoted 3 lines

Else I'd need to add a /etc/grub.d/999_chmod file in grub-installer which changes the mode of grub.cfg.new if the user wants to have a password.

I think it'd be more sensible to do this in grub-mkconfig itself - it doesn't really fit well into the /etc/grub.d/ hook system, which is really just for generating output.

You mean we check with grep if there's a password line in the generated config and then just use chmod 400 instead of 444?
Sounds good.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer
#3 lore raw
Quoted 8 lines · Felix Zielcke

Am Sonntag, den 06.09.2009, 14:38 +0100 schrieb Colin Watson:

Quoted 3 lines

I think it'd be more sensible to do this in grub-mkconfig itself - it doesn't really fit well into the /etc/grub.d/ hook system, which is really just for generating output.

You mean we check with grep if there's a password line in the generated config and then just use chmod 400 instead of 444?
Sounds good.

Yeah, that kind of thing.

Signature · 1 line
Colin Watson                                       [[email protected]]
#4 lore raw

Am Sonntag, den 06.09.2009, 14:57 +0100 schrieb Colin Watson:

Quoted 6 lines · Felix Zielcke
Quoted 5 lines

Am Sonntag, den 06.09.2009, 14:38 +0100 schrieb Colin Watson:

Quoted 3 lines

I think it'd be more sensible to do this in grub-mkconfig itself - it doesn't really fit well into the /etc/grub.d/ hook system, which is really just for generating output.

Quoted 6 lines
Quoted 3 lines

You mean we check with grep if there's a password line in the generated config and then just use chmod 400 instead of 444?
Sounds good.

Yeah, that kind of thing.

Ok here's now a patch.
Robert do you think this can go into 1.97?

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer

2009-09-06 Felix Zielcke <[email protected]>

* util/grub-mkconfig.in: Make generated config file mode 400 if it contains a password and print a warning if it fails.

grub-mkconfig.in +5 -0
Index: util/grub-mkconfig.in
===================================================================
@@ -260,6 +260,11 @@ for i in ${grub_mkconfig_dir}/* ; do
   esac
 done
 
+if [ "x${grub_cfg}" != "x" ] && grep -q "^password " ${grub_cfg}.new ; then
+  chmod 400 ${grub_cfg}.new || grub_warn "Could not make ${grub_cfg}.new readable by only root.\
+  This means your password is readable by everyone"
+fi
+
 if test "x${grub_cfg}" != "x" ; then
   # none of the children aborted with error, install the new grub.cfg
   mv -f ${grub_cfg}.new ${grub_cfg}
#5 lore raw
Quoted 3 lines · Felix Zielcke

Ok here's now a patch.
Robert do you think this can go into 1.97?

For 1.97 I'd be more comfortable with a simple s/444/400/. An automated check smells like it could have corner cases. In fact I found one:

grub-mkconfig.in for i in ${grub_mkconfig_dir}/* ; do · line 266

Quoted 8 lines
grub-mkconfig.in +4 -0
@@ -260,6 +260,11 @@ for i in ${grub_mkconfig_dir}/* ; do
   esac
 done
 
+if [ "x${grub_cfg}" != "x" ] && grep -q "^password " ${grub_cfg}.new ; then
+  chmod 400 ${grub_cfg}.new || grub_warn "Could not make ${grub_cfg}.new readable by only root.\
+  This means your password is readable by everyone"
+fi

There's a short time window in which /boot/grub/grub.cfg.new exists, has been fully generated, and its mode is 444 rather than 400. An attacker could poll this file and with some luck extract a password from it.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#6 lore raw

Am Sonntag, den 06.09.2009, 17:09 +0200 schrieb Robert Millan:

Quoted 12 lines · Felix Zielcke
Quoted 3 lines

Ok here's now a patch.
Robert do you think this can go into 1.97?

For 1.97 I'd be more comfortable with a simple s/444/400/. An automated check smells like it could have corner cases. In fact I found one:

Quoted 4 lines
(quoted diff) +0 -0
@@ -260,6 +260,11 @@ for i in ${grub_mkconfig_dir}/* ; do
   esac
 done
 
Quoted 9 lines

Review for i in ${grub_mkconfig_dir}/* ; do · line 266

Quoted 4 lines
(quoted diff) +4 -0
+if [ "x${grub_cfg}" != "x" ] && grep -q "^password " ${grub_cfg}.new ; then
+  chmod 400 ${grub_cfg}.new || grub_warn "Could not make ${grub_cfg}.new readable by only root.\
+  This means your password is readable by everyone"
+fi

There's a short time window in which /boot/grub/grub.cfg.new exists, has been fully generated, and its mode is 444 rather than 400. An attacker could poll this file and with some luck extract a password from it.

Oh right. So how about this?

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer

2009-09-06 Felix Zielcke <[email protected]>

* util/grub-mkconfig.in: Make the temporary created config mode 400 and print a warning if it fails. Change mode to 444 if it does not contain a plaintext password.

grub-mkconfig.in +6 -1
Index: util/grub-mkconfig.in
===================================================================
@@ -232,7 +232,8 @@ if test "x${grub_cfg}" != "x"; then
 
   # Allow this to fail, since /boot/grub/ might need to be fatfs to support some
   # firmware implementations (e.g. OFW or EFI).
-  chmod 444 ${grub_cfg}.new || true
+  chmod 400 ${grub_cfg}.new || grub_warn "Could not make ${grub_cfg}.new readable by only root.\
+  This means that if the generated config contains a password it is readable by everyone"
 fi
 echo "Generating grub.cfg ..." >&2
 
@@ -260,6 +261,10 @@ for i in ${grub_mkconfig_dir}/* ; do
   esac
 done
 
+if [ "x${grub_cfg}" != "x" ] && ! grep -q "^password " ${grub_cfg}.new ; then
+  chmod 444 ${grub_cfg}.new || true
+fi
+
 if test "x${grub_cfg}" != "x" ; then
   # none of the children aborted with error, install the new grub.cfg
   mv -f ${grub_cfg}.new ${grub_cfg}
#7 lore raw
Quoted 23 lines · Felix Zielcke

Am Sonntag, den 06.09.2009, 17:09 +0200 schrieb Robert Millan:

Quoted 12 lines · Felix Zielcke
Quoted 3 lines

Ok here's now a patch.
Robert do you think this can go into 1.97?

For 1.97 I'd be more comfortable with a simple s/444/400/. An automated check smells like it could have corner cases. In fact I found one:

Quoted 4 lines
(quoted diff) +0 -0
@@ -260,6 +260,11 @@ for i in ${grub_mkconfig_dir}/* ; do
   esac
 done
 
Quoted 9 lines

Review for i in ${grub_mkconfig_dir}/* ; do · line 266

Quoted 4 lines
(quoted diff) +4 -0
+if [ "x${grub_cfg}" != "x" ] && grep -q "^password " ${grub_cfg}.new ; then
+  chmod 400 ${grub_cfg}.new || grub_warn "Could not make ${grub_cfg}.new readable by only root.\
+  This means your password is readable by everyone"
+fi

There's a short time window in which /boot/grub/grub.cfg.new exists, has been fully generated, and its mode is 444 rather than 400. An attacker could poll this file and with some luck extract a password from it.

Quoted 1 line

Oh right. So how about this?

Ok.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#8 lore raw
In reply to Colin Watson
Quoted 3 lines · Colin Watson

A GRUB_CHMOD
variable seems overkill, though.

Yes. Please not a new config option just for this. Just pick a reasonable mode and set to it.

Auto-detection doesn't sound bad, although I'd be fine with just using 0400.

Quoted 7 lines
Quoted 3 lines

Else I'd need to add a /etc/grub.d/999_chmod file in grub-installer which changes the mode of grub.cfg.new if the user wants to have a password.

I think it'd be more sensible to do this in grub-mkconfig itself - it doesn't really fit well into the /etc/grub.d/ hook system, which is really just for generating output.

Agreed.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#9 lore raw
In reply to Colin Watson
Quoted 9 lines · Colin Watson
Quoted 5 lines · Felix Zielcke

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

I'd prefer to see this done only if they set a password. A GRUB_CHMOD variable seems overkill, though.

Is there a reason a non-root would like to look at grub.cfg on production system? Developers can always override chmod. If there is no real reason for non-root to look into grub.cfg I would follow the best friend in security considerations called "paranoia" and just use mode 400

Quoted 19 lines
Quoted 4 lines

Else I'd need to add a /etc/grub.d/999_chmod file in grub-installer which changes the mode of grub.cfg.new if the user wants to have a password.

I think it'd be more sensible to do this in grub-mkconfig itself - it doesn't really fit well into the /etc/grub.d/ hook system, which is really just for generating output.

--
Colin Watson                                       [[email protected]]

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#10 lore raw
Quoted 8 lines · Vladimir 'phcoder' Serbinenko
Quoted 7 lines · Colin Watson
Quoted 5 lines · Felix Zielcke

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

Quoted 7 lines
Quoted 2 lines

I'd prefer to see this done only if they set a password. A GRUB_CHMOD variable seems overkill, though.

Is there a reason a non-root would like to look at grub.cfg on production system? Developers can always override chmod. If there is no real reason for non-root to look into grub.cfg I would follow the best friend in security considerations called "paranoia" and just use mode 400

Shouldn't it be u+rw anyway, or 0600 ?

#11 lore raw

Am Sonntag, den 06.09.2009, 20:21 -0500 schrieb [email protected]:

Quoted 12 lines
Quoted 10 lines · Vladimir 'phcoder' Serbinenko
Quoted 9 lines · Colin Watson
Quoted 5 lines · Felix Zielcke

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

I'd prefer to see this done only if they set a password. A GRUB_CHMOD variable seems overkill, though.

Quoted 7 lines
Quoted 5 lines

Is there a reason a non-root would like to look at grub.cfg on production system? Developers can always override chmod. If there is no real reason for non-root to look into grub.cfg I would follow the best friend in security considerations called "paranoia" and just use mode 400

Shouldn't it be u+rw anyway, or 0600 ?

I don't think this would be good.
The next grub-mkconfig run would just overwrite your changes you made directly in grub.cfg
If any admin wants to do this nevertheless the warning at the top of it, then he can also just change the mode or use with vim for example `:w!'

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer
#12 lore raw
In reply to Vladimir 'phcoder' Serbinenko
Quoted 8 lines · Vladimir 'phcoder' Serbinenko
Quoted 7 lines · Colin Watson
Quoted 5 lines · Felix Zielcke

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

Quoted 7 lines
Quoted 2 lines

I'd prefer to see this done only if they set a password. A GRUB_CHMOD variable seems overkill, though.

Is there a reason a non-root would like to look at grub.cfg on production system? Developers can always override chmod. If there is no real reason for non-root to look into grub.cfg I would follow the best friend in security considerations called "paranoia" and just use mode 400

I like the idea of using 0400 right away, for simplicity.

OTOH, world-readable grub.cfg is useful, at least in Debian, because reportbug includes this file in bug reports.

But if it's only useful for Debian, we shouldn't let this change our agenda (ah, the conflict of wearing two hats...).

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#13 lore raw

Am Dienstag, den 08.09.2009, 16:48 +0200 schrieb Robert Millan:

Quoted 17 lines · Vladimir 'phcoder' Serbinenko
Quoted 8 lines · Colin Watson
Quoted 7 lines · Felix Zielcke
Quoted 5 lines

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

Quoted 7 lines
Quoted 2 lines

I'd prefer to see this done only if they set a password. A GRUB_CHMOD variable seems overkill, though.

Is there a reason a non-root would like to look at grub.cfg on production system? Developers can always override chmod. If there is no real reason for non-root to look into grub.cfg I would follow the best friend in security considerations called "paranoia" and just use mode 400

Quoted 8 lines

I like the idea of using 0400 right away, for simplicity.

OTOH, world-readable grub.cfg is useful, at least in Debian, because reportbug includes this file in bug reports.

But if it's only useful for Debian, we shouldn't let this change our agenda (ah, the conflict of wearing two hats...).

So in upstream we change it to 400 + warning and for Debian we use my last patch?

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer
#14 lore raw
Quoted 23 lines · Felix Zielcke

Am Dienstag, den 08.09.2009, 16:48 +0200 schrieb Robert Millan:

Quoted 22 lines · Vladimir 'phcoder' Serbinenko
Quoted 8 lines · Colin Watson
Quoted 7 lines · Felix Zielcke
Quoted 5 lines

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

Quoted 7 lines
Quoted 2 lines

I'd prefer to see this done only if they set a password. A GRUB_CHMOD variable seems overkill, though.

Is there a reason a non-root would like to look at grub.cfg on production system? Developers can always override chmod. If there is no real reason for non-root to look into grub.cfg I would follow the best friend in security considerations called "paranoia" and just use mode 400

I like the idea of using 0400 right away, for simplicity.

OTOH, world-readable grub.cfg is useful, at least in Debian, because reportbug includes this file in bug reports.

Quoted 6 lines
Quoted 3 lines

But if it's only useful for Debian, we shouldn't let this change our agenda (ah, the conflict of wearing two hats...).

So in upstream we change it to 400 + warning and for Debian we use my last patch?

Ok.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#15 lore raw

Am Donnerstag, den 10.09.2009, 20:56 +0200 schrieb Robert Millan:

Quoted 24 lines · Felix Zielcke
Quoted 23 lines

Am Dienstag, den 08.09.2009, 16:48 +0200 schrieb Robert Millan:

Quoted 22 lines · Vladimir 'phcoder' Serbinenko
Quoted 8 lines · Colin Watson
Quoted 7 lines · Felix Zielcke
Quoted 5 lines

Currently grub-mkconfig uses chmod 444 on the newly generated grub.cfg Wouldn't it be better to use 400 now that we have plaintext password support?
Or should we add support for a GRUB_CHMOD variable so users can override this setting as they please?

Quoted 7 lines
Quoted 2 lines

I'd prefer to see this done only if they set a password. A GRUB_CHMOD variable seems overkill, though.

Is there a reason a non-root would like to look at grub.cfg on production system? Developers can always override chmod. If there is no real reason for non-root to look into grub.cfg I would follow the best friend in security considerations called "paranoia" and just use mode 400

I like the idea of using 0400 right away, for simplicity.

OTOH, world-readable grub.cfg is useful, at least in Debian, because reportbug includes this file in bug reports.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

But if it's only useful for Debian, we shouldn't let this change our agenda (ah, the conflict of wearing two hats...).

So in upstream we change it to 400 + warning and for Debian we use my last patch?

Ok.

Ok commited.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer