Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp785840yba; Wed, 15 May 2019 09:54:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCPjRhwVd1PVnHvSqwMbqIgrj0/nt3YUdFmxlAodM8V8MTJL3yK9/EIXUoTFUyQSMAshvj X-Received: by 2002:a63:d901:: with SMTP id r1mr7211984pgg.271.1557939260842; Wed, 15 May 2019 09:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557939260; cv=none; d=google.com; s=arc-20160816; b=LKctCzk0OyKfBSOZ0pEWnHiog28iENLU+aWVf6cowm+1S1e00XtNP/1IhQetEycgdS n0cRZo7TSW5TjY1bbQiVsNCPyRdI4Jwg4tXEEYJcATcA4T1qu5Os4sQIgtjDvyqfsTRf B8ZcIMW30tuL0aKZldXLb0juNPRWVfh0MH5uou9gL19+1xaHrWauSYVogIxmmjJMSAle 7pRp9iNVphQg1lpQWHjsC6MUEIuPCERLgJhrDATXyoNQg7CWXRymoU0F2s8/7z+rr2Vp +bLswfGK43sy+EJn62PZCQ8e7DAG31d1rFjD1yKW29l47vyil3kam5u/0h5OeVTljRA1 ba5w== 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 :message-id:date:subject:cc:to:from; bh=O0wBX5kOR3rj4nosKZgwcIU4mLaWYxzif/0iZbag7WI=; b=givcXluo7itRv/RQlREbf4e5kIXvn8PZVausnEVQHqD5xHsYP5Mmz9jPNcLbtEapSk A1NAoZUqnxonGrZn5L7whOcl15sLneTuci6dt26w5T6Qsa9MGipv9VJ/tPmpnaG8pmGM b3/72NUe1hyDpK8Z1HSXUvqtQod/ZrpFXI1TQsQBZlHbKrVof+bVufY3rRXOQrUiGmRn APNnlNDAsMmpk7DrVC/X1gSJyA1lzLy61G/2qd6GfTjgL5f9HqngZt2Iwf4nmK/SdkJI imoYWihIKX4V6UV55vc7nPz6r8+p+f0FDqE6O69FwZsNcs6eXwbZ7Hl7BD7H37y9VO65 T8Aw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u19si2142644pgm.471.2019.05.15.09.54.05; Wed, 15 May 2019 09:54:20 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727436AbfEOQvV (ORCPT + 99 others); Wed, 15 May 2019 12:51:21 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:33020 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbfEOQvV (ORCPT ); Wed, 15 May 2019 12:51:21 -0400 Received: from localhost.localdomain (unknown [IPv6:2804:431:9719:d573:a076:d1fd:3417:b195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: koike) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id EDED326D7C1; Wed, 15 May 2019 17:51:16 +0100 (BST) From: Helen Koike To: dm-devel@redhat.com Cc: kernel@collabora.com, Helen Koike , stable@vger.kernel.org, Mike Snitzer , linux-kernel@vger.kernel.org, Alasdair Kergon Subject: [PATCH v2] dm ioctl: fix hang in early create error condition Date: Wed, 15 May 2019 13:50:54 -0300 Message-Id: <20190515165054.12680-1-helen.koike@collabora.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The dm_early_create() function (which deals with "dm-mod.create=" kernel command line option) calls dm_hash_insert() who gets an extra reference to the md object. In case of failure, this reference wasn't being released, causing dm_destroy() to hang, thus hanging the whole boot process. Fix this by calling __hash_remove() in the error path. Fixes: 6bbc923dfcf57d ("dm: add support to directly boot to a mapped device") Cc: stable@vger.kernel.org Signed-off-by: Helen Koike --- Hi, I also tested this patch version with the new test case in the following test script: https://gitlab.collabora.com/koike/dm-cmdline-test/commit/d2d7a0ee4a49931cdb59f08a837b516c2d5d743d Thanks Helen Changes in v2: - instead of modifying dm_hash_insert() to return the hash cell, use __get_name_cell(dmi->name) instead. drivers/md/dm-ioctl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index c740153b4e52..1e03bc89e20f 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -2069,7 +2069,7 @@ int __init dm_early_create(struct dm_ioctl *dmi, /* alloc table */ r = dm_table_create(&t, get_mode(dmi), dmi->target_count, md); if (r) - goto err_destroy_dm; + goto err_hash_remove; /* add targets */ for (i = 0; i < dmi->target_count; i++) { @@ -2116,6 +2116,10 @@ int __init dm_early_create(struct dm_ioctl *dmi, err_destroy_table: dm_table_destroy(t); +err_hash_remove: + (void) __hash_remove(__get_name_cell(dmi->name)); + /* release reference from __get_name_cell */ + dm_put(md); err_destroy_dm: dm_put(md); dm_destroy(md); -- 2.20.1