From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.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 4311D1E2858 for ; Tue, 2 Dec 2025 01:51:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764640278; cv=none; b=uVE+tJepvT2Dx0A8Ra+vD0n6D5xeTYueIdN883SwvIk3ClLE+S9vPCqJhMmnryAfjOK7EUva2DdsD6JeRlGj840dTGRONHv1eywTOKvUdNG+YFBa7CMeX0qkslQ3j0oS3vI3ior4oCV+H0NT5LZM3uhOjzD6F6guaJdB13pGVeI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764640278; c=relaxed/simple; bh=/8xkrEPazKfzyzrUumQ8ugo7oqOZcTRyp8/peU+RjUI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pb2gwVnHTa9h5CYaGT9lw0QGPfABAEPvmePSaO5B5ocdMqwGGI5hzAfWTptDZ3GX/MLuagUgWQM8uhSAJjOtf5MPRZPYBFJWAkbWXGYYWEP6viZx+EmY4Wz/wENYUIZPlBv+R5jAZxLtnIwg8ryix8appfimlROJEjkgBH8/aP8= 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=HJ0KsF+Y; arc=none smtp.client-ip=209.85.208.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="HJ0KsF+Y" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-640a0812658so1798492a12.0 for ; Mon, 01 Dec 2025 17:51:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764640275; x=1765245075; 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=Xvy/SLVzcwhGLHk+WQH9jNRotYaxhvGol5SkkdGX+y4=; b=HJ0KsF+YQVt3cWVbTmz66E8Y4CWctXhcKd1cHCj5/5CAxkJ5WsRzxE9eFInxfQi0Hz PJFtcpxhQA+20ezKAn5y1FH8VRRuHlu/72hp7w4nnvVu0SBg2TD3XbYkkE+UiHE8copA 7p9D9RNI+idyYtXcUhwsaWni142Gjkf4bxOxGU5Ym1SBS0hhcTZbmRUieuyKCWtTf2Ck 6YMxZH5IX0dXCtOFrltDtQAfrUUAIB81D+pc5r2Q18tKLX43xIaWHTdGlTYuEk8NrlLB 3p5ylQCaZpoS9anmjcbg+MMkHjbBNoWOBQnYSprcrvDbHswdtdlGPodEbNEyeQyDGXIx KE5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764640275; x=1765245075; 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=Xvy/SLVzcwhGLHk+WQH9jNRotYaxhvGol5SkkdGX+y4=; b=En+G2p8eH3GSX7wDW7LrEj//2IMilDX5DzS2WTAWcXP8cJrSZZfgMN9hIqZ7JKZeK5 9J5H7UndAvy6dxa8aBrDzvENqEMRKpXg4UuREymAzw74+QqtFFuSfrt9J3N7sKglSoV0 fx2E74ZuhdSjs+jMyXKwI1KZbxQpLQH+w42OJoZRz69IaDQfrtMm5Gw9Oxanvw49ub5T Ww5JfDCf4BGn86NQDOiS+jDzFaLTuCg5SUU3MI9P+T+Obtml5jlXveZ8CUZGYictV9rK 2W0KbdcExL4Pj0hauCzzVnp4riCkQXkkJIOZTA0UcfP3pSk3wDwd92KtShuUifIv4b03 kefQ== X-Forwarded-Encrypted: i=1; AJvYcCXmXuK7LBn09V0apXanpLG8RLoR9ktYdFdCt17ZB6Q1NylXSd6FUvL4njXDUGxAK3H1xnzcTihJciLoCC8=@vger.kernel.org X-Gm-Message-State: AOJu0YwpmsSMgxaXQlz5eevy2+VtmRDTNeJzWnUJY0kgKRMHDZwdB0Hx zP0DgIEtm8X3Jth9pKFqw0j7HPObYcABbLDcoC8Icps5cp6IZFgGZ3nl X-Gm-Gg: ASbGnct7eP+AUKcLvhi74ysRpRxaNZVbUUv/LcNl62PVfzpVGv/qYmQmjTMfrhxW5JN OSP0RA8xXPNg7nJlU26/2ez9NQ1NxuCIrsrEmld8IubYea/Z1IFi6MhaPtc2Z6RfZct7dHQssM5 DwCWj9U2f9GOwit+TE8Co8FDCseE4RYZ5ij7soDp/gTyzIlk6QQgg/zAEb31uF8hCS5EKqza973 MS78R1jbULaV4wAtvzYnQHQcn2E0btronmsJW1OpzSti4m1QsKaP6BWK7XbsqkFbh0Z0e0ekCIP 2Hmubkka7wLw+Uz9Hh/H85rloZnZ1yLwVJPI9yGKicWIVJYg1Z61vygbZfGyzvEmFjnUwjdNfro MZxBJsyIYdaelUwsk7HpyO9n7GVZoWi8/d+Zfd4w+W23YTjsbVLJzQmyb/2RfWDLN9hAif8XLiX GMtEFiTnuQ X-Google-Smtp-Source: AGHT+IGg9p02+L/a/lXtBqHXbLkKYNbcyW7WWXzp+P5g1sUiRvzwwWtLYKBJH2KeMk4RAdKNLuaZbQ== X-Received: by 2002:a05:6402:3512:b0:647:70c0:f3f5 with SMTP id 4fb4d7f45d1cf-64770c0f478mr7226967a12.33.1764640274443; Mon, 01 Dec 2025 17:51:14 -0800 (PST) Received: from eray-kasa ([2a02:4e0:2d14:1a1:8eee:b306:2d20:a328]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64751062261sm15624912a12.33.2025.12.01.17.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 17:51:14 -0800 (PST) Date: Tue, 2 Dec 2025 04:51:11 +0300 From: Ahmet Eray Karadag To: Joseph Qi Cc: Heming Zhao , mark@fasheh.com, jlbec@evilplan.org, ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, david.hunter.linux@gmail.com, skhan@linuxfoundation.org, syzbot+55c40ae8a0e5f3659f2b@syzkaller.appspotmail.com, Albin Babu Varghese Subject: Re: [PATCH v3] ocfs2: Invalidate inode if i_mode is zero after block read Message-ID: References: <20251108120133.37443-3-eraykrdg1@gmail.com> <20251119221723.171746-2-eraykrdg1@gmail.com> <971dd5c8-970d-47d0-8cd3-b2b56aa0aee8@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 Content-Disposition: inline In-Reply-To: <971dd5c8-970d-47d0-8cd3-b2b56aa0aee8@linux.alibaba.com> On Tue, Dec 02, 2025 at 09:25:14AM +0800, Joseph Qi wrote: > > > On 2025/11/20 10:32, Heming Zhao wrote: > > On Thu, Nov 20, 2025 at 01:17:24AM +0300, Ahmet Eray Karadag wrote: > >> A panic occurs in ocfs2_unlink due to WARN_ON(inode->i_nlink == 0) when > >> handling a corrupted inode with i_mode=0 and i_nlink=0 in memory. > >> > >> This "zombie" inode is created because ocfs2_read_locked_inode proceeds > >> even after ocfs2_validate_inode_block successfully validates a block > >> that structurally looks okay (passes checksum, signature etc.) but > >> contains semantically invalid data (specifically i_mode=0). The current > >> validation function doesn't check for i_mode being zero. > >> > >> This results in an in-memory inode with i_mode=0 being added to the VFS > >> cache, which later triggers the panic during unlink. > >> > >> Prevent this by adding an explicit check for (i_mode == 0, i_nlink == 0, non-orphan) > >> within ocfs2_validate_inode_block. If the check is true, return -EFSCORRUPTED to signal > >> corruption. This causes the caller (ocfs2_read_locked_inode) to invoke > >> make_bad_inode(), correctly preventing the zombie inode from entering > >> the cache. > >> > >> Reported-by: syzbot+55c40ae8a0e5f3659f2b@syzkaller.appspotmail.com > >> Fixes: https://syzkaller.appspot.com/bug?extid=55c40ae8a0e5f3659f2b > >> Co-developed-by: Albin Babu Varghese > >> Signed-off-by: Albin Babu Varghese > >> Signed-off-by: Ahmet Eray Karadag > >> Previous link: https://lore.kernel.org/all/20251022222752.46758-2-eraykrdg1@gmail.com/T/ > >> --- > >> v2: > >> - Only checking either i_links_count == 0 or i_mode == 0 > >> - Not performing le16_to_cpu() anymore > >> - Tested with ocfs2-test > >> --- > >> v3: > >> - Add checking both high and low bits of i_links_count > >> --- > >> fs/ocfs2/inode.c | 7 +++++++ > >> 1 file changed, 7 insertions(+) > >> > >> diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c > >> index 14bf440ea4df..c8b129db756e 100644 > >> --- a/fs/ocfs2/inode.c > >> +++ b/fs/ocfs2/inode.c > >> @@ -1456,6 +1456,13 @@ int ocfs2_validate_inode_block(struct super_block *sb, > >> goto bail; > >> } > >> > >> + if (!ocfs2_read_links_count(di) || !di->i_mode) { > > > > the code logic looks good to me, but I prefer the following code to save a few > > cpu cycles. > > > > ``` > > /* only check if the "link count" or i_mode is ZERO */ > > if (!(di->i_links_count | di->i_links_count_hi) || !di->i_mode) > > ``` > > > > @Joseph > > which do you like? > > > Sorry to miss this thread discuss. > The above check looks wried since "(di->i_links_count|di->i_links_count_hi)" > is meaningless, though it may work well... > So I'd prefer the code readability first. > > BTW, from the syzbot report, I haven't seen where to show i_mode=0 or > i_nlink=0. Am I missing something? You are right, the syzbot report itself doesn't explicitly dump the inode values. I reproduced the issue locally and debugged ocfs2_unlink() to inspect the inode attributes just before the crash. The debug output confirmed that the inode had: i_ino = 17057 i_nlink = 0 i_mode = 0 It appears the inode block read succeeds (physically), but due to corruption, validation was insufficient, allowing a zeroed/corrupted inode struct to be initialized in the VFS cache. > > Thanks, > Joseph > Regarding the patch logic: We had previously discussed and seemed to agree on an approach in the thread linked below, but since I didn't get a final response there, I refreshed the patch here. https://lore.kernel.org/all/20251022222752.46758-2-eraykrdg1@gmail.com/T/ Thanks, Eray