All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Warn the user to edit environment block by grub-editenv
@ 2019-11-05  9:20 Michael Chang
  2019-11-05 11:49 ` Javier Martinez Canillas
  2019-11-05 11:58 ` Daniel Kiper
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Chang @ 2019-11-05  9:20 UTC (permalink / raw)
  To: grub-devel

The environment block is a preallocated 1024-byte file serves as persistent
storage for environment variables. It has its own format which is sensitive to
corruption if using editor doesn't know how to process it. Besides the editor
may inadvertantly change size allocation that could have it sparse the
filesystem which could lead to unexpected outcome.

This patch adds message in grubenv file to warn the user from editing it by
tools other than grub-editenv.

Signed-off-by: Michael Chang <mchang@suse.com>
---
 util/editenv.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/util/editenv.c b/util/editenv.c
index eb2d0c03a..ee4c9e53f 100644
--- a/util/editenv.c
+++ b/util/editenv.c
@@ -30,12 +30,14 @@
 #include <string.h>
 
 #define DEFAULT_ENVBLK_SIZE	1024
+#define GRUB_ENVBLK_MESSAGE	"# WARNING: Do not edit this file other than by "PACKAGE"-editenv\n"
 
 void
 grub_util_create_envblk_file (const char *name)
 {
   FILE *fp;
   char *buf;
+  char *pbuf;
   char *namenew;
 
   buf = xmalloc (DEFAULT_ENVBLK_SIZE);
@@ -46,9 +48,13 @@ grub_util_create_envblk_file (const char *name)
     grub_util_error (_("cannot open `%s': %s"), namenew,
 		     strerror (errno));
 
-  memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
-  memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#',
-          DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
+  pbuf = buf;
+  memcpy (pbuf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
+  pbuf += sizeof (GRUB_ENVBLK_SIGNATURE) - 1;
+  memcpy (pbuf, GRUB_ENVBLK_MESSAGE, sizeof (GRUB_ENVBLK_MESSAGE) - 1);
+  pbuf += sizeof (GRUB_ENVBLK_MESSAGE) - 1;
+  memset (pbuf , '#',
+          DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) - sizeof (GRUB_ENVBLK_MESSAGE) + 2);
 
   if (fwrite (buf, 1, DEFAULT_ENVBLK_SIZE, fp) != DEFAULT_ENVBLK_SIZE)
     grub_util_error (_("cannot write to `%s': %s"), namenew,
-- 
2.16.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Warn the user to edit environment block by grub-editenv
  2019-11-05  9:20 [PATCH] Warn the user to edit environment block by grub-editenv Michael Chang
@ 2019-11-05 11:49 ` Javier Martinez Canillas
  2019-11-07  8:48   ` Michael Chang
  2019-11-05 11:58 ` Daniel Kiper
  1 sibling, 1 reply; 4+ messages in thread
From: Javier Martinez Canillas @ 2019-11-05 11:49 UTC (permalink / raw)
  To: The development of GNU GRUB, Michael Chang

Hello Michael,

On 11/5/19 10:20 AM, Michael Chang wrote:
> The environment block is a preallocated 1024-byte file serves as persistent
> storage for environment variables. It has its own format which is sensitive to
> corruption if using editor doesn't know how to process it. Besides the editor
> may inadvertantly change size allocation that could have it sparse the
> filesystem which could lead to unexpected outcome.
>

Yes, we also get reports about this issue: https://bugzilla.redhat.com/show_bug.cgi?id=1625124
 
> This patch adds message in grubenv file to warn the user from editing it by
> tools other than grub-editenv.
> 

Agreed that users should be warned that the file should only be edited with
the GRUB tools.

I also wonder if grub-editenv can't be made more robust and correct a grubenv
file (i.e: filling the missing # characters / removing any extra # character)
if is found to be corrupted and not having the expected size.

> Signed-off-by: Michael Chang <mchang@suse.com>
> ---
>  util/editenv.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 

The patch looks good to me.

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

Best regards,
-- 
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Warn the user to edit environment block by grub-editenv
  2019-11-05  9:20 [PATCH] Warn the user to edit environment block by grub-editenv Michael Chang
  2019-11-05 11:49 ` Javier Martinez Canillas
@ 2019-11-05 11:58 ` Daniel Kiper
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Kiper @ 2019-11-05 11:58 UTC (permalink / raw)
  To: Michael Chang; +Cc: grub-devel

On Tue, Nov 05, 2019 at 09:20:22AM +0000, Michael Chang wrote:
> The environment block is a preallocated 1024-byte file serves as persistent
> storage for environment variables. It has its own format which is sensitive to
> corruption if using editor doesn't know how to process it. Besides the editor
> may inadvertantly change size allocation that could have it sparse the
> filesystem which could lead to unexpected outcome.
>
> This patch adds message in grubenv file to warn the user from editing it by
> tools other than grub-editenv.
>
> Signed-off-by: Michael Chang <mchang@suse.com>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Warn the user to edit environment block by grub-editenv
  2019-11-05 11:49 ` Javier Martinez Canillas
@ 2019-11-07  8:48   ` Michael Chang
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Chang @ 2019-11-07  8:48 UTC (permalink / raw)
  To: Javier Martinez Canillas; +Cc: The development of GNU GRUB

On Tue, Nov 05, 2019 at 12:49:08PM +0100, Javier Martinez Canillas wrote:
> Hello Michael,
> 
> On 11/5/19 10:20 AM, Michael Chang wrote:
> > The environment block is a preallocated 1024-byte file serves as persistent
> > storage for environment variables. It has its own format which is sensitive to
> > corruption if using editor doesn't know how to process it. Besides the editor
> > may inadvertantly change size allocation that could have it sparse the
> > filesystem which could lead to unexpected outcome.
> >
> 
> Yes, we also get reports about this issue: https://bugzilla.redhat.com/show_bug.cgi?id=1625124
>  
> > This patch adds message in grubenv file to warn the user from editing it by
> > tools other than grub-editenv.
> > 
> 
> Agreed that users should be warned that the file should only be edited with
> the GRUB tools.
> 
> I also wonder if grub-editenv can't be made more robust and correct a grubenv
> file (i.e: filling the missing # characters / removing any extra # character)
> if is found to be corrupted and not having the expected size.

IMHO when people trying to read grubenv file they didn't expect the
sanitization from happening, as that might be troublesome to describe
problem if anyone wants to troubleshoot issue related to malformed
grubenv which is just victim of filesystem corruption and like.

I personally wouldn't mind if the function is provided as separate
command and backup original file somewhere ..

> 
> > Signed-off-by: Michael Chang <mchang@suse.com>
> > ---
> >  util/editenv.c | 12 +++++++++---
> >  1 file changed, 9 insertions(+), 3 deletions(-)
> > 
> 
> The patch looks good to me.
> 
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

Thanks a lot for your feedback and review. :)

Regards,
Michael

> 
> Best regards,
> -- 
> Javier Martinez Canillas
> Software Engineer - Desktop Hardware Enablement
> Red Hat


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-07  8:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05  9:20 [PATCH] Warn the user to edit environment block by grub-editenv Michael Chang
2019-11-05 11:49 ` Javier Martinez Canillas
2019-11-07  8:48   ` Michael Chang
2019-11-05 11:58 ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.