From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDC2B3A8727 for ; Fri, 12 Jun 2026 19:12:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781291537; cv=none; b=AV2H+oCjla+rmWtL2zVBV+jqSxFeKZSP7lVCOVg7mvjvScxspteUZJWCV8Qr/qZFmz8F2jVVeYboUTYThfNvyRmFwcbVdunCa6eArmBV0zi4KtGSqlTtjmZYyYT7twmiibpHqJU+Ql/kU+SkUxkArq3ayZ7p0czGyPw6eMK2NX8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781291537; c=relaxed/simple; bh=UeIrXYW/VOxDTD1TKQsKUhc6+O1yPrNl8u07x7at6IA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CwUUOKUHx6CixTcTnukyh5EaO88FdOaZ/Ip1zdL+KyM2glSDpwPb+hptZI52R6MBEAGPocfR03TbcrtqsPSP2MT2X1ytq1PNZ+KlSLfsHW1cci/XAuQk4CJdLMcS2BA2eqWq3aSPQv+lUfXb8uQ20Fn8z8RTkBM7NRSF3AszCew= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RVXj74Kz; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RVXj74Kz" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-842307473b5so1056941b3a.2 for ; Fri, 12 Jun 2026 12:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781291534; x=1781896334; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wgxUDA4EtUN42F2Wh6P6RN7etfV8gAwcKvN+qwmZsAw=; b=RVXj74KzO2qZGtobSQcwZuoykj85mBdAG1t6MRSNnqlxOqay0QXJ8L30J3hW7cCSLT RLKShI86qLmd2mQK6z2RY82YWynRkWf5+dS/SgVYpJ8zk9oLxWXL43SZdVC3GMBpHNsL O/jXUKSuGr9OqpXe21po/KAD6bhn7eWP+cZ8mGyl+PoZFAvnF+iW4Rm3sehR2ngHp//p QsV1/N+KhvzgJP6svO0tQN2NWs8jswXAWqJcLn+TUYFf05Vibc/bxekFY3qRUOVSCo4l ozCh3N/pa1K0nOHQ3WcOmhUHFc2/wbfoDBwHd+V1i+vOw39weXc09ITzvVwqoVexjyOE og0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781291534; x=1781896334; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wgxUDA4EtUN42F2Wh6P6RN7etfV8gAwcKvN+qwmZsAw=; b=h8DsBwEyO8XP/Rr1QoqkNIOf4jRs4e8EJFP1Nx0iWGz6e1AYRmloG4x9z0RL6Erke9 Yg2SedudRkfZfXi+WsC8/pP4iapVy+kxze3m0VxI2UI5QAfukPolEA81l0JZvty7dVrw p2OpiBnXozFNjo9Urb3QRXDkuiLqBlCTGL3XPtRanpPhP/NYmZIXkX1fLZ8ZWKUHflxs vIA4KAudhS1C6PDywGI+IGM1SHXQnye6U47FemscvEYZxOH1/oGrhlv6YbhDi0Ol/V2v 2cpxztLE3sFMNqGBZhXBNjRM8EJTxJEsjRtNrr5KKeYZAuGbDj+dL2dCvQqjMWN0U9QR Dfnw== X-Forwarded-Encrypted: i=1; AFNElJ9rdgdVSjAeYTXIan2t6zQN6YU1MJIu6j5cs6Kg+X8bw+ne4r+zUP5I7tYdC7c+Bzswbf7q2b3e+W00Ev0=@vger.kernel.org X-Gm-Message-State: AOJu0YyB8aP1WfktlQ+kSKCsNj0bvpwC7mE990ufas/RH4gs7dTpfdrB P3cIG4cYVATmJw/lsvKpVLilO2pvBmM8j08A8K0IwkbUd5ZlAfWI0FGq X-Gm-Gg: Acq92OHyE5rkPuHbqhExzY4MryPCYGw1wErT0vNaLe6kiDzxeCSFl00dk/Co3SvzyiU lHLXF5ruMfpkYTd3crtajHzLxEpO7WA6WL6EWJL0TNU7CeeD6cV83iClk1gr2LJpqEvHW8eqJ6G Eqdz3x/LpJrGLZSI+oGrk7A4dlnDGPJVy9LbpoPwswM+D4GTnBgyY3CBr7VGfT5dgsxUUq6j0GZ ew+jP6vWP3AzDXEYAm4nDRL/S2Cmke8SXWQPqIZCHno/mOURk+3ULH1dYi4E0fdBHNJ85aDCS1K DOjtc1FhIhigcd5i5GpPdbr4+T4BVsLX87OA4b2nr4zFamNK7O47zQrcEsmlfpOumeWqn4m6urE lhTzGNY83pAN+fJrmk6lNusYzxlegqmXUfxG/FBnWpyoQ9YwqeAYsUm6xe+znV4/G1lWyC1Vwa1 yBcxoLdN0Vh0yyDe/5FK6zGiAkR1GgxE5NEDNXA2xhUWjphJyR X-Received: by 2002:a05:6a00:1404:b0:836:3f6a:3e77 with SMTP id d2e1a72fcca58-8434cd4b0abmr4520090b3a.17.1781291534135; Fri, 12 Jun 2026 12:12:14 -0700 (PDT) Received: from localhost.localdomain ([61.185.160.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8434b020b53sm2952868b3a.47.2026.06.12.12.12.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 12 Jun 2026 12:12:13 -0700 (PDT) From: Jenny Guanni Qu To: shaggy@kernel.org Cc: jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Jenny Guanni Qu , syzbot+a98891ce2318fe7baf05@syzkaller.appspotmail.com Subject: [PATCH] jfs: fix use-after-free in jfs_readdir on legacy non-indexed directories Date: Sat, 13 Jun 2026 04:12:04 +0900 Message-ID: <20260612191204.95876-1-qguanni@gmail.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In the legacy (non-indexed) readdir path, jfs_readdir calls dtReadNext to advance through the directory's dtree. When dtReadNext reaches the last leaf page, it frees the metapage via DT_PUTPAGE(mp), sets bn = -1, and falls through to the out label, which stores the stale mp pointer into btstack->top->mp. Back in jfs_readdir, DT_GETSEARCH dereferences btstack.top->mp to extract the dtpage pointer. It guards this with "if (BN)", intending to distinguish root (bn=0) from non-root pages, but the -1 EOF sentinel also passes this check, causing a read from the freed metapage slab object. The existing code already had the correct EOF check ("offset beyond directory eof?") immediately after DT_GETSEARCH, but the dereference inside the macro fires first. Fix this by moving the bn < 0 check before the DT_GETSEARCH call, reading btstack.top->bn directly since the local bn variable is not yet populated. Also null out the stale mp pointer in dtReadNext when bn is -1, so the btstack does not retain a dangling pointer to freed memory. The buggy ordering predates the git history; the EOF check has followed DT_GETSEARCH since the initial JFS merge, so there is no specific commit to reference in a Fixes: tag. Reported-by: syzbot+a98891ce2318fe7baf05@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=a98891ce2318fe7baf05 Cc: stable@vger.kernel.org Signed-off-by: Jenny Guanni Qu --- Reproduced the crash on an x86_64 KASAN kernel (v7.1-rc6) using a C reproducer that mounts a JFS image, clears JFS_DIR_INDEX in the superblock to force the legacy non-indexed readdir path, and calls getdents64 past the last leaf page. The faulting access resolves via faddr2line to the DT_GETSEARCH dereference in jfs_readdir, and the free to release_metapage in dtReadNext, matching the syzbot report. syzbot's own published C reproducer produces an identical crash signature on the same kernel. With this patch applied (v7.1-rc8), the same reproducer drives the identical code path (600 entries, repeated getdents64 calls through the legacy jfs_readdir loop) and completes with no KASAN report. fs/jfs/jfs_dtree.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c index ac0f79fafaca..037121587571 100644 --- a/fs/jfs/jfs_dtree.c +++ b/fs/jfs/jfs_dtree.c @@ -2874,14 +2874,14 @@ int jfs_readdir(struct file *file, struct dir_context *ctx) ctx->pos = DIREND; return 0; } - /* get start leaf page and index */ - DT_GETSEARCH(ip, btstack.top, bn, mp, p, index); - /* offset beyond directory eof ? */ - if (bn < 0) { + if (btstack.top->bn < 0) { ctx->pos = DIREND; return 0; } + + /* get start leaf page and index */ + DT_GETSEARCH(ip, btstack.top, bn, mp, p, index); } dirent_buf = __get_free_page(GFP_KERNEL); @@ -3293,7 +3293,7 @@ static int dtReadNext(struct inode *ip, loff_t * offset, btsp = btstack->top; btsp->bn = bn; btsp->index = dtoffset->index; - btsp->mp = mp; + btsp->mp = (bn == -1) ? NULL : mp; return 0; } -- 2.50.1 (Apple Git-155)