Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6264945imu; Mon, 21 Jan 2019 06:05:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN7J5kfZ3+qbIaY/TojYDljXSiTrELBkxOA0kIwWRUSOe2wCsRESO8l9/N6wJrv6Q2MyPV9x X-Received: by 2002:a63:d747:: with SMTP id w7mr27605278pgi.360.1548079504014; Mon, 21 Jan 2019 06:05:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079503; cv=none; d=google.com; s=arc-20160816; b=0XlcR6hwUWm4tUn9ZgbKWYpayU2sMpwt+o2VlbPIhJlSHfsxsaBXdx3h2Wm/5oHWlN HEXYMlA7iBqaMI5rDZdyZMTwmBgJYsqhvrH9nHItI/Lri7tSNZtgzW+3Nmdmvi736rTt tw9WddESmLp36vAFNYXRBClODyRJPu+zZyCn/T2cYlP9jL3gJZ8JSm8J/E2Jrw2P9cBB gLMg8GhqbvUPercfBHnahieg9sdIQv5p7eJ3vjRVs5+kyFql9x9hQ1tWc/MnCMJXUDGt RKeeC5r8OUcUav8ohvWKr5UBRxx0wOTRXT5vGZEhBPOMAyOdKhDqyHuIQTPSdELqek/d kNqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kkgsx6799SHWPgZKxiiDMW82enwqauqCpiOTqoYCSKw=; b=xO/QMYo2INV0elUu24q63pIZX79jGlDlnuFKdQMGWKw1/0ZNUMHXmLTBzmziU3sZnN dq+q/ZtiNAnQvzoiqbL1tvgsMDkmOmD/OmdrIuqnBDjyB+gnRyUYb/5iEn7xQGaW2du9 sfLoCw/ZRPgeVXHdAov8SzONtu5tKv/yKxwYdhXdyx4Yt1X7EoJy+9b6KFk+F38m56WK jia6LDMPUZStvla4fbD2IbicgyjinzVlBKUUltnp+FmXSUL61lmHrZ3ePoY1Xj0buMF8 RByGumxujVDI132iADGIiJPtkfvB8ugEvXvVMQa+rcGtyOuCZ45lEnT1RCPw4IqT0RWV 8yaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YK12WkWc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6si12075767pln.66.2019.01.21.06.04.35; Mon, 21 Jan 2019 06:05:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YK12WkWc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732760AbfAUOCS (ORCPT + 99 others); Mon, 21 Jan 2019 09:02:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:49642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732747AbfAUOCM (ORCPT ); Mon, 21 Jan 2019 09:02:12 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 106F8214D8; Mon, 21 Jan 2019 14:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079331; bh=Gfjclx7/LBLvtt1WL40v2ccvbYepDCv5gvNNOSxZ6aQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YK12WkWcLCXXUN5FDyKYYDRCd+jdvLOetJ15vrSO6wQJUerQ2JmGmfBltqf8Z2ZCZ uJ1QggzkNoX4kDKT5enrt8f4JsR4Zd2Tfi9J7BaBg4qegdED9f2iWqVWj1kLrDShBB Tylxholb13TiOpsq8mlICC+4IfvDvZT4ZOQufKR0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Jens Axboe Subject: [PATCH 4.19 88/99] loop: Push loop_ctl_mutex down to loop_set_status() Date: Mon, 21 Jan 2019 14:49:20 +0100 Message-Id: <20190121134917.598468754@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara commit 550df5fdacff94229cde0ed9b8085155654c1696 upstream. Push loop_ctl_mutex down to loop_set_status(). We will need this to be able to call loop_reread_partitions() without loop_ctl_mutex. Signed-off-by: Jan Kara Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1142,46 +1142,55 @@ loop_set_status(struct loop_device *lo, struct loop_func_table *xfer; kuid_t uid = current_uid(); + err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); + if (err) + return err; if (lo->lo_encrypt_key_size && !uid_eq(lo->lo_key_owner, uid) && - !capable(CAP_SYS_ADMIN)) - return -EPERM; - if (lo->lo_state != Lo_bound) - return -ENXIO; - if ((unsigned int) info->lo_encrypt_key_size > LO_KEY_SIZE) - return -EINVAL; + !capable(CAP_SYS_ADMIN)) { + err = -EPERM; + goto out_unlock; + } + if (lo->lo_state != Lo_bound) { + err = -ENXIO; + goto out_unlock; + } + if ((unsigned int) info->lo_encrypt_key_size > LO_KEY_SIZE) { + err = -EINVAL; + goto out_unlock; + } /* I/O need to be drained during transfer transition */ blk_mq_freeze_queue(lo->lo_queue); err = loop_release_xfer(lo); if (err) - goto exit; + goto out_unfreeze; if (info->lo_encrypt_type) { unsigned int type = info->lo_encrypt_type; if (type >= MAX_LO_CRYPT) { err = -EINVAL; - goto exit; + goto out_unfreeze; } xfer = xfer_funcs[type]; if (xfer == NULL) { err = -EINVAL; - goto exit; + goto out_unfreeze; } } else xfer = NULL; err = loop_init_xfer(lo, xfer, info); if (err) - goto exit; + goto out_unfreeze; if (lo->lo_offset != info->lo_offset || lo->lo_sizelimit != info->lo_sizelimit) { if (figure_loop_size(lo, info->lo_offset, info->lo_sizelimit)) { err = -EFBIG; - goto exit; + goto out_unfreeze; } } @@ -1213,7 +1222,7 @@ loop_set_status(struct loop_device *lo, /* update dio if lo_offset or transfer is changed */ __loop_update_dio(lo, lo->use_dio); - exit: +out_unfreeze: blk_mq_unfreeze_queue(lo->lo_queue); if (!err && (info->lo_flags & LO_FLAGS_PARTSCAN) && @@ -1222,6 +1231,8 @@ loop_set_status(struct loop_device *lo, lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN; loop_reread_partitions(lo, lo->lo_device); } +out_unlock: + mutex_unlock(&loop_ctl_mutex); return err; } @@ -1468,12 +1479,8 @@ static int lo_ioctl(struct block_device case LOOP_SET_STATUS: err = -EPERM; if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) { - err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); - if (err) - return err; err = loop_set_status_old(lo, (struct loop_info __user *)arg); - mutex_unlock(&loop_ctl_mutex); } break; case LOOP_GET_STATUS: @@ -1481,12 +1488,8 @@ static int lo_ioctl(struct block_device case LOOP_SET_STATUS64: err = -EPERM; if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) { - err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); - if (err) - return err; err = loop_set_status64(lo, (struct loop_info64 __user *) arg); - mutex_unlock(&loop_ctl_mutex); } break; case LOOP_GET_STATUS64: @@ -1631,12 +1634,8 @@ static int lo_compat_ioctl(struct block_ switch(cmd) { case LOOP_SET_STATUS: - err = mutex_lock_killable(&loop_ctl_mutex); - if (!err) { - err = loop_set_status_compat(lo, - (const struct compat_loop_info __user *)arg); - mutex_unlock(&loop_ctl_mutex); - } + err = loop_set_status_compat(lo, + (const struct compat_loop_info __user *)arg); break; case LOOP_GET_STATUS: err = loop_get_status_compat(lo,