From 2d210697649c51101f1bbf733b2b6b9e8bc3f551 Mon Sep 17 00:00:00 2001 From: "mwilck@arcor.de" Date: Fri, 1 Mar 2013 23:28:31 +0100 Subject: [PATCH] DDF: add sanity checks in compare_super_ddf Besides container GUID, also check seqnum, physical and virtual disk numbers, and check match between local and global sections. Signed-off-by: Martin Wilck Signed-off-by: NeilBrown --- super-ddf.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/super-ddf.c b/super-ddf.c index 81649d45..8af4fba8 100644 --- a/super-ddf.c +++ b/super-ddf.c @@ -3369,6 +3369,9 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst) */ struct ddf_super *first = st->sb; struct ddf_super *second = tst->sb; + struct dl *dl2; + struct vcl *vl2; + unsigned int max_vds, max_pds, pd, vd; if (!first) { st->sb = tst->sb; @@ -3379,7 +3382,46 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst) if (memcmp(first->anchor.guid, second->anchor.guid, DDF_GUID_LEN) != 0) return 2; + if (first->anchor.seq != second->anchor.seq) { + dprintf("%s: sequence number mismatch %u/%u\n", __func__, + __be32_to_cpu(first->anchor.seq), + __be32_to_cpu(second->anchor.seq)); + return 3; + } + if (first->max_part != second->max_part || + first->phys->used_pdes != second->phys->used_pdes || + first->virt->populated_vdes != second->virt->populated_vdes) { + dprintf("%s: PD/VD number mismatch\n", __func__); + return 3; + } + + max_pds = __be16_to_cpu(first->phys->used_pdes); + for (dl2 = second->dlist; dl2; dl2 = dl2->next) { + for (pd = 0; pd < max_pds; pd++) + if (first->phys->entries[pd].refnum == dl2->disk.refnum) + break; + if (pd == max_pds) { + dprintf("%s: no match for disk %08x\n", __func__, + __be32_to_cpu(dl2->disk.refnum)); + return 3; + } + } + + max_vds = __be16_to_cpu(first->active->max_vd_entries); + for (vl2 = second->conflist; vl2; vl2 = vl2->next) { + if (vl2->conf.magic != DDF_VD_CONF_MAGIC) + continue; + for (vd = 0; vd < max_vds; vd++) + if (!memcmp(first->virt->entries[vd].guid, + vl2->conf.guid, DDF_GUID_LEN)) + break; + if (vd == max_vds) { + dprintf("%s: no match for VD config\n", __func__); + return 3; + } + } /* FIXME should I look at anything else? */ + return 0; } -- 2.39.2