mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 22:21:40 +00:00
fs/adfs: bigdir: calculate and validate directory checkbyte
When reading a big directory, calculate the validate the directory checkbyte to ensure that the directory contents are valid. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
aa3d4e0152
commit
d79288b4f6
@ -67,6 +67,39 @@ static int adfs_fplus_validate_tail(const struct adfs_bigdirheader *h,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8 adfs_fplus_checkbyte(struct adfs_dir *dir)
|
||||
{
|
||||
struct adfs_bigdirheader *h = dir->bighead;
|
||||
struct adfs_bigdirtail *t = dir->bigtail;
|
||||
unsigned int end, bs, bi, i;
|
||||
__le32 *bp;
|
||||
u32 dircheck;
|
||||
|
||||
end = adfs_fplus_offset(h, le32_to_cpu(h->bigdirentries)) +
|
||||
le32_to_cpu(h->bigdirnamesize);
|
||||
|
||||
/* Accumulate the contents of the header, entries and names */
|
||||
for (dircheck = 0, bi = 0; end; bi++) {
|
||||
bp = (void *)dir->bhs[bi]->b_data;
|
||||
bs = dir->bhs[bi]->b_size;
|
||||
if (bs > end)
|
||||
bs = end;
|
||||
|
||||
for (i = 0; i < bs; i += sizeof(u32))
|
||||
dircheck = ror32(dircheck, 13) ^ le32_to_cpup(bp++);
|
||||
|
||||
end -= bs;
|
||||
}
|
||||
|
||||
/* Accumulate the contents of the tail except for the check byte */
|
||||
dircheck = ror32(dircheck, 13) ^ le32_to_cpu(t->bigdirendname);
|
||||
dircheck = ror32(dircheck, 13) ^ t->bigdirendmasseq;
|
||||
dircheck = ror32(dircheck, 13) ^ t->reserved[0];
|
||||
dircheck = ror32(dircheck, 13) ^ t->reserved[1];
|
||||
|
||||
return dircheck ^ dircheck >> 8 ^ dircheck >> 16 ^ dircheck >> 24;
|
||||
}
|
||||
|
||||
static int adfs_fplus_read(struct super_block *sb, u32 indaddr,
|
||||
unsigned int size, struct adfs_dir *dir)
|
||||
{
|
||||
@ -107,6 +140,11 @@ static int adfs_fplus_read(struct super_block *sb, u32 indaddr,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (adfs_fplus_checkbyte(dir) != t->bigdircheckbyte) {
|
||||
adfs_error(sb, "dir %06x checkbyte mismatch\n", indaddr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
dir->parent_id = le32_to_cpu(h->bigdirparent);
|
||||
return 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user