Received: by 10.213.65.68 with SMTP id h4csp522809imn; Fri, 16 Mar 2018 10:18:36 -0700 (PDT) X-Google-Smtp-Source: AG47ELvbAFN8BmKdKq/Yw0L7tVuUuQZMG/pBBVL10h06tNiy/IcEnmaz82H/iIIiM/lpAe5vlWVR X-Received: by 10.98.85.197 with SMTP id j188mr2207767pfb.86.1521220716204; Fri, 16 Mar 2018 10:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521220716; cv=none; d=google.com; s=arc-20160816; b=k/BNrMc5KRLXaWk/zp82wytiw/kDnWbY6CViDxtx91viCxWtZjKfmKnBSQ7xkL1s1W 8koNWQtkfC/VccnDuJ38f0GLwouJ4ipPV90Gtkvq/UH2rm9ZF8x5TRBwsKWRPnY7u1nU ZFOP4GMfKjJMfqilLzvBzqof4NehBzSX8VOqQtpFsmuR1EpLtSZcK8YmEcdxXWtaPLR6 KIQHP3o8NIYx2Hz9vN4R1AVWeNMNV0DsC6qDNpmkBfNMaEuuihgjuroIhbmUwNnzIwbT 3lFKlBPTPsKvzjRXoXQLjgqjii1ajMoc7Q+Zz9frZeBZ4l1IE3Bz10WPmnSdIifMgkmv S5dw== 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=ay5ZyH9giRV/DPrXL70suTAgdNmnVnLSj9RMxjcT16c=; b=Q+EPJlT/B+oGPFb+Dow2JxhXpqa2AALxM3H7RFcsiBmyZdOIS5UtoPeoDG8xkPVSLU kFPtgU3GIDY9CdGzreKa8czW56BuwcUsnkw3LIE6CidpCaX2iHVfd4Fdcop9DnrZ8H6r g9cpKE4gqEoM4IhhP8+jvCB+EWrQsY6A3pHBngTU5WsEwfY+OCutImznQfXyPAX6kCWE khmozBteyUrfHfOHn7i+Kyjv03py0A018/YvHS/kVSdsi/3n1GGCvAg8CukfgqdOZW1o NQOT8AeTsL5rw4IU50yyVrgMxaxh0Bnfyrpe/Ws9/AYU/1yRLwUKRsSh7JilHWKukOFn ksOg== 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 s3-v6si6347327plb.4.2018.03.16.10.18.21; Fri, 16 Mar 2018 10:18:36 -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 S1754411AbeCPPax (ORCPT + 99 others); Fri, 16 Mar 2018 11:30:53 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37010 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933262AbeCPPat (ORCPT ); Fri, 16 Mar 2018 11:30:49 -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 D5EF810BE; Fri, 16 Mar 2018 15:30:44 +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.9 27/86] bcache: dont attach backing with duplicate UUID Date: Fri, 16 Mar 2018 16:22:50 +0100 Message-Id: <20180316152319.238331761@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152317.167709497@linuxfoundation.org> References: <20180316152317.167709497@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.9-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 @@ -937,6 +937,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); @@ -960,6 +961,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 &&