All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org
Cc: Daniel Kiper <dkiper@net-space.pl>,
	Glenn Washburn <development@efficientek.com>
Subject: [PATCH] loopback: Do not automaticaly replace existing loopback dev, error instead
Date: Fri, 27 Nov 2020 02:36:24 -0600	[thread overview]
Message-ID: <20201127083624.3482953-2-development@efficientek.com> (raw)
In-Reply-To: <20201127083624.3482953-1-development@efficientek.com>

If there is a loopback device with the same name as the one to be created,
instead of closing the old one and replacing it with the new one, return an
error instead. If the loopback device was created, its probably being used
by something and just replacing it may cause grub to loop forever. This
fixes obvious problems like `loopback d (d)/somefile'. Its not too onerous
to force the user to delete the loopback first with the `-d' switch.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/disk/loopback.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c
index 0f58d8622..d77584855 100644
--- a/grub-core/disk/loopback.c
+++ b/grub-core/disk/loopback.c
@@ -98,18 +98,13 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
   if (! file)
     return grub_errno;
 
-  /* First try to replace the old device.  */
+  /* Check that a device with requested name does not already exist.  */
   for (newdev = loopback_list; newdev; newdev = newdev->next)
     if (grub_strcmp (newdev->devname, args[0]) == 0)
-      break;
-
-  if (newdev)
-    {
-      grub_file_close (newdev->file);
-      newdev->file = file;
-
-      return 0;
-    }
+      {
+	ret = grub_error(GRUB_ERR_BAD_ARGUMENT, "device name already exists");
+	goto fail;
+      }
 
   /* Unable to replace it, make a new entry.  */
   newdev = grub_malloc (sizeof (struct grub_loopback));
-- 
2.27.0



  reply	other threads:[~2020-11-27  8:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27  8:36 [PATCH] disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h Glenn Washburn
2020-11-27  8:36 ` Glenn Washburn [this message]
2020-12-02 14:36   ` [PATCH] loopback: Do not automaticaly replace existing loopback dev, error instead Daniel Kiper
2020-12-04 11:45     ` Glenn Washburn
2020-11-30 14:42 ` [PATCH] disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h Daniel Kiper
2020-12-01  5:15   ` Glenn Washburn
2020-12-01  5:16 ` [PATCH v2] " Glenn Washburn
2020-12-02 14:28   ` Daniel Kiper
2020-12-04  1:57 ` [PATCH v2] loopback: Do not automaticaly replace existing loopback dev, error instead Glenn Washburn
2020-12-04 12:34   ` Daniel Kiper
2020-12-08  4:52     ` Glenn Washburn
2020-12-10 16:55       ` Daniel Kiper
2020-12-11 22:36         ` Glenn Washburn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201127083624.3482953-2-development@efficientek.com \
    --to=development@efficientek.com \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.