From patchwork Mon Sep 21 16:26:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "gregkh@linuxfoundation.org" X-Patchwork-Id: 309435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D441C43466 for ; Mon, 21 Sep 2020 16:43:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4760723998 for ; Mon, 21 Sep 2020 16:43:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706638; bh=42fnfEc8RLB+21VT9GxDtA29pgj9XX4YzmOC2aE1PTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=aXhd0X7FCAjNcla8zi9sNBXIUWXew0F4dsL6cKR1gCALYs48ADq581FaJA4pFt7HK sgXaVU4kUH7mtJCl4GmfRNwO1eBmPNaht0I9pl2sOPjaeWfhYywJegc9ntkqtV2c+v Wy/TIyRl9+0i2WRSH6fOUA2UjY4EIvzotACBMIJ4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729639AbgIUQnv (ORCPT ); Mon, 21 Sep 2020 12:43:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:48470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729635AbgIUQno (ORCPT ); Mon, 21 Sep 2020 12:43:44 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A0C9238E6; Mon, 21 Sep 2020 16:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706622; bh=42fnfEc8RLB+21VT9GxDtA29pgj9XX4YzmOC2aE1PTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ujO9qxJDHxKjNvkik09zLNZg8DzRzBe2SwFQtmA5+X/nYo9MCMzuN9KDfe74e4QLa j6IO7hBCdmvEKr9pSHgKK3a5JMyuKvcll0r0T33eDHTLMTkWTZvhlvwGjXaxN9jL9+ eOYxEPEl6+As7Lehv4bAis57/GO3aWcQwENeDEPU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lennart Poettering , Yang Xu , Martijn Coenen , Jens Axboe Subject: [PATCH 5.8 007/118] loop: Set correct device size when using LOOP_CONFIGURE Date: Mon, 21 Sep 2020 18:26:59 +0200 Message-Id: <20200921162036.684858019@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Martijn Coenen commit 79e5dc59e2974a48764269fa9ff544ae8ffe3338 upstream. The device size calculation was done before processing the loop configuration, which meant that the we set the size on the underlying block device incorrectly in case lo_offset/lo_sizelimit were set in the configuration. Delay computing the size until we've setup the device parameters correctly. Fixes: 3448914e8cc5("loop: Add LOOP_CONFIGURE ioctl") Reported-by: Lennart Poettering Tested-by: Yang Xu Signed-off-by: Martijn Coenen Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1114,8 +1114,6 @@ static int loop_configure(struct loop_de mapping = file->f_mapping; inode = mapping->host; - size = get_loop_size(lo, file); - if ((config->info.lo_flags & ~LOOP_CONFIGURE_SETTABLE_FLAGS) != 0) { error = -EINVAL; goto out_unlock; @@ -1165,6 +1163,8 @@ static int loop_configure(struct loop_de loop_update_rotational(lo); loop_update_dio(lo); loop_sysfs_init(lo); + + size = get_loop_size(lo, file); loop_set_size(lo, size); set_blocksize(bdev, S_ISBLK(inode->i_mode) ?