From: Gao Xiang <gaoxiang25@huawei.com>
To: Chao Yu <yuchao0@huawei.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
<devel@driverdev.osuosl.org>, LKML <linux-kernel@vger.kernel.org>,
<linux-erofs@lists.ozlabs.org>, Chao Yu <chao@kernel.org>,
Miao Xie <miaoxie@huawei.com>, <weidu.du@huawei.com>,
"Fang Wei" <fangwei1@huawei.com>, <stable@vger.kernel.org>
Subject: Re: [PATCH v2] staging: erofs: keep corrupted fs from crashing kernel in erofs_namei()
Date: Mon, 18 Feb 2019 10:17:28 +0800 [thread overview]
Message-ID: <56f03bdf-1817-6b3e-44d5-922637ac39f4@huawei.com> (raw)
In-Reply-To: <31ba7d15-058e-1996-3482-65fbd1e83e26@huawei.com>
Hi Chao,
On 2019/2/18 9:39, Chao Yu wrote:
> If the image is corrupted, qn->name[i] may be anything, as you commented
> above DBG_BUGON(), we really don't need to go through any later codes, it
> can avoid potentially encoutnering wrong condition.
>
> * otherwise, it will return 1 to just skip the invalid name
>
Just I commented in the following source code, qn is actually the user requested
name allocated in __d_alloc, which can be guaranteed with the trailing '\0' and
it is a valid string.
Thanks,
Gao Xiang
>>>> +
>>>> + /* qd could not have trailing '\0' */
>>>> + /* However it is absolutely safe if < qd->end */
>>>> + while (qd->name + i < qd->end && qd->name[i] != '\0') {
>>>> + if (qn->name[i] != qd->name[i]) {
>>>> + *matched = i;
>>>> + return qn->name[i] > qd->name[i] ? 1 : -1;
>>>> }
>>>> - return (qn->len > qd->len);
>>>> + ++i;
>>>> }
>>>> -
>>>> - if (qn->name[i] != qd->name[i]) {
>>>> - *matched = i;
>>>> - return qn->name[i] > qd->name[i] ? 1 : -1;
>>>> - }
>>>> -
>>>> - ++i;
>>>> - goto loop;
>>>> + *matched = i;
>>>> + /* See comments in __d_alloc on the terminating NUL character */
>>>> + return qn->name[i] == '\0' ? 0 : 1;
>>>> }
next prev parent reply other threads:[~2019-02-18 2:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-01 12:16 [PATCH v2] staging: erofs: keep corrupted fs from crashing kernel in erofs_namei() Gao Xiang
2019-02-12 5:05 ` Gao Xiang
2019-02-15 7:02 ` Chao Yu
2019-02-15 7:57 ` Dan Carpenter
2019-02-15 9:04 ` Gao Xiang
2019-02-15 9:32 ` Chao Yu
2019-02-15 9:35 ` Dan Carpenter
2019-02-15 10:33 ` Gao Xiang
2019-02-18 2:41 ` Chao Yu
2019-02-18 6:16 ` Dan Carpenter
2019-02-15 8:58 ` Gao Xiang
2019-02-18 1:39 ` Chao Yu
2019-02-18 2:17 ` Gao Xiang [this message]
2019-02-18 2:50 ` Chao Yu
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=56f03bdf-1817-6b3e-44d5-922637ac39f4@huawei.com \
--to=gaoxiang25@huawei.com \
--cc=chao@kernel.org \
--cc=devel@driverdev.osuosl.org \
--cc=fangwei1@huawei.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miaoxie@huawei.com \
--cc=stable@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
--cc=weidu.du@huawei.com \
--cc=yuchao0@huawei.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;
as well as URLs for NNTP newsgroup(s).