From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kiZFS-0006rT-1V for mharc-grub-devel@gnu.org; Fri, 27 Nov 2020 03:36:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiZFQ-0006qQ-A3 for grub-devel@gnu.org; Fri, 27 Nov 2020 03:36:56 -0500 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]:42050) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kiZFN-0003Sr-9d for grub-devel@gnu.org; Fri, 27 Nov 2020 03:36:56 -0500 Received: by mail-lf1-x141.google.com with SMTP id u18so5910907lfd.9 for ; Fri, 27 Nov 2020 00:36:52 -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=20TNVYe80d4KyrlyP1I3BvPhHS5sg9avdr9bru+8OlM=; b=AuNCCsGIw8Nkq8VjqMAYmc+GyqNcFh0c6Ue8NcmU6JBEZnuz9ZDRajS568CPqX/UtT 11XOhXNu1y2bDxZzDpDOXHoUMdbOLoe5CcEGsW18FJDVyUsZDLWGBrzG8qEmmujB29lr 5pwm2jTa7MrYBAKrrgnEyN0uXT1YL+/F3p1ZTb4W3VInhMiUnw3ceHXcpn6372F6W6tp BXo56V4nkhuXGBKFEYlEyhWzLiNFxn1K1BgdlaeRqzBzcgyiozMPu2vBOmVLNBy9cnQv ZjYCYw9luawdfFYo1bZ33kz+BWxfFyav1PICNdumdJ6FRKRQo81wv8z2urIadVqWXF3x e7/w== 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=20TNVYe80d4KyrlyP1I3BvPhHS5sg9avdr9bru+8OlM=; b=cvEfa/QXDOAYGdexdyOMI7aRCqZw0SpYb0G9E1glFPQx4+i9T9N/sQfsFt0JYBWaIS wE0xvS4INDMbM5nQ2Y+pUwAkAzE9SPjrlerQoPq5idedLASpsKfIzuPY9148XurBPilb vcs+/ENT0MBGh7JXfTtNlAGG3AZinCCrwTkXUkiQik+IXSo4etpB1tNq9Xu+mSXapEWn sVRau5RJe8qS/n05vOA/Vxk1OJSVU9zZV/ZVJMgMMY/kE2O0JjmW7rAQnWPqQhnWRAje cPwilVjpKQ7NwLbnUHr/Vj2FmDQWiuLO43U7/wgqN76DLVlCW8SaBcEKXSZ3IDDSRWmh DqPA== X-Gm-Message-State: AOAM531AiUttWZ7QZT8wQLvPDhE4nJu3T1Bg3BkJPuT7TiryH3lIjl3A 2JqFTMcPXg8PGKupjlJrkChHUVDueblB5g== X-Google-Smtp-Source: ABdhPJzH9sKD50//mZSxdvbhAjie4/VT0YF39l3YmXgarGm1kRv74C913+eNEL07/7kcrDdDZ8gJDg== X-Received: by 2002:a19:655c:: with SMTP id c28mr3055173lfj.549.1606466211320; Fri, 27 Nov 2020 00:36:51 -0800 (PST) Received: from localhost.localdomain ([136.49.211.192]) by smtp.gmail.com with ESMTPSA id v17sm607372lfp.169.2020.11.27.00.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 00:36:50 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Daniel Kiper , Glenn Washburn Subject: [PATCH] loopback: Do not automaticaly replace existing loopback dev, error instead Date: Fri, 27 Nov 2020 02:36:24 -0600 Message-Id: <20201127083624.3482953-2-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=2a00:1450:4864:20::141; envelope-from=development@efficientek.com; helo=mail-lf1-x141.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, 27 Nov 2020 08:36:56 -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 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 --- 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