]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.15.10/bcache-don-t-attach-backing-with-duplicate-uuid.patch
Fix up backported ptrace patch
[thirdparty/kernel/stable-queue.git] / releases / 4.15.10 / bcache-don-t-attach-backing-with-duplicate-uuid.patch
1 From 86755b7a96faed57f910f9e6b8061e019ac1ec08 Mon Sep 17 00:00:00 2001
2 From: Michael Lyle <mlyle@lyle.org>
3 Date: Mon, 5 Mar 2018 13:41:55 -0800
4 Subject: bcache: don't attach backing with duplicate UUID
5
6 From: Michael Lyle <mlyle@lyle.org>
7
8 commit 86755b7a96faed57f910f9e6b8061e019ac1ec08 upstream.
9
10 This can happen e.g. during disk cloning.
11
12 This is an incomplete fix: it does not catch duplicate UUIDs earlier
13 when things are still unattached. It does not unregister the device.
14 Further changes to cope better with this are planned but conflict with
15 Coly's ongoing improvements to handling device errors. In the meantime,
16 one can manually stop the device after this has happened.
17
18 Attempts to attach a duplicate device result in:
19
20 [ 136.372404] loop: module loaded
21 [ 136.424461] bcache: register_bdev() registered backing device loop0
22 [ 136.424464] bcache: bch_cached_dev_attach() Tried to attach loop0 but duplicate UUID already attached
23
24 My test procedure is:
25
26 dd if=/dev/sdb1 of=imgfile bs=1024 count=262144
27 losetup -f imgfile
28
29 Signed-off-by: Michael Lyle <mlyle@lyle.org>
30 Reviewed-by: Tang Junhui <tang.junhui@zte.com.cn>
31 Cc: <stable@vger.kernel.org>
32 Signed-off-by: Jens Axboe <axboe@kernel.dk>
33 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
34
35 ---
36 drivers/md/bcache/super.c | 11 +++++++++++
37 1 file changed, 11 insertions(+)
38
39 --- a/drivers/md/bcache/super.c
40 +++ b/drivers/md/bcache/super.c
41 @@ -951,6 +951,7 @@ int bch_cached_dev_attach(struct cached_
42 uint32_t rtime = cpu_to_le32(get_seconds());
43 struct uuid_entry *u;
44 char buf[BDEVNAME_SIZE];
45 + struct cached_dev *exist_dc, *t;
46
47 bdevname(dc->bdev, buf);
48
49 @@ -974,6 +975,16 @@ int bch_cached_dev_attach(struct cached_
50 return -EINVAL;
51 }
52
53 + /* Check whether already attached */
54 + list_for_each_entry_safe(exist_dc, t, &c->cached_devs, list) {
55 + if (!memcmp(dc->sb.uuid, exist_dc->sb.uuid, 16)) {
56 + pr_err("Tried to attach %s but duplicate UUID already attached",
57 + buf);
58 +
59 + return -EINVAL;
60 + }
61 + }
62 +
63 u = uuid_find(c, dc->sb.uuid);
64
65 if (u &&