Received: by 10.213.65.68 with SMTP id h4csp466531imn; Tue, 13 Mar 2018 09:57:56 -0700 (PDT) X-Google-Smtp-Source: AG47ELuMhVZg2RL/Tkfg6qTbrUkiasOflIShcQ3xsW08OOf2MIBMx/Al95FVL13Sr6SHevrsf3dK X-Received: by 2002:a17:902:2e04:: with SMTP id q4-v6mr1204120plb.22.1520960276144; Tue, 13 Mar 2018 09:57:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520960276; cv=none; d=google.com; s=arc-20160816; b=dhVtJwvX0tKzUHix0LgowYANzOODNpL8fQkbJNrm7GFuzpVX2+BBcyfjGF8ull8f2V mPdeagrcLciK0m633cI8kwB7aOoBqzL8y7PaCWrdX1nNzLFi8V9pw32xPNUXFEATXR+/ BPi2XKOxaWhQ3/szNmKyzoXDHZEF5AOJVpiwgqkL4JHWKr5VUcRttvdQjDKw7KZVvKtm Wyxe3uuYnIxiO6EiJM5cGusWVWRBNALNoNfQ3Okd+MnBS89slMUR8X9i8UzOThqerMFX ZjHq1NhrZTUezD9ZmAGQ3kWfuSNwSFAAgHbvuGYp1+gAypljR58z5hDKzLnoiBaP9NYK DziQ== 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=VRzZ0RX+KfqMvoBfNyIq4YMAcx7bekYku+RCjIJS7r0=; b=zmUDCH9uRgA1JzSwPJiuEQS/Ibmz4r8RSVpQfzsoFU08NbvJEAA3uh17rcLW+y8jPm XU5eiUDaTk/Rs99vJ0NRNBQE1Sm1qpFuYvrel/sq5RN6DPRB2XZIyF4ZKPKSxsJidnba 5BVrYpLAQwO+ViWntuPKFK92B/FUny2XSUiynVAclhnpyMukgkTHllVbFUR3Qe3qSoWc s2Y76pawLbJzB0Z8jF2Acs487tznbaXkABAsn3BfA6rn4MSHsdyMLUjNvSGPwsRb2rXM 3PtQqC9qr28IjRm1728XkW2CCsPLZFw6mDiaQ2rPk+6zI8Byk0vuvVVpNr1rH5O1bM8R mM6A== 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 x24-v6si396116pll.83.2018.03.13.09.57.41; Tue, 13 Mar 2018 09:57:56 -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 S933231AbeCMPaX (ORCPT + 99 others); Tue, 13 Mar 2018 11:30:23 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58766 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752148AbeCMPaT (ORCPT ); Tue, 13 Mar 2018 11:30:19 -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 8A5C6F8F; Tue, 13 Mar 2018 15:30:18 +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.15 061/146] bcache: dont attach backing with duplicate UUID Date: Tue, 13 Mar 2018 16:23:48 +0100 Message-Id: <20180313152325.385945864@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152320.439085687@linuxfoundation.org> References: <20180313152320.439085687@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.15-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 @@ -951,6 +951,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); @@ -974,6 +975,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 &&