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=1796379581; b=2ikmeiXBOpASqBjvifXwwhzOGJ3fsDNLYYKidvbnC7Ue2oMPnjuSn87HZzDry5E5Jm/p g6ExTDen0TrUyBPgCGwQk23ydqS0kFFKhGgAma0eNhcQLO+83S9CPBIOmrCKEE6WQAMKJ g6b0jV77v9QESrWI3IgmWT3XbOgwfuO4irvo2ns5LHBSwKBIa2C+lJrkLJNh9NtMLeixH JBDh3OIGK9wpUr8vWab2/nEXFydAfR2e+OeSM/9gNZxjEb3GUgQvr0LxuSrlrAICU0/S3 +oZpVYITDtk03G4rOeAzhTh9hYcajGiG5QRj8UeHF+j1bARQE0HoZ57CAlp4YDDiz0A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379581; 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=41SeGiEn4Y7DWeUF1fYTq7Q7ixf+Zm8H6+emW+8slos=; b=AdAXzku1eiBcvz41XAW1ntjDNyDbqF3MDUysMKRfExS3FRDgjYvOGXGPAn3PvWo80qE3 56O4GvZvjvR+FUGgnwemJnUF39F1mpTGDdEmkCMa0/uWE61kb9iZDM2ERuA9zqLMRRe2r IvZMyi7s6w3+9a1HWXyjI5MuITIoSOYCa6/IAuTc7rl7uMSyG2dPkj9M1qxzSI9mDRdfI B3QofMVFUtNtgXi0gxoF9uF3hRj8eIqek0GH+ZC6upBt7DvgzJlA4T2KyLbE7nl9NcsZv 1g0hdoeZlYPV/77hZfIKbxhf+kMUZtEZiWA7IiYXvlhRPeUmr7LmCymdr9tGOh9BTdA== 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="LoGF/YaF"; 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 BEC71606A322; Fri, 4 Dec 2026 10:19:41 +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=LoGF/YaF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3404B1F000C2; Fri, 4 Dec 2026 10:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379581; bh=41SeGiEn4Y7DWeUF1fYTq7Q7ixf+Zm8H6+emW+8slos=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LoGF/YaFDn2MlMCQhzJb9NXOUX8aCGcBlnkBnyMtZ1fI7ZkBePLjM9SooqVDY4pV2 0jgsF4pJnoVPy/cW+7yXmZqeDwV1KKeVSikjWOWH2Ie1JzO+8jUaOYL5I7Stf5ca+X 0LlOV7//rbPwPrcRjyio1sUkgpU1HYr77yOs6M9Q= 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.1 0009/1059] fs: aio: reject partial mremap to avoid Null-pointer-dereference error Date: Fri, 4 Dec 2026 18:52:20 +0900 Message-ID: <20261204100644.252326266@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 3c3770d8e2637..535757e11f67f 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