From patchwork Fri Aug 18 13:07:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 9908579 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 4ED9D60382 for ; Fri, 18 Aug 2017 13:07:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FB1A28CAA for ; Fri, 18 Aug 2017 13:07:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3478A28CB4; Fri, 18 Aug 2017 13:07:51 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 DB4FF28CAA for ; Fri, 18 Aug 2017 13:07:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750881AbdHRNHu (ORCPT ); Fri, 18 Aug 2017 09:07:50 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:37916 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750812AbdHRNHt (ORCPT ); Fri, 18 Aug 2017 09:07:49 -0400 Received: by mail-wr0-f195.google.com with SMTP id 49so7418552wrw.5 for ; Fri, 18 Aug 2017 06:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ZBh30BBMDMXBvmym8QxFgU8LIVtCAWVOQdHSSqwCTbU=; b=t1ZiQaht1xKewDG2/RwQggziivMMS14JkSqYxjCtptAUEqcVoDQjbDy3Yy9w00f8pv SsjPyscX7zv33lQKsWp1pzscSd6s0GenE+1bdSsaD8/cqJe6flwg6nWeJL68QsozsKRt ALaJtvsF9/n4ifzTDtFzIn70SRWtLONQSIOWI/wvBkjEpvcLfmczTU7MVtg0Zgn4Z7IV +nwqgSkGurAcuwr6+2dtHuFflIRt+7vnLxamtCBV8XRjasmo7azus2jIflh9ngt8/Q9e 0J2fWoL3YubtQPYqrztrUIq4Db9UnhUb7gnuIea24sOemFZQjos+6KVEZyBjLprtRD48 bM+w== 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; bh=ZBh30BBMDMXBvmym8QxFgU8LIVtCAWVOQdHSSqwCTbU=; b=m1xcAyB0qvDMjHHzrCjJ3X+YpxIg5JdYeR9vOx1Cdiq8oP117yfzcpkM7+r/98J6cg i9F0zT+FP9n9QWXDst/b3aQy5h3o2HknRp9jEFvENJbY14NuLyyjYobdwfJV1rN/lQLf jnvGpGx8ezzIKVM//YaEgMRvsi9rFWnIVpxzFyAEJiduGgxaZ7TgkE5he4AJScb7nYBb 1u7DKUcSdQWltzTCDZTAN1ZGv6yLu1LdnSj2tlo2XXTxgxbI94CXsW2QS5BgvSDwMR0T NUZGKYliW0wDH3ckVlxIQHK56dwuVWLvvYpezibsT2C4385wSeSKr+yT5MefFGfJD0cx JrHA== X-Gm-Message-State: AHYfb5gMmFtsvNX85EG0rCU/Bc2IN58iiwgzSLpYZU+poaJ0bsyNh87z VEqevBO0IP7GN0O0 X-Received: by 10.28.136.8 with SMTP id k8mr1627577wmd.67.1503061668319; Fri, 18 Aug 2017 06:07:48 -0700 (PDT) Received: from merlot.mazyland.net (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.googlemail.com with ESMTPSA id g133sm2332191wmd.48.2017.08.18.06.07.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 06:07:47 -0700 (PDT) From: Milan Broz To: linux-block@vger.kernel.org Cc: kzak@redhat.com, axboe@kernel.dk, hare@suse.de, Milan Broz Subject: [PATCH] loop: Fix freeze if configured block size is not supported Date: Fri, 18 Aug 2017 15:07:33 +0200 Message-Id: <20170818130733.11254-1-gmazyland@gmail.com> X-Mailer: git-send-email 2.14.1 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 The commit f2c6df7dbf9a60e1cd9941f9fb376d4d9ad1e8dd loop: support 4k physical blocksize adds support for loop block size with only specific block sizes. If the size is not supported, the code returns -EINVAL keeping the loop queue frozen. This causes that device could be locked for a long time by processes trying to scan device (udev). (And also causing subsequent LOOP_CLR_FD operations noop.) Fix it by using goto to proper exit location with queue unfreeze. (The same bug is for setting crypt attribute but this code is probably no more used. Patch fixes it as well though.) Signed-off-by: Milan Broz --- 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 ||