* [f2fs-dev] [PATCH v2] f2fs: avoid out-of-range memory access @ 2019-07-02 8:05 Ocean Chen via Linux-f2fs-devel 2019-07-03 2:07 ` Chao Yu 0 siblings, 1 reply; 5+ messages in thread From: Ocean Chen via Linux-f2fs-devel @ 2019-07-02 8:05 UTC (permalink / raw) To: jaegeuk, yuchao0, linux-f2fs-devel, linux-kernel; +Cc: oceanchen blk_off might over 512 due to fs corrupt. Use ENTRIES_IN_SUM to protect invalid memory access. v2: - fix typo Signed-off-by: Ocean Chen <oceanchen@google.com> --- fs/f2fs/segment.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 8dee063c833f..a5e8af0bd62e 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3403,6 +3403,8 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) for (j = 0; j < blk_off; j++) { struct f2fs_summary *s; + if (j >= ENTRIES_IN_SUM) + return -EFAULT; s = (struct f2fs_summary *)(kaddr + offset); seg_i->sum_blk->entries[j] = *s; offset += SUMMARY_SIZE; -- 2.22.0.410.gd8fdbe21b5-goog _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: avoid out-of-range memory access 2019-07-02 8:05 [f2fs-dev] [PATCH v2] f2fs: avoid out-of-range memory access Ocean Chen via Linux-f2fs-devel @ 2019-07-03 2:07 ` Chao Yu 2019-07-03 15:03 ` Ocean Chen via Linux-f2fs-devel 0 siblings, 1 reply; 5+ messages in thread From: Chao Yu @ 2019-07-03 2:07 UTC (permalink / raw) To: Ocean Chen, jaegeuk, linux-f2fs-devel, linux-kernel Hi Ocean, If filesystem is corrupted, it should fail mount due to below check in f2fs_sanity_check_ckpt(), so we are safe in read_compacted_summaries() to access entries[0,blk_off], right? for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) return 1; Thanks, On 2019/7/2 16:05, Ocean Chen wrote: > blk_off might over 512 due to fs corrupt. > Use ENTRIES_IN_SUM to protect invalid memory access. > > v2: > - fix typo > Signed-off-by: Ocean Chen <oceanchen@google.com> > --- > fs/f2fs/segment.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > index 8dee063c833f..a5e8af0bd62e 100644 > --- a/fs/f2fs/segment.c > +++ b/fs/f2fs/segment.c > @@ -3403,6 +3403,8 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) > > for (j = 0; j < blk_off; j++) { > struct f2fs_summary *s; > + if (j >= ENTRIES_IN_SUM) > + return -EFAULT; > s = (struct f2fs_summary *)(kaddr + offset); > seg_i->sum_blk->entries[j] = *s; > offset += SUMMARY_SIZE; > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: avoid out-of-range memory access 2019-07-03 2:07 ` Chao Yu @ 2019-07-03 15:03 ` Ocean Chen via Linux-f2fs-devel 2019-07-04 7:11 ` Chao Yu 0 siblings, 1 reply; 5+ messages in thread From: Ocean Chen via Linux-f2fs-devel @ 2019-07-03 15:03 UTC (permalink / raw) To: yuchao0, jaegeuk, linux-f2fs-devel, linux-kernel Hi Yu Chao, The cur_data_segno only was checked in mount process. In terms of security concern, it's better to check value before using it. I know the risk is low. IMHO, it can be safer. BTW, I found we can only check blk_off before for loop instead of checking 'j' in each iteratoin. On Wed, Jul 03, 2019 at 10:07:11AM +0800, Chao Yu wrote: > Hi Ocean, > > If filesystem is corrupted, it should fail mount due to below check in > f2fs_sanity_check_ckpt(), so we are safe in read_compacted_summaries() to access > entries[0,blk_off], right? > > for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { > if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || > le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) > return 1; > > Thanks, > > On 2019/7/2 16:05, Ocean Chen wrote: > > blk_off might over 512 due to fs corrupt. > > Use ENTRIES_IN_SUM to protect invalid memory access. > > > > v2: > > - fix typo > > Signed-off-by: Ocean Chen <oceanchen@google.com> > > --- > > fs/f2fs/segment.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > > index 8dee063c833f..a5e8af0bd62e 100644 > > --- a/fs/f2fs/segment.c > > +++ b/fs/f2fs/segment.c > > @@ -3403,6 +3403,8 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) > > > > for (j = 0; j < blk_off; j++) { > > struct f2fs_summary *s; > > + if (j >= ENTRIES_IN_SUM) > > + return -EFAULT; > > s = (struct f2fs_summary *)(kaddr + offset); > > seg_i->sum_blk->entries[j] = *s; > > offset += SUMMARY_SIZE; > > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: avoid out-of-range memory access 2019-07-03 15:03 ` Ocean Chen via Linux-f2fs-devel @ 2019-07-04 7:11 ` Chao Yu 2019-07-08 3:21 ` Ocean Chen via Linux-f2fs-devel 0 siblings, 1 reply; 5+ messages in thread From: Chao Yu @ 2019-07-04 7:11 UTC (permalink / raw) To: Ocean Chen, jaegeuk, linux-f2fs-devel, linux-kernel Hi Ocean, On 2019/7/3 23:03, Ocean Chen wrote: > Hi Yu Chao, > > The cur_data_segno only was checked in mount process. In terms of > security concern, it's better to check value before using it. I know the Could you explain more about security concern.. Do you get any report from user or tools that complaining f2fs issue/codes? I'm not against sanity check for basic core data of filesystem in run-time, but, in order to troubleshoot root cause of this issue we can trigger panic directly to dump more info under F2FS_CHECK_FS macro. So, maybe we can change as below? blk_off = le16_to_cpu(ckpt->cur_data_blkoff[i]); +if (blk_off > ENTRIES_IN_SUM) { + f2fs_bug_on(1); + f2fs_put_page(page, 1); + return -EFAULT; +} Thanks, > risk is low. IMHO, it can be safer. > BTW, I found we can only check blk_off before for loop instead of > checking 'j' in each iteratoin. > > On Wed, Jul 03, 2019 at 10:07:11AM +0800, Chao Yu wrote: >> Hi Ocean, >> >> If filesystem is corrupted, it should fail mount due to below check in >> f2fs_sanity_check_ckpt(), so we are safe in read_compacted_summaries() to access >> entries[0,blk_off], right? >> >> for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { >> if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || >> le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) >> return 1; >> >> Thanks, >> >> On 2019/7/2 16:05, Ocean Chen wrote: >>> blk_off might over 512 due to fs corrupt. >>> Use ENTRIES_IN_SUM to protect invalid memory access. >>> >>> v2: >>> - fix typo >>> Signed-off-by: Ocean Chen <oceanchen@google.com> >>> --- >>> fs/f2fs/segment.c | 2 ++ >>> 1 file changed, 2 insertions(+) >>> >>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c >>> index 8dee063c833f..a5e8af0bd62e 100644 >>> --- a/fs/f2fs/segment.c >>> +++ b/fs/f2fs/segment.c >>> @@ -3403,6 +3403,8 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) >>> >>> for (j = 0; j < blk_off; j++) { >>> struct f2fs_summary *s; >>> + if (j >= ENTRIES_IN_SUM) >>> + return -EFAULT; >>> s = (struct f2fs_summary *)(kaddr + offset); >>> seg_i->sum_blk->entries[j] = *s; >>> offset += SUMMARY_SIZE; >>> > . > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: avoid out-of-range memory access 2019-07-04 7:11 ` Chao Yu @ 2019-07-08 3:21 ` Ocean Chen via Linux-f2fs-devel 0 siblings, 0 replies; 5+ messages in thread From: Ocean Chen via Linux-f2fs-devel @ 2019-07-08 3:21 UTC (permalink / raw) To: yuchao0, jaegeuk, linux-f2fs-devel, linux-kernel Hi YuChao, Yes, we got externel researcher reports this security vulnerability. And dump info is better when blk_off is invalid. I'll prepare the next patch for it. On Thu, Jul 04, 2019 at 03:11:27PM +0800, Chao Yu wrote: > Hi Ocean, > > On 2019/7/3 23:03, Ocean Chen wrote: > > Hi Yu Chao, > > > > The cur_data_segno only was checked in mount process. In terms of > > security concern, it's better to check value before using it. I know the > > Could you explain more about security concern.. Do you get any report from user > or tools that complaining f2fs issue/codes? > > I'm not against sanity check for basic core data of filesystem in run-time, but, > in order to troubleshoot root cause of this issue we can trigger panic directly > to dump more info under F2FS_CHECK_FS macro. > > So, maybe we can change as below? > > blk_off = le16_to_cpu(ckpt->cur_data_blkoff[i]); > +if (blk_off > ENTRIES_IN_SUM) { > + f2fs_bug_on(1); > + f2fs_put_page(page, 1); > + return -EFAULT; > +} > > Thanks, > > > risk is low. IMHO, it can be safer. > > BTW, I found we can only check blk_off before for loop instead of > > checking 'j' in each iteratoin. > > > > On Wed, Jul 03, 2019 at 10:07:11AM +0800, Chao Yu wrote: > >> Hi Ocean, > >> > >> If filesystem is corrupted, it should fail mount due to below check in > >> f2fs_sanity_check_ckpt(), so we are safe in read_compacted_summaries() to access > >> entries[0,blk_off], right? > >> > >> for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { > >> if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || > >> le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) > >> return 1; > >> > >> Thanks, > >> > >> On 2019/7/2 16:05, Ocean Chen wrote: > >>> blk_off might over 512 due to fs corrupt. > >>> Use ENTRIES_IN_SUM to protect invalid memory access. > >>> > >>> v2: > >>> - fix typo > >>> Signed-off-by: Ocean Chen <oceanchen@google.com> > >>> --- > >>> fs/f2fs/segment.c | 2 ++ > >>> 1 file changed, 2 insertions(+) > >>> > >>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > >>> index 8dee063c833f..a5e8af0bd62e 100644 > >>> --- a/fs/f2fs/segment.c > >>> +++ b/fs/f2fs/segment.c > >>> @@ -3403,6 +3403,8 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) > >>> > >>> for (j = 0; j < blk_off; j++) { > >>> struct f2fs_summary *s; > >>> + if (j >= ENTRIES_IN_SUM) > >>> + return -EFAULT; > >>> s = (struct f2fs_summary *)(kaddr + offset); > >>> seg_i->sum_blk->entries[j] = *s; > >>> offset += SUMMARY_SIZE; > >>> > > . > > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-07-08 3:21 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-07-02 8:05 [f2fs-dev] [PATCH v2] f2fs: avoid out-of-range memory access Ocean Chen via Linux-f2fs-devel 2019-07-03 2:07 ` Chao Yu 2019-07-03 15:03 ` Ocean Chen via Linux-f2fs-devel 2019-07-04 7:11 ` Chao Yu 2019-07-08 3:21 ` Ocean Chen via Linux-f2fs-devel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).