From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379538; b=h9IBs+CFC8es7kNMHiOAGXYdjzt/UAwWwanbZVvI8Y46W72sfM1HgkxbXQJ3uAUWyvol xxvr08Q5RIKAhHblbVPF3TpdYYpvo1AsZjj2zz77fKkf9O41BlyKaLkD+9zh3UBsDM56F O2i0eUxTqT6Y0Ut0YW7c4hfVdMCW0cA5Mbe5P7gT1UtZaVkiDa/XPpg3jeS5Nwp4XRG6b Js/Am9vWCK4SKwSHqkEDMGmO0/1YUFLoQdLLvsinBFbKLMo6LJ1yh+PEIYrv9Qa/dSb5c b79Mf6JbcE+v+tXYl+s+m+spTdDqOEKEvwjZLaX+ITbj2NjFD+/P8FgfqyvMnwC1uVw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379538; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=DwJkAx3RVyFvif2E21wLWzAWBN7DZEDit9sWEhU490Y=; b=fm3EVGOUHqI40lS7AidbiL0vpiPbwTdH1euQHe9m1MaaMF10LM5mo635Qe/CX3ZAJsyy 37BAId5y2ZAktQ0dV1+7RZJv/kQj32hBsv6kRDmg7fNAWqikrVvXkl8yngF6oPPgjjRtK QlsVFM6qxIHe6z40Q3sFNYAJzovffrUztq9fJ3+r2uUWiJiJy6toq38wR/DJ9+KenPAPD HYiFOv1F6tA94MOaea4LPr4eJbtADyc04/+R71gs8vhNlL8HUfDbDom1c4inyh5Dnd2pU e4VCc1s/ITXXsDoNQSkWvmh1/4Ibh9fVlb8k1HniAQkLuPiFMkx3yui/efNzVxMrJXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=qa56Phd2; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86893606A322; Fri, 4 Dec 2026 10:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=qa56Phd2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F18501F000CE; Fri, 4 Dec 2026 10:18:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379538; bh=DwJkAx3RVyFvif2E21wLWzAWBN7DZEDit9sWEhU490Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qa56Phd2vcjr6qXXUwqofbQvmqTauh/bFbwJHdgnERayQTWYMyYJ67rAQnhgm/OUg KAMJbVywGFS7OZxuWQepNsCWdOQUPzQbJ+fCOcy4dvDPk3zIhiN4zMF6ybQ0qq19Jl HdnVJUdmi8nZ2mw16krET7beiuY+W7/Hi+xCLKVU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zizhi Wo , Jan Kara , Christian Brauner , Sasha Levin Subject: [PATCH 6.6 0011/1167] fs: aio: reject partial mremap to avoid Null-pointer-dereference error Date: Fri, 4 Dec 2026 18:50:38 +0900 Message-ID: <20261204100702.341131534@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zizhi Wo [ Upstream commit 3adf7ae18bf42601246031002287c103a27df307 ] [BUG] Recently, our internal syzkaller testing uncovered a null pointer dereference issue: BUG: kernel NULL pointer dereference, address: 0000000000000000 ... [ 51.111664] filemap_read_folio+0x25/0xe0 [ 51.112410] filemap_fault+0xad7/0x1250 [ 51.113112] __do_fault+0x4b/0x460 [ 51.113699] do_pte_missing+0x5bc/0x1db0 [ 51.114250] ? __pte_offset_map+0x23/0x170 [ 51.114822] __handle_mm_fault+0x9f8/0x1680 ... Crash analysis showed the file involved was an AIO ring file. The phenomenon triggered is the same as the issue described in [1]. [CAUSE] Consider the following scenario: userspace sets up an AIO context via io_setup(), which creates a VMA covering the entire ring buffer. Then userspace calls mremap() with the AIO ring address as the source, a smaller old_len (less than the full ring size), MREMAP_MAYMOVE set, and without MREMAP_DONTUNMAP. The kernel will relocate the requested portion to a new destination address. During this move, __split_vma() splits the original AIO ring VMA. The requested portion is unmapped from the source and re-established at the destination, while the remainder stays at the original source address as an orphan VMA. The aio_ring_mremap() callback fires on the new destination VMA, updating ctx->mmap_base to the destination address. But the callback is unaware that only a partial region was moved and that an orphan VMA still exists at the source: source(AIO): +-------------------+---------------------+ | moved to dest | orphan VMA (AIO) | +-------------------+---------------------+ A A+partial_len A+ctx->mmap_size dest: +-------------------+ | moved VMA (AIO) | +-------------------+ B B+partial_len Later, io_destroy() calls vm_munmap(ctx->mmap_base, ctx->mmap_size), which unmaps the destination. This not only fails to unmap the orphan VMA at the source, but also overshoots the destination VMA and may unmap unrelated mappings adjacent to it! After put_aio_ring_file() calls truncate_setsize() to remove all pages from the pagecache, any subsequent access to the orphan VMA triggers filemap_fault(), which calls a_ops->read_folio(). Since aio does not implement read_folio, this results in a NULL pointer dereference. [FIX] Note that expanding mremap (new_len > old_len) is already rejected because AIO ring VMAs are created with VM_DONTEXPAND. The only problematic case is a partial move where "old_len == new_len" but both are smaller than the full ring size. Fix this by checking in aio_ring_mremap() that the new VMA covers the entire ring. This ensures the AIO ring is always moved as a whole, preventing orphan VMAs and the subsequent crash. [1]: https://lore.kernel.org/all/20260413010814.548568-1-wozizhi@huawei.com/ Signed-off-by: Zizhi Wo Link: https://patch.msgid.link/20260418060634.3713620-1-wozizhi@huaweicloud.com Reviewed-by: Jan Kara Signed-off-by: Christian Brauner Signed-off-by: Sasha Levin --- fs/aio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/aio.c b/fs/aio.c index 8a4d95a825678..a7309c2250138 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -369,7 +369,8 @@ static int aio_ring_mremap(struct vm_area_struct *vma) ctx = rcu_dereference(table->table[i]); if (ctx && ctx->aio_ring_file == file) { - if (!atomic_read(&ctx->dead)) { + if (!atomic_read(&ctx->dead) && + (ctx->mmap_size == (vma->vm_end - vma->vm_start))) { ctx->user_id = ctx->mmap_base = vma->vm_start; res = 0; } -- 2.53.0