mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Shawn Shao <shawnq1@163.com>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
	Yangtao Li <frank.li@vivo.com>,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hfs: reject empty nodes in forward record traversal
Date: Mon, 30 Nov 2026 11:47:45 -0800	[thread overview]
Message-ID: <fcb208044e60bbeb29eb8a6f7eeb137fd83227b0.camel@dubeyko.com> (raw)
In-Reply-To: <20261130065609.2165939-1-shawnq1@163.com>

On Mon, 2026-11-30 at 06:56 +0000, Shawn Shao wrote:
> Hello,
> 
> A malformed classic HFS catalog can contain an empty leaf whose
> `next`
> link points to itself.  When `getdents64()` advances from the root
> folder-thread record to that leaf, `hfs_brec_goto()` subtracts zero
> records and repeats the transition indefinitely.  The task stays in
> kernel context with the catalog B-tree lock held and does not exit
> after
> `SIGKILL`.
> 
> The image mounts read-only.  The issue requires a privileged mount of
> an
> attacker-supplied HFS image and causes a local availability denial of
> service.  It does not demonstrate memory corruption, information
> disclosure, or privilege escalation.
> 
> On the patched kernel, the first `getdents64()` returns the 48 bytes
> for
> `.` and `..`; the next call returns `-EIO` promptly.  The close
> control,
> which changes only the empty leaf's `next` field from 2 to 0, returns
> the
> dot entries and exits normally.

Frankly speaking, I cannot connect the commit message explanation and
the fix itself. It sounds confusing.

> 
> A related public report discusses malformed records in the separate
> HFS+ driver and its unlink/writeback path.  This reproducer is in the
> classic HFS driver and the `readdir` path:
> https://lkml.iu.edu/2606.3/02410.html
> 
> Tested source revision:
> HEAD commit:    7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046
> source version: Linux 7.4.0-rc4
> compiler:       gcc 11.4.0, GNU ld 2.38
> QEMU:           6.2.0, x86-64 TCG
> 
> Vulnerable console output:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/a1b616ee6d82742ae58cfe2ec23405550f49e257/vulnerable-cycle-console.txt
> Control console output:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/066ea9864657394d6d6e728c68ccd3315ffc088a/vulnerable-control-console.txt
> Patched console output:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/948aa7bd9c9a9a4b3964bfd1fab61544b6a3f401/fixed-two-call-console.txt
> Kernel config:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/664d72f164fe325e8cc97119c3d592692e9c3357/kernel-config.txt
> Reproducer:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/cca14b4b603fe8b0f12e72d2819f4bc02ff7be80/poc.c
> Image builder:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/b858d02dc8c97a5b324771bd134f1c0b2603b3c2/make_image.py
> Init script:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/b7dd3708e4a4b753e9de8941b4b2d1ce38afd934/init
> Initramfs builder:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/fb2c2fb32fac59b77f7bb3ee9c23fe0d02ebb097/build_initramfs.sh
> QEMU runner:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/44e5decf5788b8e73da0fe4d01cf70f41f6289b2/run_qemu.sh
> Fixed-kernel check:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/18041ca2ebe658179b5de4e97e6e0d62c4ed75d6/fixed-check.c
> Patch file:
> https://gist.githubusercontent.com/shaos26/06dc92e4840aef9766cd82b8c644fe16/raw/80c76dd1dea20d6ed3f8c67d2e64ec042e880535/fix.patch
> 
> The Gist also contains the fixed-kernel positive and control logs. 
> To
> reproduce, run:
> 
>     work=$(mktemp -d /tmp/hfs-leaf.XXXXXX)
>     cd "$work"
>     gist_id=06dc92e4840aef9766cd82b8c644fe16
>     gist_revision=e7630526685aa318b25a981ea5044014607f1521
>     gist_base=https://gist.githubusercontent.com/shaos26
>     gist=$gist_base/$gist_id/raw/$gist_revision
>     for file in kernel-config.txt poc.c fixed-check.c make_image.py \
>         init build_initramfs.sh run_qemu.sh fix.patch; do
>         curl -fL "$gist/$file" -o "$file"
>     done
>     git clone \
>        
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
>     cd linux
>     git checkout 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046
>     mkdir build
>     cp ../kernel-config.txt build/.config
>     make O=build olddefconfig
>     make O=build -j"$(nproc)" bzImage
>     cd ..
>     python3 make_image.py cycle.img cycle
>     python3 make_image.py control.img control
>     sh ./build_initramfs.sh "$PWD/rootfs" "$PWD/initramfs.cpio.gz"
>     sh ./run_qemu.sh linux/build/arch/x86/boot/bzImage \
>         initramfs.cpio.gz cycle.img cycle.log
>     sh ./run_qemu.sh linux/build/arch/x86/boot/bzImage \
>         initramfs.cpio.gz control.img control.log
> 
> To test the fix, run `git apply --check ../fix.patch` and `git apply
> ../fix.patch` from the Linux source directory, rebuild, then rerun
> the
> cycle image.  For the second-call check, build the initramfs with
> `POC_SRC="$PWD/fixed-check.c"`.
> 
> Reject an invalid record cursor before following the next leaf link:
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Shawn Shao <shawnq1@163.com>
> ---
>  fs/hfs/bfind.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/fs/hfs/bfind.c b/fs/hfs/bfind.c
> index d56e47bdc517d..c0af468651674 100644
> --- a/fs/hfs/bfind.c
> +++ b/fs/hfs/bfind.c
> @@ -211,6 +211,11 @@ int hfs_brec_goto(struct hfs_find_data *fd, int
> cnt)
>  		fd->record -= cnt;
>  	} else {
>  		while (cnt >= bnode->num_recs - fd->record) {

We try to execute bnode->num_recs - fd->record already here. If the fd-
>record, bnode->num_recs, or cnt are incorrect, then we should not to
execute this check because we should have not correct condition check.
And we could have any of these values incorrect. It looks to me that we
need more precise refactoring of hfs_brec_goto().

> +			if (unlikely(fd->record >= bnode->num_recs))
> {
> +				res = -EIO;
> +				goto out;
> +			}

This check inside of the loop looks like not correct solution.

Thanks,
Slava.

> +
>  			cnt -= bnode->num_recs - fd->record;
>  			fd->record = 0;
>  			idx = bnode->next;

      reply	other threads:[~2026-11-30 19:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  6:56 Shawn Shao
2026-11-30 19:47 ` Viacheslav Dubeyko [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=fcb208044e60bbeb29eb8a6f7eeb137fd83227b0.camel@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shawnq1@163.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

all inboxes | Powered by JetHome®