From patchwork Tue Aug 22 17:32:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9915827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CAB99603FF for ; Tue, 22 Aug 2017 17:33:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3FDF283ED for ; Tue, 22 Aug 2017 17:33:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8CC3286B7; Tue, 22 Aug 2017 17:33:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AD7628635 for ; Tue, 22 Aug 2017 17:33:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752045AbdHVRdP (ORCPT ); Tue, 22 Aug 2017 13:33:15 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:35548 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752377AbdHVRdN (ORCPT ); Tue, 22 Aug 2017 13:33:13 -0400 Received: by mail-pf0-f175.google.com with SMTP id w127so17864973pfd.2 for ; Tue, 22 Aug 2017 10:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=C3mLE+xLNP+EyhfXTfWAasrWm6kWYvEmc5GbMoZCEjk=; b=TWyWIWVnzL14eMkh1eOd5UmIE3oKdCzXLxy9GJuHBLOsumfX/HLqj6j/L39Hy1lWcI wdk95ccukMNvRMdvptH4hhfuE96v8JDnsNl08qv2nU0jBstfd90mFZbEzZckjN1IH+ya I5y2Uf83S8AM8tqKVGhMOBYFrw0PwQf7LyudEXh6vVHjTtUw7NZG7zulkWdN2IhklN1e jseF9Cs6drPj/es4f3fxck7BoHhqlcN5iZNlJ55yQcxNa366m4P9Gg5iXS/XfNr/b65w LdFzvjcl+l8JY3R5kMypTxvAG+v995vb/T4+pSdu28JjDtegNaNzPXBoFq7cjZ9CyJ+J YIJA== 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:in-reply-to:references; bh=C3mLE+xLNP+EyhfXTfWAasrWm6kWYvEmc5GbMoZCEjk=; b=Ge755tqbrDfn9ObOP967lfrP5KGM3Q7SgS9GKyqOcYxxDiDCO3mOneW+dxOMK4MTeO hZXruAeD9X//fMy+WOVGm1F9+fHb/YNAhqFKc28Asp4S1gpJntY3+42b84UZM73ks4sn iis7Um8ze88c1FVSws2qf5yvOIGTXCdzGg00rTgFei1MHMEKC157jgJqmp64PZ0Uq9rm JPw4bQA+sc/6ZycuGDGd3oem7GTMGq5nb/gcbS+YbLErjbbUqQPs3RH7Vtw8famkjX0L FKdCPJF+2NVJRlTvDLwcjogdDu7nFMSXmfh/ENN0u71oLepj27v3hT3jdNug2VsrQS96 AklQ== X-Gm-Message-State: AHYfb5h8V21CMep85h6/Rlgaoa+c3ZTZKdJTkwTi8Rg9kpqJnMUaI42R 0sxOY9zq8SbXAGGV2Ppqdw== X-Received: by 10.99.156.1 with SMTP id f1mr1392456pge.327.1503423192915; Tue, 22 Aug 2017 10:33:12 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:99f5]) by smtp.gmail.com with ESMTPSA id m10sm4920083pgd.62.2017.08.22.10.33.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 10:33:11 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: kernel-team@fb.com, Hannes Reinecke , Ming Lei , Karel Zak , Milan Broz Subject: [PATCH v3 1/4] loop: fix hang if LOOP_SET_STATUS gets invalid blocksize or encrypt type Date: Tue, 22 Aug 2017 10:32:58 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval In both of these error cases, we need to make sure to unfreeze the queue before we return. Fixes: ecdd09597a57 ("block/loop: fix race between I/O and set_status") Fixes: f2c6df7dbf9a ("loop: support 4k physical blocksize") Tested-by: Milan Broz Reviewed-by: Milan Broz Reviewed-by: Hannes Reinecke Signed-off-by: Omar Sandoval --- drivers/block/loop.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index ef8334949b42..26548e07bc31 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1125,11 +1125,15 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) if (info->lo_encrypt_type) { unsigned int type = info->lo_encrypt_type; - if (type >= MAX_LO_CRYPT) - return -EINVAL; + if (type >= MAX_LO_CRYPT) { + err = -EINVAL; + goto exit; + } xfer = xfer_funcs[type]; - if (xfer == NULL) - return -EINVAL; + if (xfer == NULL) { + err = -EINVAL; + goto exit; + } } else xfer = NULL; @@ -1144,10 +1148,14 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) if (LO_INFO_BLOCKSIZE(info) != 512 && LO_INFO_BLOCKSIZE(info) != 1024 && LO_INFO_BLOCKSIZE(info) != 2048 && - LO_INFO_BLOCKSIZE(info) != 4096) - return -EINVAL; - if (LO_INFO_BLOCKSIZE(info) > lo->lo_blocksize) - return -EINVAL; + LO_INFO_BLOCKSIZE(info) != 4096) { + err = -EINVAL; + goto exit; + } + if (LO_INFO_BLOCKSIZE(info) > lo->lo_blocksize) { + err = -EINVAL; + goto exit; + } } if (lo->lo_offset != info->lo_offset ||