From: David Sterba <dsterba@suse.cz>
To: Su Yue <suy.fnst@cn.fujitsu.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/3] btrfs: Introduce btrfs_check_namelen to avoid reading beyond boundary
Date: Mon, 29 May 2017 17:22:43 +0200 [thread overview]
Message-ID: <20170529152243.GL14523@twin.jikos.cz> (raw)
In-Reply-To: <20170525020908.25830-1-suy.fnst@cn.fujitsu.com>
On Thu, May 25, 2017 at 10:09:06AM +0800, Su Yue wrote:
> When reading out name from inode_ref, dir_item, it's possible that
> corrupted name_len lead to read beyond boundary.
>
> Since there are already patches for btrfs-progs, this is for btrfs.
>
> Introduce function btrfs_check_namelen, it should be called before reading
> name from extent_buffer.
> The function compares arg @namelen with boundary then returns 'proper'
> namelen.
>
> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Such validation is useful, but I'm concerned about the proposed
implementation and usage pattern.
> +/*
> + * Returns >0: the value @namelen after cut according item boundary
> + * Returns 0: on error
> + */
> +u16 btrfs_check_namelen(struct extent_buffer *leaf, int slot,
> + unsigned long start, u32 namelen)
This function does not match its name, it does not check, but somehow
sanitizes the input length read from the leaf. From a "check" I'd expect
some good/bad result, so it could be used in an if statement.
> +{
> + u32 end;
> + u64 ret = namelen;
> +
> + end = btrfs_leaf_data(leaf) + btrfs_item_end_nr(leaf, slot);
> +
> + if (start > end)
> + return 0;
> + if (start + namelen > end) {
> + ret = end - start;
> + if (ret > U16_MAX)
Where does this limit come from?
> + ret = 0;
> + }
> + return ret;
ret is u64, function returns u16.
> +}
next prev parent reply other threads:[~2017-05-29 15:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-25 2:09 [PATCH 1/3] btrfs: Introduce btrfs_check_namelen to avoid reading beyond boundary Su Yue
2017-05-25 2:09 ` [PATCH 2/3] btrfs: check namelen with boundary in verify dir_item Su Yue
2017-05-29 15:24 ` David Sterba
2017-05-25 2:09 ` [PATCH 3/3] btrfs: check namelen before read/memcmp_extent_buffer Su Yue
2017-05-29 15:43 ` David Sterba
2017-05-31 2:31 ` Su Yue
2017-05-29 15:22 ` David Sterba [this message]
2017-05-29 15:33 ` [PATCH 1/3] btrfs: Introduce btrfs_check_namelen to avoid reading beyond boundary David Sterba
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=20170529152243.GL14523@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=suy.fnst@cn.fujitsu.com \
/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