Received: by 10.213.65.68 with SMTP id h4csp531967imn; Fri, 16 Mar 2018 10:35:21 -0700 (PDT) X-Google-Smtp-Source: AG47ELu92xzqOslioLfmEhaSuxJNWBXCZwhf5u0kATqmHH+60kFrZGVJri8Ul5AUMWMhH+4HMGpv X-Received: by 10.99.127.75 with SMTP id p11mr2039447pgn.392.1521221720996; Fri, 16 Mar 2018 10:35:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521221720; cv=none; d=google.com; s=arc-20160816; b=injWl0bcn0ZjuuvGik7/NtuwT3aW9LdZdqIYd2fpsDCzphuqyPMPGrI5Q54oakWAjn QXyDUoMLLm40CJ+BAxIhCqjrdeYHlSXS/Mta8nUrNbIINOB1/FzRDxFbPd2kbW6usiYO yDr4XRBSxQZc1SUNhb4yCBNj6VEehId/mhA6ErjpRBQv9YznEWclg7RRmwdtT/ckblgw cvu7GU3idf0Hi0s3uqRoDMWm7m/JMRq6zEjwsJQdSZJ2+zCJQ/w+5GarbARZPCzrxOYF 19eBKtm23xnboxHEg+9vDfOTswKnX7sQ6onyNMl22zxa6mFYsdLWsy3PE1o24n6+8bCp lC6A== 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=dqOc2DVwvV+0hyX9K9nPzxpjArG91KGTeMFD0dzD4yQ=; b=Qs4zVwFgbffncTGhw5+hEj+XNH44Dy8BYQ0RNfmGAy4kMvp1CWZpQ6Lznj5ByxQRYG 1JEaIzPtx0BHQHRgrPONe4I97ByS3jEqPhSrk5KXp5iXLxGkkfVXAURKIUZCOMoCGiXO hTkdSs4t+0oeaNTfUr0yJ7WPckiKIMuPLyFdXN7LE7ygBvMSt1dqftPrcEqqGwa4NjTc FEq5CKR625BjgXYwetaOdVnsHONOi12VD8ZVVtXSfpS8HSJ+RiKslYoVNaNJzJfdCW7J s46r3OWD9TSmZDcDUflA1MpmsiqgamWHTwM/m4mCTC0hIDThq69E6btVYvW0REokhCst VCGg== 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 f5-v6si6622251plf.223.2018.03.16.10.35.07; Fri, 16 Mar 2018 10:35: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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754232AbeCPP1Y (ORCPT + 99 others); Fri, 16 Mar 2018 11:27:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34150 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932356AbeCPP1R (ORCPT ); Fri, 16 Mar 2018 11:27:17 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 40F4A1252; Fri, 16 Mar 2018 15:27:17 +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.4 19/63] bcache: dont attach backing with duplicate UUID Date: Fri, 16 Mar 2018 16:22:51 +0100 Message-Id: <20180316152302.184398395@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152259.964532775@linuxfoundation.org> References: <20180316152259.964532775@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.4-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 @@ -935,6 +935,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); @@ -958,6 +959,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 &&