From: Hongling Zeng <zhongling0719@126.com>
To: Namjae Jeon <linkinjeon@kernel.org>,
Hongling Zeng <zenghongling@kylinos.cn>
Cc: hyc.lee@gmail.com, charsyam@gmail.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] ntfs: validate error codes in check_windows_hibernation_status()
Date: Fri, 03 Jul 2026 16:25:00 +0800 [thread overview]
Message-ID: <6A4771DC.3030301@126.com> (raw)
In-Reply-To: <CAKYAXd-2nR9-=O5DYiw6x9R4KpuiV9eqH+HwiYxdAmihw4PvYw@mail.gmail.com>
Looking at ntfs_lookup_inode_by_name() more carefully:
All error return paths inside the function use hardcoded kernel errnos
(MREF_ERR(-ENOENT), MREF_ERR(-EIO), MREF_ERR(-ENOMEM)) - these are
already valid by construction.
The actual risk occurs when the function returns a "successful" MFT
reference from disk (ie->data.dir.indexed_file) that happens to have
bit 47 set - making IS_ERR_MREF() true at the caller. In this case,
MREF_ERR() extracts garbage from untrusted disk data.
This cannot be fixed inside ntfs_lookup_inode_by_name() without
changing its return value semantics, because from the function's
perspective it found a matching index entry and returned it. Only
the caller, after IS_ERR_MREF() triggers, is in a position to
validate that the extracted error code is a legitimate errno.
Restructuring the function to distinguish "real errors I generated"
from "disk data that looks like an error" would require a more
invasive API change (e.g., returning int + out-parameter), which
seems inappropriate for a legacy filesystem in maintenance mode.
在 2026年07月03日 15:06, Namjae Jeon 写道:
> On Thu, Jul 2, 2026 at 12:37 PM Hongling Zeng <zenghongling@kylinos.cn> wrote:
>> check_windows_hibernation_status() calls ntfs_lookup_inode_by_name()
>> which returns MFT references read directly from disk (untrusted data).
>> The current code extracts error codes via MREF_ERR() without proper
>> validation, allowing maliciously crafted NTFS images to trigger
>> incorrect error handling.
>>
>> The MFT reference encoding uses bit 47 as an error indicator, but the
>> lower 32 bits can contain arbitrary values. If a malicious image sets
>> the error bit with a positive integer (e.g., 1), MREF_ERR() returns
>> that positive value. This can cause the function to incorrectly
>> interpret the error as "Windows is hibernated" status, potentially
>> leading to the filesystem being mounted read-only (denial of service).
>>
>> Fix by strictly validating error codes: only accept negative values
>> in the valid errno range [-MAX_ERRNO, -1]. Convert all other values
>> (positive, zero, or out-of-range) to -EIO to indicate disk corruption.
>>
>> This prevents potential security issues and ensures proper error handling
>> for corrupted or malicious NTFS filesystems.
>>
>> Fixes: 1e9ea7e04472d ("Revert \"fs: Remove NTFS classic\"")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
> I think this should be fixed in ntfs_lookup_inode_by_name(), rather
> than in the caller.
> And I will revert your previous patch ("ntfs: validate error codes
> from untrusted disk data").
>
> Thanks.
next prev parent reply other threads:[~2026-07-03 8:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 3:36 [PATCH] ntfs: validate error codes in check_windows_hibernation_status() Hongling Zeng
2026-07-03 7:06 ` Namjae Jeon
2026-07-03 8:25 ` Hongling Zeng [this message]
2026-07-03 10:40 ` Namjae Jeon
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=6A4771DC.3030301@126.com \
--to=zhongling0719@126.com \
--cc=charsyam@gmail.com \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=zenghongling@kylinos.cn \
/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.