From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kl0MB-0002wU-Jm for mharc-grub-devel@gnu.org; Thu, 03 Dec 2020 20:57:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kl0M9-0002vV-8y for grub-devel@gnu.org; Thu, 03 Dec 2020 20:57:57 -0500 Received: from mail-qv1-xf44.google.com ([2607:f8b0:4864:20::f44]:41866) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kl0M7-00053S-0L for grub-devel@gnu.org; Thu, 03 Dec 2020 20:57:56 -0500 Received: by mail-qv1-xf44.google.com with SMTP id x13so2073740qvk.8 for ; Thu, 03 Dec 2020 17:57:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8qun0iFQO9eSbuDokJhLDv+IA9caJDOC3wvQmU+sMr8=; b=YcMkBIsqzNNXbE1g8p55+kPfKzzeua1EqLHOVkzCBirit1hUhhwHtVLTP8lwD9D8yW Ag0+JU+OP8tCFdUY70l9I6jNAudktg4BC4pZKnR9edWU4Ii097bNLPzXU09H7thhLVyV vLFdEYFAfpEoLzpZ05kzt+jPILnR+JByxxMaOvj3cwAiEeHath35KZFLLgYvoytGXj9G gz+kgUDLxlRHYRNDrWRfvWnc9Ek0zDo7np3UQnP1CeOHkHLpwJVPYAV1mR4JKeEfmpBV kC+V4zchpTpECocUUgSVY6pG2xaQrC+TxfiYBBy46Iv6EQ8DUNi8utIt1HCNKCeC0yBN zhLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8qun0iFQO9eSbuDokJhLDv+IA9caJDOC3wvQmU+sMr8=; b=ZL04IzY5aWkSm5lSn/O1yV58AHRIlaMy+fitkjrhUjTupgvFeioJKpEZLIr13/eqHk pHz7ONGRxBN5RV2sseW+j2cDn3Q4K3kV7xaRWEeDBB0ENzPe4evDhII4/28joyHmBRT/ 8DUcmrNfu5fxScJnfpuIRFgtEnZRxL/fL2frk3rNaQZiEzw9h4Cr7hzDmJBVx7rTM34m UBLejwImf3TPpuGEZW0X7irb42AoP+VoxfXYChtDf4nBt8kPlKbuPttffLo1KObJKVsI pT9EbNOu8WOeNk1O3f+9vd3UTNGvRYUwJQEfdEBXnp3uyfHhKzgGztYLrmN0OpT+3EuH DLvQ== X-Gm-Message-State: AOAM533nrymAAthCld7D0h8s4UuMvarLCzwGNRN4I6gvxiEXJZ9oyai3 eUAZGL9LeElF6l25sUFKz0G2VDQFewWUpA== X-Google-Smtp-Source: ABdhPJzGVBYP1DlGvGBwcWdsy3EVdE2+sdyzYqdyt+sHey+DjlLbgP3440likLdGUI3n92oD/jfD5w== X-Received: by 2002:a0c:f4d0:: with SMTP id o16mr2539573qvm.45.1607047073675; Thu, 03 Dec 2020 17:57:53 -0800 (PST) Received: from localhost.localdomain ([136.49.211.192]) by smtp.gmail.com with ESMTPSA id l10sm3469738qti.37.2020.12.03.17.57.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 17:57:53 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Daniel Kiper , Glenn Washburn Subject: [PATCH v2] loopback: Do not automaticaly replace existing loopback dev, error instead Date: Thu, 3 Dec 2020 19:57:11 -0600 Message-Id: <20201204015711.4102520-1-development@efficientek.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201127083624.3482953-1-development@efficientek.com> References: <20201127083624.3482953-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::f44; envelope-from=development@efficientek.com; helo=mail-qv1-xf44.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Dec 2020 01:57:57 -0000 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 crash unexpectedly. 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 --- grub-core/disk/loopback.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index cdf9123fa..ef3a05fec 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -92,24 +92,16 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args) if (argc < 2) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); + /* 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) + return grub_error(GRUB_ERR_BAD_ARGUMENT, "device name already exists"); + file = grub_file_open (args[1], GRUB_FILE_TYPE_LOOPBACK | GRUB_FILE_TYPE_NO_DECOMPRESS); if (! file) return grub_errno; - /* First try to replace the old device. */ - 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; - } - /* Unable to replace it, make a new entry. */ newdev = grub_malloc (sizeof (struct grub_loopback)); if (! newdev) -- 2.27.0