Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1945957imm; Thu, 24 May 2018 03:23:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqN5sIWQID8EdcRsSWXAODaXejIyJYZOFcTgsOEpQSpnMgqJyajlnmcvY7V9kPsC83z8W7t X-Received: by 2002:a62:74b:: with SMTP id b72-v6mr6625432pfd.133.1527157426701; Thu, 24 May 2018 03:23:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527157426; cv=none; d=google.com; s=arc-20160816; b=adufxuJW69d51ekwXNuM7uPps/il0RrWSUbMtybwYk1u6/++6RoOV6bHR3S1cee/v0 6fz7Pg25zL9gKe9zevQN69c0JRseOqi39gSU1U3/TlYG6yE4A6MaGmHY1XAXmqyTqWB0 watFWuXfFTNkUDHlv4AzX+RW8Cjle/kPzjl9fdAm3Lw0duVSMdY16P+HoFJa7onn8pW6 VWopg9nRV+pwo3GoOg3AbXGLOwFeDpbYnKQaMovQZSPrG1fBbE8ACruQma0bPfg/1gAR h2KfpCIo8Jn2Kb0tXG2GuGSYTafbHbZzhs1IUVlgljhUlIt/hVfd5ZQP4dsHPeY0Mz/S tZYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=GyVdLmelDnqA6X6a6TBOTWzv/Heim4FHNf1/JVvu9lk=; b=FlVkSFcpSz/a77Mwp24FqSOlib+TOfMNmVQU1cSOcCGT6Syg5L5h/l7B5+OiEitGO7 0OAof91X04T7w+T+u2d0Guiu2sSPAOmdYFMXDL69wpMm40A4e25YZtUw2cUtRryZhKKY V0FCtq12wryGDG5vB4VfwLU2Awv9yJOw9+ZnLnqj6g6Qd6AA21axwnUluVNsFbFpf+hC JGuQOVMV4pNe/Y7dCzZlq3XggjlR335bR8E+4PI3fDMWzB+QkekioLc+0L4bEA6InYGU 6lz0R0YlzctBIwDPpN+QK20RM3ex5YLXsKar9PHbcCiRyPF30vArtCosvLNKrkuexMd6 rvhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F6Pagy/K; 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 r4-v6si16714655pgp.103.2018.05.24.03.23.32; Thu, 24 May 2018 03:23:46 -0700 (PDT) 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=F6Pagy/K; 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 S1031158AbeEXKCt (ORCPT + 99 others); Thu, 24 May 2018 06:02:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:50638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031112AbeEXKCo (ORCPT ); Thu, 24 May 2018 06:02:44 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 0507920870; Thu, 24 May 2018 10:02:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527156163; bh=EPQz9Atfzmgabae+QJE/GbZj3g57JiOf/+/D1Mfbrrc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F6Pagy/KpFL+APMK9Lu2PIu+xHTrSHU0OpWxGNm36ElmfSuG7trRIMCf9+zQZledz RmbSVid5YqNtVJBFbaukA7VFE8yal5ffwL8gn+Of4VrPzTTC0GrND5n0Br69hP+14E CRe9WlugkC9pJrxEKkVTPgPP028OLCEzEmx5dUes= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+31e8daa8b3fc129e75f2@syzkaller.appspotmail.com, Omar Sandoval , Jens Axboe Subject: [PATCH 4.16 086/161] loop: fix LOOP_GET_STATUS lock imbalance Date: Thu, 24 May 2018 11:38:31 +0200 Message-Id: <20180524093028.748525266@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Omar Sandoval commit bdac616db9bbadb90b7d6a406144571015e138f7 upstream. Commit 2d1d4c1e591f made loop_get_status() drop lo_ctx_mutex before returning, but the loop_get_status_old(), loop_get_status64(), and loop_get_status_compat() wrappers don't call loop_get_status() if the passed argument is NULL. The callers expect that the lock is dropped, so make sure we drop it in that case, too. Reported-by: syzbot+31e8daa8b3fc129e75f2@syzkaller.appspotmail.com Fixes: 2d1d4c1e591f ("loop: don't call into filesystem while holding lo_ctl_mutex") Signed-off-by: Omar Sandoval Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1287,12 +1287,13 @@ static int loop_get_status_old(struct loop_device *lo, struct loop_info __user *arg) { struct loop_info info; struct loop_info64 info64; - int err = 0; + int err; - if (!arg) - err = -EINVAL; - if (!err) - err = loop_get_status(lo, &info64); + if (!arg) { + mutex_unlock(&lo->lo_ctl_mutex); + return -EINVAL; + } + err = loop_get_status(lo, &info64); if (!err) err = loop_info64_to_old(&info64, &info); if (!err && copy_to_user(arg, &info, sizeof(info))) @@ -1304,12 +1305,13 @@ loop_get_status_old(struct loop_device * static int loop_get_status64(struct loop_device *lo, struct loop_info64 __user *arg) { struct loop_info64 info64; - int err = 0; + int err; - if (!arg) - err = -EINVAL; - if (!err) - err = loop_get_status(lo, &info64); + if (!arg) { + mutex_unlock(&lo->lo_ctl_mutex); + return -EINVAL; + } + err = loop_get_status(lo, &info64); if (!err && copy_to_user(arg, &info64, sizeof(info64))) err = -EFAULT; @@ -1530,12 +1532,13 @@ loop_get_status_compat(struct loop_devic struct compat_loop_info __user *arg) { struct loop_info64 info64; - int err = 0; + int err; - if (!arg) - err = -EINVAL; - if (!err) - err = loop_get_status(lo, &info64); + if (!arg) { + mutex_unlock(&lo->lo_ctl_mutex); + return -EINVAL; + } + err = loop_get_status(lo, &info64); if (!err) err = loop_info64_to_compat(&info64, arg); return err;