From: Theodore Ts'o Date: Sun, 24 Aug 2008 02:27:22 +0000 (-0400) Subject: libblkid: Strengthen the JFS probe routine X-Git-Tag: v1.41.1~54 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=b41fb002257d4b997560cd77676b78219be03c24;p=tools%2Fe2fsprogs.git libblkid: Strengthen the JFS probe routine Check to make sure a JFS filesystem is really correct by checking the relationship between the following fields in the JFS superblock: s_bsize, s_l2bsize, s_pbsize, s_l2pbsize, and s_l2bfactor. Thanks to Lesh Bogdanow for this suggestion. Signed-off-by: "Theodore Ts'o" --- diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c index 225116a..92052e1 100644 --- a/lib/blkid/probe.c +++ b/lib/blkid/probe.c @@ -780,6 +780,16 @@ static int probe_jfs(struct blkid_probe *probe, js = (struct jfs_super_block *)buf; + if (blkid_le32(js->js_bsize) != (1 << blkid_le16(js->js_l2bsize))) + return 1; + + if (blkid_le32(js->js_pbsize) != (1 << blkid_le16(js->js_l2pbsize))) + return 1; + + if ((blkid_le16(js->js_l2bsize) - blkid_le16(js->js_l2pbsize)) != + blkid_le16(js->js_l2bfactor)) + return 1; + if (strlen((char *) js->js_label)) label = (char *) js->js_label; blkid_set_tag(probe->dev, "LABEL", label, sizeof(js->js_label)); diff --git a/lib/blkid/probe.h b/lib/blkid/probe.h index ac3a083..993156d 100644 --- a/lib/blkid/probe.h +++ b/lib/blkid/probe.h @@ -181,10 +181,13 @@ struct jfs_super_block { unsigned char js_magic[4]; __u32 js_version; __u64 js_size; - __u32 js_bsize; - __u32 js_dummy1; - __u32 js_pbsize; - __u32 js_dummy2[27]; + __u32 js_bsize; /* 4: aggregate block size in bytes */ + __u16 js_l2bsize; /* 2: log2 of s_bsize */ + __u16 js_l2bfactor; /* 2: log2(s_bsize/hardware block size) */ + __u32 js_pbsize; /* 4: hardware/LVM block size in bytes */ + __u16 js_l2pbsize; /* 2: log2 of s_pbsize */ + __u16 js_pad; /* 2: padding necessary for alignment */ + __u32 js_dummy2[26]; unsigned char js_uuid[16]; unsigned char js_label[16]; unsigned char js_loguuid[16];