From nobody Mon Jun 8 14:35:26 2026 Received: from mail-oa1-f67.google.com (mail-oa1-f67.google.com [209.85.160.67]) (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 66FDF2E7385 for ; Thu, 28 May 2026 15:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779981669; cv=none; b=bjTyDi5Eq0wG9hoE0I9C2WFdmJcfx7iwy68ooXykiCuUlsRF03OTYCUjaf8+FPmOSNzEJ7N7WfKBcgSRhY0yspaMNFXl4A01cC/nA8ZNs3nUJp4Lt9SaaM+z0QvBKEMbl+ra9uSVN9l7ZzzrsCvGM0Op5pP75y9CituAFD8uVzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779981669; c=relaxed/simple; bh=cnrMv9pFINjlIDVxwMlibIQsjXF+MWcPnxVt7TCPaO4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=No41VoUflFRySzyLeKusKarJGy3dqNBIRpOXrI5tbWwMgzOosruU+BQkH+FNFy6P/dQu3xSwMQLGQPD76M0DnxCObryC1cCWv182BzX8+VAhWQv8qgEZEH+LpaC9sv1dbSjk9FN/fswTNoO/etwDP5HfKF0VWEVQb/exXnCj5j0= 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=bhPvCjah; arc=none smtp.client-ip=209.85.160.67 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="bhPvCjah" Received: by mail-oa1-f67.google.com with SMTP id 586e51a60fabf-43b70c501a7so4182073fac.2 for ; Thu, 28 May 2026 08:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779981668; x=1780586468; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lKyeZOhiIPY0gsvqQF5rr0FjC/35V41zMh9J4dscFOg=; b=bhPvCjahXZnS4/Df0uCuB6gumM2ft7Nn01tf6nZiaAMiV8sVbfwbO6GsgtWAe7RU+x oIDGh6q+f3ZlNZW1eqTIsnQSjcf6PHq1KCjWQcKrGavfGExIwqFNmmYyYpMTPcTWdkb7 6bbqQ67+t3DY3Z2rZ0jhPZQOdDkdlwivyXlSTTY3DacEf+vZx2+1+LXDUF+2oOD0Laq2 MCStVbnrlYSBt1YK2PElrKs+jjcX1oJ0CAxX/Q/QacIpY15IHbhcgSWBwmBZC9aLLFcM /z3tgeFQ9BHULZlOr+1oWbjcB9+4L11eaLj8BRuf++9EyXjCpM6RmAu1kNxbA3cJYQ9J CQzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779981668; x=1780586468; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lKyeZOhiIPY0gsvqQF5rr0FjC/35V41zMh9J4dscFOg=; b=OoD4fyFUTeq4FEdaGu8HNDAEQY6LDqGq2f9b4wpNXlx+OGGBVZPUZV7FkhIsiEjMQZ DqmNu1hfBf4nWWgQ/4GSB5pIpdbXZHhtvIez+P2LfGLnyfPDle//+kU/qY3B0lC5RDuG XRFXFlOcrmoSM7cS7yI0pnE+rzTAtAryNeIAyMAPA7of5D2IrxyZfHd8OEYyJ6WjKVaU FB3sYfHMWV7Zwv8TyCMYCOfYzJfswQZe9QNUgFVcP1TPxqP/WmmzlvEEMAYW6JG+kYyv pwqRj6DXrAn6drYxphenhCfiIOWyTsno7sNj0KIrVmrSjwvPm/HFm92pMR6Q/zx+uK1/ 3NZw== X-Forwarded-Encrypted: i=1; AFNElJ/AzU1ev7cDwsEhx3FvHJBEOrXA0xaGZGuhPFGDTP6d0STy5IViyLXDoz9voQco37X8QkFBUq4s/AMmkS0=@vger.kernel.org X-Gm-Message-State: AOJu0YwZ+QE5i6h9gt3aVtKb0uPMUr8u9Ob/OG2RyM9Id9Vt0NY/JT+B sw6KshwXcfjXuCkakRky5DMyzcimH546HSFcFDoj78W1mCqXp5ziS4VFaKt41W/al1DJOQ== X-Gm-Gg: Acq92OGOQVqiSgRsHHembPgQLeKgEFMEGHJpHcsjifKDqKKuDaR4+7ePejSYWvRrasR NxzJa8zt7LVZBt7mPLeIs98OSexvVw3b6Pn8UKBQv+dT51OAx1A7Eueso/39/X1Ktbhe9hvO82w NrwjxayJ3hHoocjO5tFlkbL2OlQM4RfHot6RSA2ZhQNdIcatJBcI92otLhCXdDAT4X68AK0uI2H +8kRj6cA5D8JJoI7B6SCXTSYBHxaiDsGUY/E84cnjRSTTXY17z39k+80LMcRgGvO0hpvW+ni6fL rMIrFvSrSjuFvqKl7n6IePzMGFjiSUuSlvHgFzMtTn9FRGXrez1xWXwx6EwAiE0BYFD0XoaytaD 6I3Q8yjMcAOq2RozB/WvZsoa6lddTgljPRP2ax6Bpntrswym9DFdsKxYhGE+10c3e5Tl5hqtZPL q3VQ/YjaxESfuk8Jon0zuAzt9bZnhppJrd3HJwzwpbOw== X-Received: by 2002:a05:6a21:618e:b0:3b2:864a:ed74 with SMTP id adf61e73a8af0-3b3293bb68amr30607340637.43.1779981157661; Thu, 28 May 2026 08:12:37 -0700 (PDT) Received: from localhost ([111.228.63.84]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c852054c8a0sm15459221a12.15.2026.05.28.08.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 08:12:37 -0700 (PDT) From: Zhang Cen To: Mark Fasheh , Joel Becker , Joseph Qi Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, zerocling0077@gmail.com, 2045gemini@gmail.com, Zhang Cen Subject: [PATCH] ocfs2: validate fast symlink target during inode read Date: Thu, 28 May 2026 23:12:30 +0800 Message-Id: <20260528151230.361127-1-rollkingzzc@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ocfs2_validate_inode_block() already rejects several inconsistent self-contained dinodes before they are exposed to the rest of the filesystem. Fast symlinks need the same treatment. A zero-cluster symlink is treated as a fast symlink and later read through page_get_link() and ocfs2_fast_symlink_read_folio(). That path uses strnlen() on the inline payload and then copies len + 1 bytes into the folio. If a corrupt dinode stores an i_size that does not fit the inline area or omits the terminating NUL at i_size, that copy reads past the end of the inode block buffer. Reject zero-cluster symlink dinodes whose i_size exceeds the inline fast-symlink capacity or whose inline payload is not NUL-terminated exactly at i_size when the inode block is validated. This keeps malformed fast symlinks from reaching the read path. Validation reproduced this kernel report: KASAN use-after-free in ocfs2_fast_symlink_read_folio+0x12c/0x1f0 RIP: 0033:0x7f5c6d859aa7 Read of size 3905 Call trace: dump_stack_lvl+0x66/0xa0 (?:?) print_report+0xce/0x630 (?:?) ocfs2_fast_symlink_read_folio+0x12c/0x1f0 (fs/ocfs2/inode.c:?) srso_alias_return_thunk+0x5/0xfbef5 (?:?) __virt_addr_valid+0x19f/0x330 (?:?) kasan_report+0xe0/0x110 (?:?) kasan_check_range+0x105/0x1b0 (?:?) __asan_memcpy+0x23/0x60 (?:?) filemap_read_folio+0x27/0xe0 (?:?) filemap_read_folio+0x35/0xe0 (?:?) do_read_cache_folio+0x138/0x230 (?:?) __page_get_link+0x26/0x110 (?:?) page_get_link+0x2e/0x70 (?:?) vfs_readlink+0x15e/0x250 (?:?) touch_atime+0x4d/0x370 (?:?) do_readlinkat+0x186/0x200 (?:?) do_user_addr_fault+0x65a/0x890 (?:?) __x64_sys_readlink+0x46/0x60 (?:?) do_syscall_64+0x115/0x6a0 (arch/x86/entry/syscall_64.c:87) entry_SYSCALL_64_after_hwframe+0x77/0x7f (?:?) Fixes: ea022dfb3c2a ("ocfs: simplify symlink handling") Assisted-by: Codex:gpt-5.5 Signed-off-by: Zhang Cen Reviewed-by: Joseph Qi --- fs/ocfs2/inode.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c index a510a0eb1adc..e54a320f35f1 100644 --- a/fs/ocfs2/inode.c +++ b/fs/ocfs2/inode.c @@ -1525,6 +1525,29 @@ int ocfs2_validate_inode_block(struct super_block *s= b, } } =20 + if (S_ISLNK(le16_to_cpu(di->i_mode)) && + !le32_to_cpu(di->i_clusters)) { + int max_inline =3D ocfs2_fast_symlink_chars(sb); + u64 i_size =3D le64_to_cpu(di->i_size); + + if (i_size >=3D max_inline) { + rc =3D ocfs2_error(sb, + "Invalid dinode #%llu: fast symlink i_size %llu exceeds max %d\n", + (unsigned long long)bh->b_blocknr, + (unsigned long long)i_size, + max_inline - 1); + goto bail; + } + + if (strnlen((char *)di->id2.i_symlink, i_size + 1) !=3D i_size) { + rc =3D ocfs2_error(sb, + "Invalid dinode #%llu: fast symlink is not NUL-terminated at i_size = %llu\n", + (unsigned long long)bh->b_blocknr, + (unsigned long long)i_size); + goto bail; + } + } + if (le32_to_cpu(di->i_flags) & OCFS2_CHAIN_FL) { struct ocfs2_chain_list *cl =3D &di->id2.i_chain; u16 bpc =3D 1 << (OCFS2_SB(sb)->s_clustersize_bits - @@ -1812,4 +1835,3 @@ const struct ocfs2_caching_operations ocfs2_inode_cac= hing_ops =3D { .co_io_lock =3D ocfs2_inode_cache_io_lock, .co_io_unlock =3D ocfs2_inode_cache_io_unlock, }; - --=20 2.43.0