From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 1B0883905E6 for ; Tue, 11 Aug 2026 02:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786416244; cv=none; b=jrF6FWdjmDQGoLPuttwMY3/tITEMAajo8JMxN3X/L8/kDC9Pdlf5MluzjkLsDcpBcY1mpXPbTVReHL6Xfmh4bAgeOos+oTAotmK7owCA9kTIZ87C3iXj8dyJJaHM4fRrhHyIxPQ0wf9BUgdq4HpEkIhhAKM3ac9pWxf0mkOoTlE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786416244; c=relaxed/simple; bh=Zuczg2SkP/5ojRcZFRKQ4ku4YS+3+DzDOBTJc2/A9Po=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PWAen3KFSLEBKdvtJphm4kvGBBTEUIQP6J9SZZ57XefQLnhsR40obix89a8jCauYcup+Jhw38z8hpkIrTT/V0wLRTBHjaL5jj/eR4u6jCjv4UZYjaNRobG3UJftc7PB6qNdtB8Y83U86EvmQI7Qvwgz6N54piLuGqsG+c4StCe0= 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=KDyrxshG; arc=none smtp.client-ip=209.85.214.174 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="KDyrxshG" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2cee9b74ee1so21290015ad.3 for ; Mon, 10 Aug 2026 19:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786416236; x=1787021036; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=uFGDd6MJX6QKx/u+FjV9oJmCytT4Rq2gvVt/3A3Rh9w=; b=KDyrxshGxJ5yTBq2WU5/vuTfMhumTBwAg9X8RbdU5GFqQniYF0328JnnbejVDoJz5O HHl81HuHbhtfyq+cPGCJkDj0a1ay0TErtiARWyxJMO+88+xH6yoDJZY4Z0P5JRhjDUbE lIucyBhY/yyICVOa5oAqST8Vw7IWAjapXMOxeJZkl5XPZ6cvhhFnDDgTd6a/eUti+Avr zt4PNoZj2dmSge5qKJtF7dl5HOstGABef7jvKlG7c8081Kme2wu+4bT/X8OfY0KeOTH5 gQw9uhIcYXJaFf7OZmRQWHqFe209vml5BZ9HFxnD//DVYHayk+S3/mYe4/DkWCrZlGCI nvLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786416236; x=1787021036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=uFGDd6MJX6QKx/u+FjV9oJmCytT4Rq2gvVt/3A3Rh9w=; b=W5xiGsXQOYpnbh9tDQbJZlwcC4+klMy/nkLXAwEKg6i684JG4Yh8nx0XbcpuSuygRE ppJmJtoBbIABuZdzd6+bf5i+5iHgnNVSrCziJLYJfzxktCwtGvXpBk3cIY82hremdEYj Ks4MqKDnosA04sR4vZFxgk9QtP7vJChz9EPy6SHzBNymN/CS5XA7hHIC5iahh0lkRyCB 67SsSXZZvJDhU2p1Z1Xvcu/iPXXZQMT9XtMVTOPUdGMR7DGbkzXRwZ99vgx3sdqnLNue k3Ipw81mqlxfdKYUwL+y0HPWhrXpc+x+5An9ssRakx7yaabzdbhmlkeBnlpKb5a9QMjD 7A8A== X-Forwarded-Encrypted: i=1; AHgh+RrV4Xz7HitVtDHEfSodnhrsyMbGMiZh/NCL26G9CojaOISjS8LwGFtTj7YTOoS7LDaDPMoW40+fS333RTE=@vger.kernel.org X-Gm-Message-State: AOJu0YxR0vVuOYcDbuvhfNmEZV2cxwZEBrUjOqlsR6iJQ0PZmMWcJDSa R5isGBPZ0yLGALUDH14ORoGQmKyM5tbEbvgYL3JqrCANk2YVEcWGy9lp X-Gm-Gg: AR+sD10TzJQtE1wT7kBLFllp3I4v/3FwysBQgN20wP9autkfXiOcJyDTYsNOp37us9L rJ9v+NNEGrzIC+VUtfWAdKjx1nmaOlUcWLTvj6JjjiAZ1aK1uz20p1ejbRAV7Q1NO70M0jBMFTq uOUmjP6t01sR1hRSjDo/pgJlDXo/S8lWmgMC/9eVENt1rKrGaufbyxDDnrRdGTcWY6Vd7ntDJ8e pv3iNtj2Lli/pdo8qysr41rEWdt3ylefyFJ7my9lp+ildIA7HF3S0q7/aqRtPopb5/RniAFl+kL ByKf+3bAY2mriRMJYA//y7h3ZMfZJeoIA0mfyHiJ0VhqUwS9i2Gui+suhYpOzOIgc8LBjYqpfdS mb3RbFE+1+5gHgc1yX2XUW55MBWBxNDF8kPoBzNj1K5MFNbDjAJqT8PDU2efAih7e7w12QRbHZ/ NjDi+kdUrEWFfSa39sWB6Mav43CNusWnhjwZAiC5+8JKh0SKdPUURTYIVqwAVSbLfwru6i1sLBl Sdz7rToIYU= X-Received: by 2002:a17:902:d54f:b0:2ca:6c8:abd8 with SMTP id d9443c01a7336-2d3178b48fbmr2660065ad.12.1786416236033; Mon, 10 Aug 2026 19:43:56 -0700 (PDT) Received: from osman.mioffice.cn ([43.224.245.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d3160f47easm464165ad.64.2026.08.10.19.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 19:43:55 -0700 (PDT) From: Zhan Xusheng X-Google-Original-From: Zhan Xusheng To: Andrew Morton , Joseph Qi Cc: Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Jun Piao , Heming Zhao , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com Subject: [PATCH v2 2/2] ocfs2: bound-check dir entries in the inline-data re-validation scan Date: Tue, 11 Aug 2026 10:43:37 +0800 Message-ID: <20260811024337.3972976-3-zhanxusheng@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260811024337.3972976-1-zhanxusheng@xiaomi.com> References: <20260811024337.3972976-1-zhanxusheng@xiaomi.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ocfs2_dir_foreach_blk_id() re-scans the inline data area the same way ocfs2_dir_foreach_blk_el() re-scans a directory block, and is missing the same two bounds: for (i = 0; i < i_size_read(inode) && i < offset; ) { de = (struct ocfs2_dir_entry *)(data->id_data + i); if (le16_to_cpu(de->rec_len) < OCFS2_DIR_REC_LEN(1)) break; i += le16_to_cpu(de->rec_len); } ocfs2_validate_inode_block() keeps i_size inside the inline area: if (le16_to_cpu(data->id_count) > ocfs2_max_inline_data_with_xattr(sb, di)) if (le64_to_cpu(di->i_size) > le16_to_cpu(data->id_count)) and that area runs to the end of the inode block, so for a full inline directory data->id_data + i_size is the end of di_bh->b_data. A bogus rec_len leaves i in the last OCFS2_DIR_REC_LEN(1) - 1 bytes of it, and de->rec_len, at byte offset 8 within the entry, is then read past the block. The emit loop below hands i_size_read(inode) to ocfs2_check_dir_entry(), which refuses both an entry that close to the end and one whose rec_len runs past it. Apply the same two bounds to the re-validation scan, reading i_size once into a local as ocfs2_check_dir_entry() takes it as @size. Unlike the extent case there is no mask to corrupt here: an unbounded i only sets ctx->pos past i_size, which ends the readdir early rather than moving it to the wrong place. Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Jun Piao Cc: Heming Zhao Signed-off-by: Zhan Xusheng --- fs/ocfs2/dir.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index 39ce60874e17..863c69dec7da 100644 --- a/fs/ocfs2/dir.c +++ b/fs/ocfs2/dir.c @@ -1812,7 +1812,12 @@ static int ocfs2_dir_foreach_blk_id(struct inode *inode, * dirent right now. Scan from the start of the block * to make sure. */ if (!inode_eq_iversion(inode, *f_version)) { - for (i = 0; i < i_size_read(inode) && i < offset; ) { + loff_t size = i_size_read(inode); + + for (i = 0; i + OCFS2_DIR_REC_LEN(1) <= size && + i < offset;) { + unsigned int rec_len; + de = (struct ocfs2_dir_entry *) (data->id_data + i); /* It's too expensive to do a full @@ -1821,10 +1826,11 @@ static int ocfs2_dir_foreach_blk_id(struct inode *inode, * least that it is non-zero. A * failure will be detected in the * dirent test below. */ - if (le16_to_cpu(de->rec_len) < - OCFS2_DIR_REC_LEN(1)) + rec_len = le16_to_cpu(de->rec_len); + if (rec_len < OCFS2_DIR_REC_LEN(1) || + i + rec_len > size) break; - i += le16_to_cpu(de->rec_len); + i += rec_len; } ctx->pos = offset = i; *f_version = inode_query_iversion(inode); -- 2.43.0