Re: [PATCH] hfs: Sanity check the root record

From: Jan Kara
Date: Tue Nov 26 2024 - 16:53:10 EST


On Tue 26-11-24 09:21:50, Leo Stone wrote:
> Hello,
>
> On Tue, Nov 26, 2024 at 10:33:13AM +0100, Jan Kara wrote:
> >
> > This certainly won't hurt but shouldn't we also add some stricter checks
> > for entry length so that we know we've loaded enough data to have full info
> > about the root dir?
>
> Yes, that would be a good idea. Do we want to keep the existing checks
> and just make sure we have at least enough to initialize the struct:
>
> if (fd.entrylength > sizeof(rec) || fd.entrylength < 0 ||
> fd.entrylength < sizeof(rec.dir)) {
> res = -EIO;
> goto bail_hfs_find;
> }
>
> Or be even stricter and only accept the exact length:
>
> if (fd.entrylength != sizeof(rec.dir)) {
> res = -EIO;
> goto bail_hfs_find;
> }

Yes, this strict check would make sense to me. I just don't know HFS good
enough whether this is a safe assumption to make so it would be good to
test with some HFS filesystem.

Honza
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR