From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: lei lu <llfamsec@gmail.com>
Cc: mark@fasheh.com, jlbec@evilplan.org, ocfs2-devel@lists.linux.dev,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] ocfs2: add bounds checking to ocfs2_search_dirblock()
Date: Mon, 27 May 2024 10:33:02 +0800 [thread overview]
Message-ID: <059f5953-4f6d-4580-9bc5-685a03364987@linux.alibaba.com> (raw)
In-Reply-To: <20240526110631.10618-1-llfamsec@gmail.com>
On 5/26/24 7:06 PM, lei lu wrote:
> Add a check to make sure all members of the ocfs2_dir_entry
> don't stray beyond valid memory region.
>
> Signed-off-by: lei lu <llfamsec@gmail.com>
> ---
> fs/ocfs2/dir.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
> index d620d4c53c6f..385576d86983 100644
> --- a/fs/ocfs2/dir.c
> +++ b/fs/ocfs2/dir.c
> @@ -358,6 +358,17 @@ static inline int ocfs2_search_dirblock(struct buffer_head *bh,
>
> de = (struct ocfs2_dir_entry *) de_buf;
>
> + if (unlikely(de_buf + OCFS2_DIR_MEMBER_LEN > dlimit)) {
> + ret = -1;
> + goto bail;
> + }
It seems that this check can be moved to:
while (de_buf < dlimit - OCFS2_DIR_MEMBER_LEN) {
...
}
> + de_len = le16_to_cpu(de->rec_len);
> + if (unlikely(de_buf + de_len > dlimit) ||
dlimit = de_buf + bytes;
So here you mean check de_len < bytes?
Or should we check more precisely, like in ocfs2_check_dir_entry():
(de - bh->b_data) + de_len > bytes - OCFS2_DIR_REC_LEN(de->name_len)
> + unlikely(de_len < OCFS2_DIR_REC_LEN(de->name_len))) {
This is already done in ocfs2_check_dir_entry().
> + ret = -1;
> + goto bail;
> + }
> +
> if (de_buf + namelen <= dlimit &&
> ocfs2_match(namelen, name, de)) {
> /* found a match - just to be sure, do a full check */
> @@ -371,7 +382,6 @@ static inline int ocfs2_search_dirblock(struct buffer_head *bh,
> }
>
> /* prevent looping on a bad block */
> - de_len = le16_to_cpu(de->rec_len);
> if (de_len <= 0) {
> ret = -1;
> goto bail;
next prev parent reply other threads:[~2024-05-27 2:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-26 11:06 [PATCH] ocfs2: add bounds checking to ocfs2_search_dirblock() lei lu
2024-05-27 2:33 ` Joseph Qi [this message]
[not found] ` <CAEBF3_b6uSbo5s6dk=Vvt+mYzSjzzx0RMnaHQcc+YdWco6Dpzw@mail.gmail.com>
[not found] ` <CAEBF3_anUzNk6gwLG0d=_5QyWeStvkmp_nT9Z_k9fFdjvJ-wiQ@mail.gmail.com>
2024-05-27 3:32 ` Joseph Qi
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=059f5953-4f6d-4580-9bc5-685a03364987@linux.alibaba.com \
--to=joseph.qi@linux.alibaba.com \
--cc=gregkh@linuxfoundation.org \
--cc=jlbec@evilplan.org \
--cc=llfamsec@gmail.com \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.