mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: George Rurikov <g.ryurikov@securitycode.ru>
To: <stable@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: George Ryurikov <g.ryurikov@securitycode.ru>,
	Anton Altaparmakov <anton@tuxera.com>,
	<linux-ntfs-dev@lists.sourceforge.net>,
	<linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org>,
	"Danila Chernetsov" <listdansp@mail.ru>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Christian Brauner <brauner@kernel.org>
Subject: [PATCH 5.10] ntfs: do not dereference a null ctx on error
Date: Tue, 8 Oct 2024 11:52:01 +0300	[thread overview]
Message-ID: <20241008085201.2209609-1-g.ryurikov@securitycode.ru> (raw)

From: George Ryurikov <g.ryurikov@securitycode.ru>

Danila Chernetsov <listdansp@mail.ru>

commit aa4b92c5234878d55da96d387ea4d3695ca5e4ab upstream.

In ntfs_mft_data_extend_allocation_nolock(), if an error condition occurs
prior to 'ctx' being set to a non-NULL value, avoid dereferencing the NULL
'ctx' pointer in error handling.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Danila Chernetsov <listdansp@mail.ru>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: George Ryurikov <g.ryurikov@securitycode.ru>
---
 fs/ntfs/mft.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c
index 0d62cd5bb7f8..3feb218174fa 100644
--- a/fs/ntfs/mft.c
+++ b/fs/ntfs/mft.c
@@ -1955,36 +1955,38 @@ static int ntfs_mft_data_extend_allocation_nolock(ntfs_volume *vol)
                                "attribute.%s", es);
                NVolSetErrors(vol);
        }
-       a = ctx->attr;
+
        if (ntfs_rl_truncate_nolock(vol, &mft_ni->runlist, old_last_vcn)) {
                ntfs_error(vol->sb, "Failed to truncate mft data attribute "
                                "runlist.%s", es);
                NVolSetErrors(vol);
        }
-       if (mp_rebuilt && !IS_ERR(ctx->mrec)) {
-               if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(
+       if (ctx) {
+               a = ctx->attr;
+               if (mp_rebuilt && !IS_ERR(ctx->mrec)) {
+                       if (ntfs_mapping_pairs_build(vol, (u8 *)a + le16_to_cpu(
                                a->data.non_resident.mapping_pairs_offset),
                                old_alen - le16_to_cpu(
-                               a->data.non_resident.mapping_pairs_offset),
+                                       a->data.non_resident.mapping_pairs_offset),
                                rl2, ll, -1, NULL)) {
-                       ntfs_error(vol->sb, "Failed to restore mapping pairs "
+                               ntfs_error(vol->sb, "Failed to restore mapping pairs "
                                        "array.%s", es);
-                       NVolSetErrors(vol);
-               }
-               if (ntfs_attr_record_resize(ctx->mrec, a, old_alen)) {
-                       ntfs_error(vol->sb, "Failed to restore attribute "
+                               NVolSetErrors(vol);
+                       }
+                       if (ntfs_attr_record_resize(ctx->mrec, a, old_alen)) {
+                               ntfs_error(vol->sb, "Failed to restore attribute "
                                        "record.%s", es);
+                               NVolSetErrors(vol);
+                       }
+                       flush_dcache_mft_record_page(ctx->ntfs_ino);
+                       mark_mft_record_dirty(ctx->ntfs_ino);
+               } else if (IS_ERR(ctx->mrec)) {
+                       ntfs_error(vol->sb, "Failed to restore attribute search "
+                               "context.%s", es);
                        NVolSetErrors(vol);
                }
-               flush_dcache_mft_record_page(ctx->ntfs_ino);
-               mark_mft_record_dirty(ctx->ntfs_ino);
-       } else if (IS_ERR(ctx->mrec)) {
-               ntfs_error(vol->sb, "Failed to restore attribute search "
-                               "context.%s", es);
-               NVolSetErrors(vol);
-       }
-       if (ctx)
                ntfs_attr_put_search_ctx(ctx);
+       }
        if (!IS_ERR(mrec))
                unmap_mft_record(mft_ni);
        up_write(&mft_ni->runlist.lock);
--
2.34.1

Заявление о конфиденциальности

Данное электронное письмо и любые приложения к нему являются конфиденциальными и предназначены исключительно для адресата. Если Вы не являетесь адресатом данного письма, пожалуйста, уведомите немедленно отправителя, не раскрывайте содержание другим лицам, не используйте его в каких-либо целях, не храните и не копируйте информацию любым способом.

                 reply	other threads:[~2024-10-08  8:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20241008085201.2209609-1-g.ryurikov@securitycode.ru \
    --to=g.ryurikov@securitycode.ru \
    --cc=anton@tuxera.com \
    --cc=brauner@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ntfs-dev@lists.sourceforge.net \
    --cc=listdansp@mail.ru \
    --cc=lvc-project@linuxtesting.org \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®