Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) (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 987DA3346BC for ; Mon, 19 Jan 2026 18:01:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845725; cv=none; b=P8FaNNmJWE11vdOpzHUZFbcCaroecybAi6hLdSKAoD6aHBb/gLF1QjWI2sppRtFU6u9BzAehxCR0fbaBKS8U12Z1X25niYCNmM+r0L5zmPuIsYK609EnhcDrN+WguDAtFkfpbaksA7MPng5NYA/uQkAiOkP6VCAm3gmIlUq9qcw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845725; c=relaxed/simple; bh=Mbd6B76acQYFcT25UuF4U150G/AIM3mo8YkVwgKDm0Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t6hOSFDY1G7Mq5AAuw4FJ5jpuO7zdfj0VsXSAlxtlzR6hxo4HjFqwmgY2jNlgLqjsvRraUbl8O7oeF9zthX4qnMuHiJ5o1TyZfM9NLLcent69wB4uhZ/pXR2Df22EGaOSqEXxopkN4+kdYvbRUnqQrwkcFuvu6qzhtMJuUu8Too= 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=aHKsYaPF; arc=none smtp.client-ip=209.85.167.171 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="aHKsYaPF" Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-45c9c505fe8so1261296b6e.0 for ; Mon, 19 Jan 2026 10:01:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768845709; x=1769450509; 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; bh=m06w4WXj+V7Ts8qLgM3nR20C9EMLJygWYWZnc/rqyZU=; b=aHKsYaPFWkjh4CTFtgEuNfTOkaRky04i+smpU4j2FjnngsYJDJLRwPHAjj9XudQUCs LjdhazTsU+elmRfJe9M+wJUbAzZjoMyrqASqpqFdY4p6QGlI8BPfTFF/hfSkcCbIblql NOZv9EVyKpcRna/74kFuX26P2Ykhw2Z340IvVhohyYZgF6m0hiiIiTuz0laIo07Rp0Bi SY4JvzhVfRNGg5F9rzSMSd5yf9HlhWM8lzl9oEgySurNBioTQWoGAmKJlbcwlGs8phWw VwI/fiko+wcggKqKNc6IoWGbyXKtSHwV4zxv6XiE8FXLxBpyXbbrqTYJJERJc7cP0E1u fBaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768845709; x=1769450509; 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; bh=m06w4WXj+V7Ts8qLgM3nR20C9EMLJygWYWZnc/rqyZU=; b=U88vqOw6QtwYtIhnVXT7tR21oDupTSygDMFI9qRQL9PrL/qzO7WySOGYX2eWc/zb5n 7DhlnfE6OIMJ99uWTJ53MkIh5Oef6MQ/He1xmlYAGrYktwo53vc+20RlK7COcLPjj03L xVOURQkJ6DV1i+64YM0zXkXLhFzhJ/QyPI7ETCFvfBx5EooctlnsvtuHaQCpyEubjoKT oKjYLPaZWmmsrwkFgEFE6et8PIKbvOnClf4XLgfqMJzo0N8LWWltwUhVjVtYcQlf+jNW gXBtt+zUV8qV1jJHaeHRWgDUwtzjwaX5++jhs7huK0eyuZoduy1mLl/khD6EeY62Tuxv 6lCQ== X-Forwarded-Encrypted: i=1; AJvYcCWPdkqrkTNqHbFPlcfL3nFDW1h/aDZ+Ysov49wUGGYSuWugPMzBLLOt8hGUqV5iDSRElJO9RQkFPpEYhRw=@vger.kernel.org X-Gm-Message-State: AOJu0YyMY/lt0I8aYbs1nZSQW09SHAHGaBqJjL2Qhtz/7/Qv2VXUc0BA GTUCvr41r0JhU9pAAB/NwjbKay4ruQelhFg4zHpkgXnY8YUbgbkAuQAa X-Gm-Gg: AY/fxX6BAPly0l3JtlDcDqN9LjMfTJpsnDTdFc4fkeb6VYCTAaf48xCi2shSNy9ob9Q 42xhsRt4JJp8wFOJpqMGOWvc7vQLgFayhM5p/Re77kdiFpx8b6tLl2LqaomYvibjc+UanG/XYKs hmtS78liwV6TD8bRkJKBsWrqx7Rekfnu9B+z9j+D9c2v0stPjmxC5rJiVRhxYC5OgP0qmJE2xMk kcEvjJMs8QpIdxwzeHbU7HN6o6BlsJTK+8dus3JyesLC2rjd+KcQLlm2+6/iv4TaqQJgpoGoa0/ h6RwQTPu01CAXUS8j23PZ4wUqLZcfliLAsT1NIVSIYb9TTgl85g+9cMYZglSevpzNgI5qTW0f1L pPfMhjzvlJYJCXNDvwNlMs0K1iXLzx9BbSN8OVtzWmmA9rWJclxsVW9UjFe1OLgdCAlA6XjWDJx aIRcolxbC0lA7t4V7j36YP82fkMzGXZbYC X-Received: by 2002:a05:6808:1a1a:b0:450:b7a0:41ca with SMTP id 5614622812f47-45c9d73516bmr5400321b6e.22.1768845709285; Mon, 19 Jan 2026 10:01:49 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 5614622812f47-45c9e03e82esm5780228b6e.15.2026.01.19.10.01.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 10:01:48 -0800 (PST) From: Jiasheng Jiang To: heming.zhao@suse.com Cc: jiashengjiangcool@gmail.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, linux-kernel@vger.kernel.org, mark@fasheh.com, ocfs2-devel@lists.linux.dev Subject: Re: [PATCH] ocfs2: fix slab-out-of-bounds in ocfs2_rotate_requires_path_adjustment Date: Mon, 19 Jan 2026 18:01:47 +0000 Message-Id: <20260119180147.1708-1-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Mon, 19 Jan 2026 22:50:00 +0800, Heming Zhao wrote: > On Fri, Jan 16, 2026 at 05:21:13PM +0000, Jiasheng Jiang wrote: >> In ocfs2_rotate_requires_path_adjustment(), the variable 'next_free' is >> assigned the value of 'left_el->l_next_free_rec'. This value is then used >> to index the 'l_recs' array as 'next_free - 1'. >> >> If the filesystem is corrupted or in an unexpected state such that >> 'l_next_free_rec' is 0, this leads to an array index of -1, triggering >> a slab-out-of-bounds access. >> >> Other functions in alloc.c, such as ocfs2_rotate_leaf() and >> ocfs2_update_edge_lengths(), effectively guard against this condition. >> This patch adds a similar check to return 0 immediately if 'next_free' >> is 0, preventing the out-of-bounds access. > > Do you have reproduction steps to support your analysis? > > - Heming Regarding the reproduction steps, we detected this issue through static analysis. We do not have a specific script to reproduce this as it requires a corrupted filesystem image. However, if the filesystem metadata is corrupted (e.g., due to bit rot or software bugs), it is possible that l_next_free_rec reads as 0. In the current implementation, this leads to accessing l_recs with index -1, causing a slab-out-of-bounds access. This patch is intended as a hardening measure. Instead of crashing the kernel when encountering such invalid on-disk data, it is safer to abort the operation gracefully. This change also improves consistency within fs/ocfs2/alloc.c. Other functions such as ocfs2_rotate_leaf() and ocfs2_update_edge_lengths() already guard against this specific condition (next_free == 0) to avoid invalid access. This also aligns with recent fixes like Commit 44acc46d182f ("ocfs2: avoid NULL pointer dereference in dx_dir_lookup_rec()"), which addressed issues caused by empty extent lists. I will update the commit message in the next version to explicitly state that this is a hardening measure against on-disk corruption. - Jiasheng >> >> Signed-off-by: Jiasheng Jiang >> --- >> fs/ocfs2/alloc.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c >> index 58bf58b68955..b15c6f751d99 100644 >> --- a/fs/ocfs2/alloc.c >> +++ b/fs/ocfs2/alloc.c >> @@ -2327,6 +2327,10 @@ static int ocfs2_rotate_requires_path_adjustment(struct ocfs2_path *left_path, >> >> left_el = path_leaf_el(left_path); >> next_free = le16_to_cpu(left_el->l_next_free_rec); >> + >> + if (unlikely(next_free == 0)) >> + return 0; >> + >> rec = &left_el->l_recs[next_free - 1]; >> >> if (insert_cpos > le32_to_cpu(rec->e_cpos)) >> -- >> 2.25.1 >>