linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Jin Qian <jinqian@google.com>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [PATCH 1/1] f2fs-tools: sanity check segno and blk_off when building curseg array
Date: Thu, 27 Apr 2017 15:41:48 -0700	[thread overview]
Message-ID: <20170427224148.GA14138@jaegeuk.local> (raw)
In-Reply-To: <20170427220349.35334-1-jinqian@google.com>

Hi Jin,

On 04/27, Jin Qian wrote:
> segno and blk_off were read from input image without sanity check. This
> could lead to buffer overflow when accessing internal arrays like SIT
> sentries and seg_entry cur_valid_map.
> 
> Signed-off-by: Jin Qian <jinqian@google.com>
> ---
>  fsck/mount.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fsck/mount.c b/fsck/mount.c
> index ffaa0ed..749c417 100644
> --- a/fsck/mount.c
> +++ b/fsck/mount.c
> @@ -1040,6 +1040,9 @@ static void build_curseg(struct f2fs_sb_info *sbi)
>  			blk_off = get_cp(cur_node_blkoff[i - CURSEG_HOT_NODE]);
>  			segno = get_cp(cur_node_segno[i - CURSEG_HOT_NODE]);
>  		}
> +		ASSERT(segno < TOTAL_SEGS(sbi));
> +		ASSERT((blk_off >> 3) < SIT_VBLOCK_MAP_SIZE);

		ASSERT(blk_off < DEFAULT_BLOCKS_PER_SEGMENT);

Otherwise, blk_off can be cut by shift operation.

Thanks,

> +
>  		array[i].segno = segno;
>  		array[i].zone = GET_ZONENO_FROM_SEGNO(sbi, segno);
>  		array[i].next_segno = NULL_SEGNO;
> -- 
> 2.13.0.rc0.306.g87b477812d-goog

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

      reply	other threads:[~2017-04-27 22:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-27 22:03 [PATCH 1/1] f2fs-tools: sanity check segno and blk_off when building curseg array Jin Qian
2017-04-27 22:41 ` Jaegeuk Kim [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170427224148.GA14138@jaegeuk.local \
    --to=jaegeuk@kernel.org \
    --cc=jinqian@google.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).