From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 3853227816C for ; Mon, 1 Dec 2025 06:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764570278; cv=none; b=XWyy1lvqqqEegkXIMHv7lkVDBKfGJcTsGMHH/T9ROdFMbKfq8nC103rsbQl4EzWW9DHpxa4oSHvk4MAu2LjWKLyJQUTyRkBN/GXTYBAC9xPGKBJ/jIptCz7KqyvlabWmb0GeHhN1K+IPI5hILPMzdfNhQkaNA7xY09+cM7iSl+4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764570278; c=relaxed/simple; bh=2io+coGsPXy7Rc27r/JqPO/Zr9vIFhBw2CPH38P9x0k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ejX8nLiiBeVAGku7co7qmdbcL5MhaG+zi5C7X7oKxCjYAVV3mEk2H255ha1M2j1SVRcjcRytlg05KBa9jouAG/PEmHcd1ApiHuJzS6CeiPd4Ktk9uxzGOIf0oWUDvF6m06aRI5aQh8i+7liv+dQMXMI5YoxRgtZIRofyKrl5xrI= 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=LGSwfLj7; arc=none smtp.client-ip=209.85.216.54 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="LGSwfLj7" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-343774bd9b4so2998123a91.2 for ; Sun, 30 Nov 2025 22:24:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764570276; x=1765175076; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=peAT0TtJ+zmGu6HEzqEiByNE29w1TbiVx2+7wH8lyF8=; b=LGSwfLj7tQEOIEvv+UQ3ymefZQhsUDT3QyhV8IGolW/roWt/HfGAUEA+A5iYr2SVbx b0ouseZ4UXBb+euJfR2nmWT3fWP3OzcN9zRjbEqsCGf4B39Ug04+DkfmZ1pnI1YuViNM s3WVmREseXLMXxBAQTkvFU8jf6WzSR+Uyl6Z4lY275MYI8FUtCVKrV3OqURGgTGCMhwJ heYwHz1Y0vBMOuyBjewH3ZKN7DNeawYz9PDEPlyt2lIoDh9+XXBJc694UGd2L6p/CA8e QQMFZqAv00yTbAzXG7I7bPnK0FGVOhtQw+eyzHfWIUs7Bu9riFmUTQVaKMr3jskttwk1 nhcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764570276; x=1765175076; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=peAT0TtJ+zmGu6HEzqEiByNE29w1TbiVx2+7wH8lyF8=; b=doAqrnnbOJHVEIvjvK7sYAM2BJMKJ3kDZTVlVeZ9BcYOoG+YaVD+qZKcByaQEE3Ix5 pFGVu7ZO4HL7ccdVO6TTppTt90OoozBo+W+AnZR+5XO80bBED/ModydY6Iycrd0jCW3i DjvVYbw4EfqFaLzP0WIJQS0QTUrl7+QrMMo01aBLkOoo5RHmnMFeSxEBugozXQM7GMdF pkKxR+xXEY0nZRrx8imrjYnKcGOudNDVHBGxDvVRf41WbLyLWVzOyr+rM573TB7n8FFr 7gRwjVGdKDXU/eln/PYSdDxb5VJ/AWa6TnFwCoTW97eQwjjXRSi9lrYNDCRTP/IsDyWL Jetg== X-Forwarded-Encrypted: i=1; AJvYcCVHDcdCt41YwFqtG9F/H42FYGZD7DzkFveHF9uasDCXgkBdFIk8t9vBnz9IyJG626dC/S9eekx/9AmUwm0=@vger.kernel.org X-Gm-Message-State: AOJu0YzpP9/2iZb5C+cfNLuHrCQAiaxRQLZG6TyelJfbALqD/p3V7T6p xq0mxmkVXASFNLJEy0q1gkL7+gOlNng8p2MSvZSa0D0s2zj+ILE3cDi0IJbZ3DeizyE= X-Gm-Gg: ASbGncsoXruSRKr8kvkRFcyXAQYK4nGiA/KG+64Vc0kXFxiSN7FNlVXznjj05iIwJdi 8GiQEVmqUjbuJidh6+ADndyrEMCSZt91w/mVwxkSmtjt8X9NCQzrs6X7S0tdIKGwZpKCn63qeP/ Z1EGApvTHblNQhSMlWWTfnXaIBYaWJAqw+qyORRKYQbkarkncdnZCbzUQkkz/ESFZQa5Ee31JKo 7ppnv+/8TOo1tFdOhtXoMLxrQ6j/DQ4JIJ2XCw75cNQfaR6t7qr8jmfsYKnqBuuoK77PKCMBG5T aK8M/lWNH3iMxAdKHLn8UO1k4PMIe4F3trb0qytiC0tWEed6rC8Yrwn4m00jSKYCU++0wJXnj6L jsRS/Itpo2uCvVKdhwPdXaVF0rOm4KX1/rmDcG2qJ918UV3o0SAUk+DRgkc9ojgVx7nAIxwOrGM OSxwNPVhnaeA== X-Google-Smtp-Source: AGHT+IGNMBL8zDhRobd+qHrdQkwX8FWvtMRKN8hXCxfnIN+ugTut4kAT7vSMmoOejqWih8bkdISh2A== X-Received: by 2002:a17:90b:4a08:b0:336:b60f:3936 with SMTP id 98e67ed59e1d1-34733e72342mr39442424a91.12.1764570276389; Sun, 30 Nov 2025 22:24:36 -0800 (PST) Received: from inspiron ([114.79.136.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3477b7341d2sm11828072a91.11.2025.11.30.22.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Nov 2025 22:24:36 -0800 (PST) Date: Mon, 1 Dec 2025 11:54:28 +0530 From: Prithvi Tambewagh To: Joseph Qi Cc: mark@fasheh.com, jlbec@evilplan.org, ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org, david.hunter.linux@gmail.com, khalid@kernel.org, syzbot+96d38c6e1655c1420a72@syzkaller.appspotmail.com Subject: Re: [PATCH] fs: ocfs2: fix kernel BUG in ocfs2_find_victim_chain Message-ID: References: <20251130104637.264258-1-activprithvi@gmail.com> <6d27a5aa-1e32-4dd3-997c-ddc015be88a3@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <6d27a5aa-1e32-4dd3-997c-ddc015be88a3@linux.alibaba.com> On Mon, Dec 01, 2025 at 10:51:49AM +0800, Joseph Qi wrote: > > >On 2025/11/30 18:46, Prithvi Tambewagh wrote: >> syzbot reported a kernel BUG in ocfs2_find_victim_chain() because the >> `cl_next_free_rec` field of the allocation chain list is 0, triggring the >> BUG_ON(!cl->cl_next_free_rec) condition and panicking the kernel. >> >> To fix this, `cl_next_free_rec` is checked inside the caller of >> ocfs2_find_victim_chain() i.e. ocfs2_claim_suballoc_bits() and if it is >> equal to 0, ocfs2_error() is called, to log the corruption and force the >> filesystem into read-only mode, to prevent further damage. >> >> Reported-by: syzbot+96d38c6e1655c1420a72@syzkaller.appspotmail.com >> Closes: https://syzkaller.appspot.com/bug?extid=96d38c6e1655c1420a72 >> Tested-by: syzbot+96d38c6e1655c1420a72@syzkaller.appspotmail.com >> Cc: stable@vger.kernel.org >> Signed-off-by: Prithvi Tambewagh >> --- >> fs/ocfs2/suballoc.c | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c >> index 6ac4dcd54588..84bb2d11c2aa 100644 >> --- a/fs/ocfs2/suballoc.c >> +++ b/fs/ocfs2/suballoc.c >> @@ -1993,6 +1993,13 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_alloc_context *ac, >> >> cl = (struct ocfs2_chain_list *) &fe->id2.i_chain; >> > >This blank line can be eliminated. > >> + if (le16_to_cpu(cl->cl_next_free_rec) == 0) { > >Better to add the upper limit check as well. e.g. > >!le16_to_cpu(cl->cl_next_free_rec) || >le16_to_cpu(cl->cl_next_free_rec) > le16_to_cpu(cl->cl_count) Hello Joseph, I went through the code in fs/ocfs2/suballoc.c, like this function static inline u16 ocfs2_find_smallest_chain(struct ocfs2_chain_list *cl) { u16 curr, best; best = curr = 0; while (curr < le16_to_cpu(cl->cl_count)) { if (le32_to_cpu(cl->cl_recs[best].c_total) > le32_to_cpu(cl->cl_recs[curr].c_total)) best = curr; curr++; } return best; } and in function ocfs2_block_group_alloc() these lines if (le16_to_cpu(cl->cl_next_free_rec) < le16_to_cpu(cl->cl_count)) le16_add_cpu(&cl->cl_next_free_rec, 1); and observed that according to the architecture of ocfs2, the chain list is in the form of 0-indexed array. In that case, the change you suggested for upper limit, could be re-written as le16_to_cpu(cl->cl_next_free_rec) >= le16_to_cpu(cl->cl_count) since value of cl->cl_next_free_rec greater than or equal to cl->cl_count will indicate that there are no available chains. Can you please review this? Thank you, Prithvi > >Thanks, >Joseph > >> + status = ocfs2_error(ac->ac_inode->i_sb, >> + "Chain allocator dinode %llu has 0 chains\n", >> + (unsigned long long)le64_to_cpu(fe->i_blkno)); >> + goto bail; >> + } >> + >> victim = ocfs2_find_victim_chain(cl); >> ac->ac_chain = victim; >> >> >> base-commit: 939f15e640f193616691d3bcde0089760e75b0d3 >