Re: [f2fs-dev] [PATCH v2 1/2] f2fs: fix to avoid potential memory corruption in __update_iostat_latency()

From: Jaegeuk Kim
Date: Wed Jan 18 2023 - 20:53:49 EST


On 01/16, Yangtao Li wrote:
> Hi Chao,
>
> > Maybe it's betterr to merge these two check condition as below?
> >
> > if (iotype >= NR_PAGE_TYPE) {
> > f2fs_bug_on(sbi, iotype != META_FLUSH);
> > iotype = META;
> > }
>
> For normal , only META_FLUSH will be greater than NR_PAGE_TYPE,
> there is no problem with this logic.
>
> >
> > For CHECK_FS is off case, I guess it's fine to not return and just print
> > warning message for notice.
>
> But if there is an exception, we don't know the type we originally wanted to count.
> If they are all changed to meta, it is possible to get a wrong statistic. I think
> there is no need to make statistics on this kind of error scene. Just like in the
> next patch, if iostat_lat_type is wrong, we should return directly instead of changing
> the value beyond the range to WRITE_ASYNC_IO.
>
> So it's no need tp merge these two check condition?

I also prefer to do like Chao's comment. We don't need to expect such exception
at all.

And, it seems we just need to do like:

enum page_type iotype;

if (iotype == META_FLUSH) {
iotype = META;
} else if (iotype >= NR_PAGE_TYPE) {
f2fs_warn();
return;
}

>
> Thx,
> Yangtao