Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (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 7C7F7328B56 for ; Mon, 19 Jan 2026 17:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845456; cv=none; b=qGuWEE5DID5akSj1gBr4qiAIo9po9bjq0iglaf4m86G4wXZa+j8KhfOou5lyEYpFOZaiah70V5nqTxP5gPnoLHI6Yd+DXjpBG4G1XxlSoyozxXEVqRuCejApHMpq5ENljy46qFAOadGqSRuj2SYreyHMLZz5PGInjWRnt0KDSGQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768845456; c=relaxed/simple; bh=cpKTHoVU6rxq8ro6IVZyVowYOJaQNQAyFfEqHXJQyFQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oIe9WlqeHN5Z0N9NDotZRe9NFNV1U0jHbgf8Ck8N9pOsvfpTaRZNCUDtD9WGaM0hreZrH3VZIOJKUfX1zrc/HTDR4KKkwxhgFVf7Gv1pyHKUhmb1u6t636MvXn9+T1le+9fShNZWuw3qseqB87ejx7zUIK1RztLTM+3rq2y6CvU= 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=WLV3qbol; arc=none smtp.client-ip=209.85.160.45 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="WLV3qbol" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-4042905015cso3145801fac.0 for ; Mon, 19 Jan 2026 09:57:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768845454; x=1769450254; 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=LdOCSHF7WzjxbGwyP2+q0DqDBTdH7rLJK6gj6eHKSiE=; b=WLV3qbolPWf31hFrCWQ2XHqC/4sOEruFY9FbgijTBeEE7/glHdTzjyv7zZvR54fFgb qU9bo7nQTi6MkC/V/QLd0qvbPc0qOwWOUYyRDWHCU9RpW24JZcONgzMQcTg2KBRJVOZo xD/AGCoTWKzohpXHeu+qDUTQmcZ4IY04gm2T/3O2qXZwTG0KtLgqyK/LtgHT4fOORmpg 6C6ca/YWH/IviqkfaE7FjH2F+I3MqzIhMIO+FkksdwfPrUgrDhBUmDRF4GzEY6+/YDDE arDstLCLjIYzTta5VZMWw4nA/6xlgQclwzhO56WPfqDKCef6r6VqVbqUwVo/Ovk+dBaO Ta7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768845454; x=1769450254; 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=LdOCSHF7WzjxbGwyP2+q0DqDBTdH7rLJK6gj6eHKSiE=; b=rtbZ4mKOc51zQ7MZRHl5EUnm3dQw0whsn3wK+ZErqFNE4Dy7ry8NbMrHTGUYSrHb5p XtAA68j2HEgGp1iZQKTZmGxUrWQX7JY7mJKkZt2wtifi6RDDUUzyVvvI21wJxRzzNfBz KnBJT160XaHXqbnbTBtIEgzAOJVdLyTGqfdSh0A4ZuTxaycA4h+UPBtRhNAXeLCBGFdw 4RwHC/ooNluKnlVxNNu0k/pAg3g05Z7j9i4X4M6c7hzSzyVvhpBBTJ9CUbE1J0FlCe4+ q8kOcjqlgIZYd9GfKMDf8mXfJvOFChwrC0znEheMEMRo1C6Hwlq0RS/iuZ6dLzJo162m arQg== X-Forwarded-Encrypted: i=1; AJvYcCXEby29TiWZW7Fduh4Y2wiUFmFuksHvWW3YesWANGR6pdtNU+mVv93zanO1mRel6OOycI/LBfFyp7YnkWw=@vger.kernel.org X-Gm-Message-State: AOJu0YyCpjQVElpfADpbstpWqTnKRozokty3hobYcGOXM2GW5RRufr8r RlG/n3xMg6bJTw2pp2BzHzBk4ahvuP2pzGThJKzrKBsYJZf5L0+aZEEo X-Gm-Gg: AY/fxX6pzlOSBrGumsdtwN4rz/MzDkU2gCebBFrYhIgTwAMJR8AfqkMjQyXCOU3bV9f KnsWdXaeo1WNU0xw1wenFY08VWnSlcC8v+MGkSQMf05YoKyJbf0Z3xNhtBKBfEUXRGwdWE4ReEM +YF3dG06Paf86khTRSeF/Yab5cJ7GX3LC5BuiWncnIF6Mo0tK5cDXLuPXKIx0qX7hpFO/WRrkXH oLayyB9gmgFlaEd9BdRkeNvuPz6+bs3V+7JRcY49a3NY1Xtj9Pxn5RII5PRRBeF0ffyJ4bmcPuZ gcAlbuZNwxhQo9r9X0zQTXt6h9FJl9ZASYBRSOM0cS/tCbBlrf/oae08TTl9MO1XttNsn2HTYAA dxWpB4auf2NfFSxELGYiW5f4i+EvwvWqVxXSZqhhAmTrz6TPGEYsSBgnLVVW1ctdbUYUfsdGgJi 3LTh5Lzd8TsvzGHorBVxgMKUOROBNLsQve X-Received: by 2002:a05:6820:1898:b0:65f:6cda:d429 with SMTP id 006d021491bc7-661188caae3mr5032368eaf.4.1768845454290; Mon, 19 Jan 2026 09:57:34 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-66118781fedsm4886179eaf.11.2026.01.19.09.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 09:57:33 -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 NULL pointer dereference in ocfs2_xattr_get_rec Date: Mon, 19 Jan 2026 17:57:32 +0000 Message-Id: <20260119175732.1444-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:49:16 +0800, Heming Zhao wrote: > On Sat, Jan 17, 2026 at 05:35:56PM +0000, Jiasheng Jiang wrote: >> In ocfs2_xattr_get_rec, the variable 'rec' is initialized to NULL. >> If the extent list 'el' is empty (l_next_free_rec == 0), the loop >> iterating over the records is skipped, leaving 'rec' as NULL. >> >> Since 'e_blkno' is initialized to 0, the function enters the error >> handling block 'if (!e_blkno)'. Inside this block, the function calls >> ocfs2_error() and attempts to dereference 'rec' via >> 'le32_to_cpu(rec->e_cpos)' and 'ocfs2_rec_clusters(el, rec)'. This >> results in a NULL pointer dereference and a kernel panic. > > 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, such inconsistency leads to a NULL pointer dereference and panics the system. This patch is intended as a hardening measure. Instead of crashing the kernel when encountering such invalid on-disk data, it is safer to report a filesystem error via ocfs2_error and abort the operation gracefully. This approach aligns with recent fixes in OCFS2. For example, Commit 44acc46d182f ("ocfs2: avoid NULL pointer dereference in dx_dir_lookup_rec()") addressed an identical issue where an empty extent list left the 'rec' pointer NULL. I will update the commit message in the next version to explicitly state that this is a hardening measure against on-disk corruption, ensuring the rationale is accurate. - Jiasheng >> >> Fix this by ensuring 'rec' is not NULL before accessing its members >> within the error handling path, or by checking for an empty list >> explicitly. >> >> Signed-off-by: Jiasheng Jiang >> --- >> fs/ocfs2/xattr.c | 14 ++++++++++---- >> 1 file changed, 10 insertions(+), 4 deletions(-) >> >> diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c >> index 1b21fbc16d73..b018c84dbc05 100644 >> --- a/fs/ocfs2/xattr.c >> +++ b/fs/ocfs2/xattr.c >> @@ -3757,10 +3757,16 @@ static int ocfs2_xattr_get_rec(struct inode *inode, >> } >> >> if (!e_blkno) { >> - ret = ocfs2_error(inode->i_sb, "Inode %lu has bad extent record (%u, %u, 0) in xattr\n", >> - inode->i_ino, >> - le32_to_cpu(rec->e_cpos), >> - ocfs2_rec_clusters(el, rec)); >> + if (rec) >> + ret = ocfs2_error(inode->i_sb, >> + "Inode %lu has bad extent record (%u, %u, 0) in xattr\n", >> + inode->i_ino, >> + le32_to_cpu(rec->e_cpos), >> + ocfs2_rec_clusters(el, rec)); >> + else >> + ret = ocfs2_error(inode->i_sb, >> + "Inode %lu has bad extent record (NULL) in xattr\n", >> + inode->i_ino); >> goto out; >> } >> >> -- >> 2.25.1 >> >>