Received: by 10.213.65.68 with SMTP id h4csp426867imn; Tue, 13 Mar 2018 08:42:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELtlEvqm9UZnRHxyP1uoatE+lX2kOTB/EMrSTpgGSUitJ423088AXXG9ObHDnZirXKeeKUUg X-Received: by 10.101.71.138 with SMTP id e10mr859676pgs.317.1520955771231; Tue, 13 Mar 2018 08:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520955771; cv=none; d=google.com; s=arc-20160816; b=sCJxn7K5MoriYynWA5QBfjCjun+lOEs7KLzkHjFeqcy+NDtgJiGeDiYm94BWUodhtM yhqoNHo8WKdpShlQGBlVx+CSCITz/sXfnW0Ruaivcg3XA7UzCs13cvVHNk0gfYoh7QMv rcQjTkfjGrJGajLJe6qe1YaFNNlnNsX95Z0FMspTHvp4xJqWFE7KiOwQAT6XfBaMDmu7 jTn5SHvI9yz26KnZlZ2OgzO9WfP44eM1xUeDFMjJhim2MWY4IMmsSG/K6S7xD4OUuBUe MKVFmD4nS0seV71l4OFKXpLlXMpfo7eI0Xfz+6o+PjerKeQDtS4wChwRGOFSzi/hlaQV q8ag== 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 :arc-authentication-results; bh=k2cPhOCsekz1gFFEajo9kMCmd8ihTGT00haOZPCU+Bw=; b=QMVnnSFX92LQuQ7bXDEKHr+m4lqUCRu8pLgg9xhS2ALqvECEYytgMApM1a1XqNIlnS HAcM8ltglsUCGveL3olV7Om1nPOHhPKhYPH+oj1JllKNyy66PrwuFSA8Zc4feXBUwk0S vnql4lhhuolFoNORy7Ayn5wkYH9BR3a529gzeUQLdDOcg5ww0pE73X94cwFsyqqKeJzW gwvNLEg42LOy+mOr3F3/1mg4zslVmRyT7dfCdUR1lEARkuIL8LCMfEHZMf71uJdji5p7 j7yCY6OjdRZz9lPqvU4gj3romWTV0NppyzsVkfimEsWEnMtg08TisSso/X0WvpcG9ZKD Piaw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d81si323644pfj.222.2018.03.13.08.42.36; Tue, 13 Mar 2018 08:42:51 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934805AbeCMPjv (ORCPT + 99 others); Tue, 13 Mar 2018 11:39:51 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35444 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934132AbeCMPjr (ORCPT ); Tue, 13 Mar 2018 11:39:47 -0400 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 07321FDD; Tue, 13 Mar 2018 15:39:46 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Lyle , Tang Junhui , Jens Axboe Subject: [PATCH 4.14 096/140] bcache: dont attach backing with duplicate UUID Date: Tue, 13 Mar 2018 16:24:59 +0100 Message-Id: <20180313152504.603720689@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152458.201155692@linuxfoundation.org> References: <20180313152458.201155692@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: Michael Lyle commit 86755b7a96faed57f910f9e6b8061e019ac1ec08 upstream. This can happen e.g. during disk cloning. This is an incomplete fix: it does not catch duplicate UUIDs earlier when things are still unattached. It does not unregister the device. Further changes to cope better with this are planned but conflict with Coly's ongoing improvements to handling device errors. In the meantime, one can manually stop the device after this has happened. Attempts to attach a duplicate device result in: [ 136.372404] loop: module loaded [ 136.424461] bcache: register_bdev() registered backing device loop0 [ 136.424464] bcache: bch_cached_dev_attach() Tried to attach loop0 but duplicate UUID already attached My test procedure is: dd if=/dev/sdb1 of=imgfile bs=1024 count=262144 losetup -f imgfile Signed-off-by: Michael Lyle Reviewed-by: Tang Junhui Cc: Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/super.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -938,6 +938,7 @@ int bch_cached_dev_attach(struct cached_ uint32_t rtime = cpu_to_le32(get_seconds()); struct uuid_entry *u; char buf[BDEVNAME_SIZE]; + struct cached_dev *exist_dc, *t; bdevname(dc->bdev, buf); @@ -961,6 +962,16 @@ int bch_cached_dev_attach(struct cached_ return -EINVAL; } + /* Check whether already attached */ + list_for_each_entry_safe(exist_dc, t, &c->cached_devs, list) { + if (!memcmp(dc->sb.uuid, exist_dc->sb.uuid, 16)) { + pr_err("Tried to attach %s but duplicate UUID already attached", + buf); + + return -EINVAL; + } + } + u = uuid_find(c, dc->sb.uuid); if (u &&