From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: Jia-Ju Bai <baijiaju@buaa.edu.cn>
Cc: <ntfs3@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] fs: ntfs3: Fix possible null-pointer dereferences in mi_read()
Date: Mon, 8 May 2023 16:57:32 +0400 [thread overview]
Message-ID: <16b5bd2f-8098-0447-d3c9-0e764cf78d01@paragon-software.com> (raw)
In-Reply-To: <20230321132211.3103922-1-baijiaju@buaa.edu.cn>
On 21.03.2023 17:22, Jia-Ju Bai wrote:
> In a previous commit 2681631c2973 ("fs/ntfs3: Add null pointer check to
> attr_load_runs_vcn"), ni can be NULL in attr_load_runs_vcn(), and thus it
> should be checked before being used.
>
> However, in the call stack of this commit, mft_ni in mi_read() is
> aliased with ni in attr_load_runs_vcn(), and it is also used in
> mi_read() at two places:
>
> mi_read()
> rw_lock = &mft_ni->file.run_lock -> No check
> attr_load_runs_vcn(mft_ni, ...)
> ni (namely mft_ni) is checked in the previous commit
> attr_load_runs_vcn(..., &mft_ni->file.run) -> No check
>
> Thus, to avoid possible null-pointer dereferences, the related checks
> should be added.
>
> These bugs are reported by a static analysis tool implemented by myself,
> and they are found by extending a known bug fixed in the previous commit.
> Thus, they could be theoretical bugs.
>
> Signed-off-by: Jia-Ju Bai <baijiaju@buaa.edu.cn>
> ---
> fs/ntfs3/record.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
> index defce6a5c8e1..dfa1fed9c0d9 100644
> --- a/fs/ntfs3/record.c
> +++ b/fs/ntfs3/record.c
> @@ -124,7 +124,7 @@ int mi_read(struct mft_inode *mi, bool is_mft)
> struct rw_semaphore *rw_lock = NULL;
>
> if (is_mounted(sbi)) {
> - if (!is_mft) {
> + if (!is_mft && mft_ni) {
> rw_lock = &mft_ni->file.run_lock;
> down_read(rw_lock);
> }
> @@ -148,7 +148,7 @@ int mi_read(struct mft_inode *mi, bool is_mft)
> ni_lock(mft_ni);
> down_write(rw_lock);
> }
> - err = attr_load_runs_vcn(mft_ni, ATTR_DATA, NULL, 0, &mft_ni->file.run,
> + err = attr_load_runs_vcn(mft_ni, ATTR_DATA, NULL, 0, run,
> vbo >> sbi->cluster_bits);
> if (rw_lock) {
> up_write(rw_lock);
Thanks, your patch has been applied.
prev parent reply other threads:[~2023-05-08 12:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 13:22 [PATCH] fs: ntfs3: Fix possible null-pointer dereferences in mi_read() Jia-Ju Bai
2023-05-08 12:57 ` Konstantin Komarov [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=16b5bd2f-8098-0447-d3c9-0e764cf78d01@paragon-software.com \
--to=almaz.alexandrovich@paragon-software.com \
--cc=baijiaju@buaa.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@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 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).