Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2000045imm; Thu, 24 May 2018 04:17:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqi7HGUYEEZ4RUgEwwBCK/MyF/E45p+htNQzrJx38mJQtP6CVMwDvzkfmaQKMF+f+J1br73 X-Received: by 2002:a62:3085:: with SMTP id w127-v6mr6838304pfw.224.1527160655313; Thu, 24 May 2018 04:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527160655; cv=none; d=google.com; s=arc-20160816; b=RGnxN+Kv8CJ2vSZshwMu+rrkVIbFYyJhkBLrnudnoXyBJKJqh3TB88Dj4yYSf41ccO AAGK7rKDsJFbUO3IMlS/A5bk5ZkhxObeVma34Bj8/Ds3LG10hdklX4iFSq9Yg+kNBquH BsXGX/x4wO8vxB8sx0eYNSeODPPdSvbgKIxtaWzpRv10bepX43hCryXHnxh+HCiLoLq/ bZoJyZRgCWhiq3yKMPKspbWz2YjD1IzKUmx3IeDPXTDTpkk/zXMwlkTaWejqcRrxNDF1 oPz8XTKJ0gQ+hDygK6+0Cbm+tg7C+1N+B33yH7i6oElmLnznShaXXSsoP5mzQgrm78fJ zCjA== 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=nBCmF9qP4XR6Z5QJnKJLMEc+uckV2y6LAdkZBRuSWck=; b=YZvwud2FsGGxM3uO/GJS89nnfgYhS8+objokqyBJhcJYYE6657LVOIfmAgX5VXm5iH ofGsiAC631GhF705kK/e5YFXTn3bdFxxa/TEmnOx88qS8EMb8xT4CJUkDDxr7Uk6lFQ2 4Hombmk3bWgU6JbGTfmIpkgbaqSYUYV/utrRGBZX3Kz+25RuUxd7G+KH24lu8A1pWvsK INm6fONkub2Hnk4mTTk/2WRokMYvZaSBCIB1F7/M0CY0hSzK1GTpIQZ0w9MK8rAiqwbg v4Cxe3+5q18ExDB2MmwWS8Lqm6zkcIas3h1QmfCsOPMyYwjDzoGrlD1zAHjkpihzNQmH dkfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J0+5t4IJ; 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 a5-v6si23073909pla.117.2018.05.24.04.17.20; Thu, 24 May 2018 04:17:35 -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=J0+5t4IJ; 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 S968683AbeEXLQs (ORCPT + 99 others); Thu, 24 May 2018 07:16:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:59194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968033AbeEXJxY (ORCPT ); Thu, 24 May 2018 05:53:24 -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 6D2E120892; Thu, 24 May 2018 09:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155603; bh=7D8iGKdSwXFIiqd40ApOjKQlVggGIZf2kZU5PpxcrhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J0+5t4IJFL7gLiUT4z86dv2DpqExEnEyEr+6ID2RtLaWZ0DhwF/wIfrAcWUs80/jQ W8N0QJtgssZOCdO55utdN3ObqG5NVbMWwVTs93ceM2I4VCyqYyrPqOMUJ/F4Yi/p6k jvIwxAaQfxRP5m+nV2dEmKYNFOOokgfhjQ4LZLp0= 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.14 050/165] loop: fix LOOP_GET_STATUS lock imbalance Date: Thu, 24 May 2018 11:37:36 +0200 Message-Id: <20180524093624.053521515@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@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.14-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 @@ -1282,12 +1282,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))) @@ -1299,12 +1300,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; @@ -1525,12 +1527,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;