Linux fsverity development list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrey Albershteyn" <aalbersh@kernel.org>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Christoph Hellwig" <hch@lst.de>,
	"Carlos Maiolino" <cem@kernel.org>,
	fsverity <fsverity@lists.linux.dev>
Cc: david@fromorbit.com, "Darrick J. Wong" <djwong@kernel.org>
Subject: Re: [PATCH v19 14/15] xfs: introduce health state for corrupted fsverity metadata
Date: Fri, 20 Nov 2026 16:36:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-225577@kernel.org> (raw)
In-Reply-To: <20261120155752.192025-15-aalbersh@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] xfs: XFS_SICK_INO_FSVERITY is never cleared by online scrub
  or repair
- [Medium] xfs: race and stale XFS_SICK_INO_FSVERITY in
  xfs_fsverity_get_descriptor()
--

commit d3eed7a2ba01498b4bc83bae6fcdf5fb68591bb5
Author: Andrey Albershteyn <aalbersh@kernel.org>

xfs: introduce health state for corrupted fsverity metadata

This commit adds the XFS_SICK_INO_FSVERITY health flag (exposed to
userspace via bulkstat as XFS_BS_SICK_FSVERITY) and marks inodes sick
when xfs_fsverity_get_descriptor() detects corrupted fsverity metadata.

> diff --git a/fs/xfs/libxfs/xfs_health.h b/fs/xfs/libxfs/xfs_health.h
> index 1d45cf5789e86..932b447190da7 100644
> --- a/fs/xfs/libxfs/xfs_health.h
> +++ b/fs/xfs/libxfs/xfs_health.h
> @@ -104,6 +104,7 @@ struct xfs_rtgroup;
>  /* Don't propagate sick status to ag health summary during inactivation */
>  #define XFS_SICK_INO_FORGET	(1 << 12)
>  #define XFS_SICK_INO_DIRTREE	(1 << 13)  /* directory tree structure */
> +#define XFS_SICK_INO_FSVERITY	(1 << 14)  /* fsverity metadata */
>  
>  /* Primary evidence of health problems in a given group. */
>  #define XFS_SICK_FS_PRIMARY	(XFS_SICK_FS_COUNTERS | \
> @@ -140,7 +141,8 @@ struct xfs_rtgroup;
>  				 XFS_SICK_INO_XATTR | \
>  				 XFS_SICK_INO_SYMLINK | \
>  				 XFS_SICK_INO_PARENT | \
> -				 XFS_SICK_INO_DIRTREE)
> +				 XFS_SICK_INO_DIRTREE | \
> +				 XFS_SICK_INO_FSVERITY)

[Severity: Medium]
Does online scrub or repair ever clear XFS_SICK_INO_FSVERITY once it is
set?

When xchk_prepare_iscrub() runs xchk_inode_setup_verity() on an inode
with broken verity metadata, xfs_fsverity_get_descriptor() sets
XFS_SICK_INO_FSVERITY on ip->i_sick.  However, type_to_health_flag for
XFS_SCRUB_TYPE_INODE only tracks XFS_SICK_INO_CORE, and neither
xchk_inode() nor xrep_inode_verity() adds XFS_SICK_INO_FSVERITY to
sc->sick_mask or sc->healthy_mask.

After xrep_inode_verity() repairs the inode and the post-repair re-scrub
pass calls xchk_update_health(), xfs_inode_mark_healthy() clears
XFS_SICK_INO_CORE and XFS_SICK_INO_FORGET while leaving
XFS_SICK_INO_FSVERITY set on ip->i_sick.  The repaired inode continues
to report XFS_BS_SICK_FSVERITY in bulkstat, cannot be reclaimed by
xfs_reclaim_igrab(), and causes xfs_inactive_health() to falsely mark
the AG sick with XFS_SICK_AG_INODES when inactivated.

> diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c
> index ec4006729e757..36520a187a2c7 100644
> --- a/fs/xfs/xfs_fsverity.c
> +++ b/fs/xfs/xfs_fsverity.c
> @@ -98,8 +98,10 @@ xfs_fsverity_get_descriptor(
>  	if (error)
>  		return error;
>  
> -	if (is_empty)
> +	if (is_empty) {
> +		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
>  		return -ENODATA;
> +	}
>  
>  	/*
>  	 * Make sure we can open large file on a 32-bit kernel
> @@ -110,8 +112,10 @@ xfs_fsverity_get_descriptor(
>  
>  	last_block_offset =
>  		XFS_FSB_TO_B(mp, rec.br_startoff + rec.br_blockcount);
> -	if (last_block_offset <= xfs_fsverity_metadata_offset(ip))
> +	if (last_block_offset <= xfs_fsverity_metadata_offset(ip)) {
> +		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
>  		return -ENODATA;
> +	}
>  
>  	desc_size_pos = last_block_offset - sizeof(__be32);
>  	error = fsverity_pagecache_read(inode, (char *)&d_desc_size,
> @@ -120,20 +124,29 @@ xfs_fsverity_get_descriptor(
>  		return error;
>  
>  	desc_size = be32_to_cpu(d_desc_size);
> -	if (XFS_IS_CORRUPT(mp, desc_size > FS_VERITY_MAX_DESCRIPTOR_SIZE))
> +	if (XFS_IS_CORRUPT(mp, desc_size > FS_VERITY_MAX_DESCRIPTOR_SIZE)) {
> +		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
>  		return -ERANGE;
> -	if (XFS_IS_CORRUPT(mp, desc_size > desc_size_pos))
> +	}

[Severity: Medium]
Can an in-flight xfs_fsverity_get_descriptor() race with online repair
and mark the inode sick after S_VERITY has already been cleared?

xfs_fsverity_get_descriptor() checks S_VERITY and reads the last extent
under XFS_ILOCK_EXCL, then drops XFS_ILOCK_EXCL before reading from the
pagecache and validating the descriptor without holding XFS_IOLOCK or
XFS_MMAPLOCK:

CPU0                                  CPU1
xfs_file_open()
  ...
  xfs_fsverity_get_descriptor()
    xfs_ilock(ip, XFS_ILOCK_EXCL)
    /* sees S_VERITY set */
    xfs_bmap_last_extent(...)
    xfs_iunlock(ip, XFS_ILOCK_EXCL)
                                      xchk_prepare_iscrub()
                                        xchk_ilock(sc, XFS_IOLOCK_EXCL)
                                        xchk_ilock(sc, XFS_MMAPLOCK_EXCL)
                                        truncate_inode_pages(..., isize)
                                        xchk_ilock(sc, XFS_ILOCK_EXCL)
                                      xrep_inode()
                                        xrep_inode_verity()
                                          xfs_bunmapi_range(...)
                                          inode_set_flags(..., 0, S_VERITY)
                                      xchk_teardown_inode()
    fsverity_pagecache_read(...)
    xfs_inode_mark_sick(ip,
        XFS_SICK_INO_FSVERITY)  <-- marks repaired inode sick

Besides marking the already-repaired inode sick, if CPU0 runs
fsverity_pagecache_read() between truncate_inode_pages() and
xfs_bunmapi_range(), it can also repopulate post-EOF folios in the
pagecache because read_mapping_folio() does not acquire XFS_MMAPLOCK.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120155752.192025-1-aalbersh@kernel.org?part=14

  reply	other threads:[~2026-11-20 16:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 15:57 [PATCH v19 00/15] fs-verity support for XFS with post EOF merkle tree Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 01/15] xfs: introduce fsverity on-disk changes Andrey Albershteyn
2026-11-20 16:26   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 02/15] xfs: don't allow to enable DAX on fs-verity sealed inode Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 03/15] xfs: disable direct read path for fs-verity files Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 04/15] xfs: don't report dio_mem_align and dio_offset_align for fsverity files Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 05/15] xfs: handle fsverity I/O in write/read path Andrey Albershteyn
2026-11-20 16:27   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 06/15] xfs: use read ioend for fsverity data verification Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 07/15] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 08/15] xfs: don't remove written extents past EOF on fsverity inodes Andrey Albershteyn
2026-11-20 16:21   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 09/15] xfs: add fs-verity support Andrey Albershteyn
2026-11-20 16:51   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 10/15] xfs: initialize fs-verity on file open Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 11/15] xfs: add fs-verity ioctls Andrey Albershteyn
2026-11-20 16:19   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 12/15] xfs: advertise fs-verity being available on filesystem Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 13/15] xfs: check and repair the verity inode flag state Andrey Albershteyn
2026-11-20 16:28   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 14/15] xfs: introduce health state for corrupted fsverity metadata Andrey Albershteyn
2026-11-20 16:36   ` sashiko-bot [this message]
2026-11-20 15:57 ` [PATCH v19 15/15] xfs: enable ro-compat fs-verity flag Andrey Albershteyn
2026-11-20 16:38   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-225577@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aalbersh@kernel.org \
    --cc=cem@kernel.org \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=fsverity@lists.linux.dev \
    --cc=hch@lst.de \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox