linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xfs: set inode size after creating symlink
@ 2021-01-21 15:19 Jeffrey Mitchell
  2021-01-21 18:41 ` Darrick J. Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jeffrey Mitchell @ 2021-01-21 15:19 UTC (permalink / raw)
  To: Darrick J . Wong; +Cc: linux-xfs, linux-kernel, Jeffrey Mitchell

When XFS creates a new symlink, it writes its size to disk but not to the
VFS inode. This causes i_size_read() to return 0 for that symlink until
it is re-read from disk, for example when the system is rebooted.

I found this inconsistency while protecting directories with eCryptFS.
The command "stat path/to/symlink/in/ecryptfs" will report "Size: 0" if
the symlink was created after the last reboot on an XFS root.

Call i_size_write() in xfs_symlink()

Signed-off-by: Jeffrey Mitchell <jeffrey.mitchell@starlab.io>
---
 fs/xfs/xfs_symlink.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c
index 1f43fd7f3209..c835827ae389 100644
--- a/fs/xfs/xfs_symlink.c
+++ b/fs/xfs/xfs_symlink.c
@@ -300,6 +300,7 @@ xfs_symlink(
 		}
 		ASSERT(pathlen == 0);
 	}
+	i_size_write(VFS_I(ip), ip->i_d.di_size);
 
 	/*
 	 * Create the directory entry for the symlink.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] xfs: set inode size after creating symlink
  2021-01-21 15:19 [PATCH] xfs: set inode size after creating symlink Jeffrey Mitchell
@ 2021-01-21 18:41 ` Darrick J. Wong
  2021-01-21 19:21   ` Jeffrey Mitchell
  2021-01-21 19:58 ` Brian Foster
  2021-01-22  8:02 ` Christoph Hellwig
  2 siblings, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2021-01-21 18:41 UTC (permalink / raw)
  To: Jeffrey Mitchell; +Cc: linux-xfs, linux-kernel

On Thu, Jan 21, 2021 at 09:19:12AM -0600, Jeffrey Mitchell wrote:
> When XFS creates a new symlink, it writes its size to disk but not to the
> VFS inode. This causes i_size_read() to return 0 for that symlink until
> it is re-read from disk, for example when the system is rebooted.
> 
> I found this inconsistency while protecting directories with eCryptFS.

Heh.  No doubt caused by the fact that we only call i_size_write for
regular files, ecryptfs copies i_size_read() of the lower dentry into
the ecryptfs inode, and ecryptfs_getattr_link and doesn't call ->getattr
on the lower inode.

Do directories have the same problem?  I'm guessing no because every
other file type calls vfs_getattr on the lower dentry, which should link
us to xfs_vn_getattr.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D


> The command "stat path/to/symlink/in/ecryptfs" will report "Size: 0" if
> the symlink was created after the last reboot on an XFS root.
> 
> Call i_size_write() in xfs_symlink()
> 
> Signed-off-by: Jeffrey Mitchell <jeffrey.mitchell@starlab.io>
> ---
>  fs/xfs/xfs_symlink.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c
> index 1f43fd7f3209..c835827ae389 100644
> --- a/fs/xfs/xfs_symlink.c
> +++ b/fs/xfs/xfs_symlink.c
> @@ -300,6 +300,7 @@ xfs_symlink(
>  		}
>  		ASSERT(pathlen == 0);
>  	}
> +	i_size_write(VFS_I(ip), ip->i_d.di_size);
>  
>  	/*
>  	 * Create the directory entry for the symlink.
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] xfs: set inode size after creating symlink
  2021-01-21 18:41 ` Darrick J. Wong
@ 2021-01-21 19:21   ` Jeffrey Mitchell
  0 siblings, 0 replies; 5+ messages in thread
From: Jeffrey Mitchell @ 2021-01-21 19:21 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, linux-kernel

On Thu, Jan 21, 2021 at 10:41:37AM -0800, Darrick J. Wong wrote:
> Do directories have the same problem?

Yes, I just checked in a VM. While ecryptfs does call vfs_getattr(), it
only uses the "blocks" value to supplement the data from an identical
generic_fillattr() call to what ecryptfs_getattr_link() uses. The reported
size still comes from i_size_read().

V/R,
Jeffrey Mitchell

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] xfs: set inode size after creating symlink
  2021-01-21 15:19 [PATCH] xfs: set inode size after creating symlink Jeffrey Mitchell
  2021-01-21 18:41 ` Darrick J. Wong
@ 2021-01-21 19:58 ` Brian Foster
  2021-01-22  8:02 ` Christoph Hellwig
  2 siblings, 0 replies; 5+ messages in thread
From: Brian Foster @ 2021-01-21 19:58 UTC (permalink / raw)
  To: Jeffrey Mitchell; +Cc: Darrick J . Wong, linux-xfs, linux-kernel

On Thu, Jan 21, 2021 at 09:19:12AM -0600, Jeffrey Mitchell wrote:
> When XFS creates a new symlink, it writes its size to disk but not to the
> VFS inode. This causes i_size_read() to return 0 for that symlink until
> it is re-read from disk, for example when the system is rebooted.
> 
> I found this inconsistency while protecting directories with eCryptFS.
> The command "stat path/to/symlink/in/ecryptfs" will report "Size: 0" if
> the symlink was created after the last reboot on an XFS root.
> 
> Call i_size_write() in xfs_symlink()
> 
> Signed-off-by: Jeffrey Mitchell <jeffrey.mitchell@starlab.io>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/xfs_symlink.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c
> index 1f43fd7f3209..c835827ae389 100644
> --- a/fs/xfs/xfs_symlink.c
> +++ b/fs/xfs/xfs_symlink.c
> @@ -300,6 +300,7 @@ xfs_symlink(
>  		}
>  		ASSERT(pathlen == 0);
>  	}
> +	i_size_write(VFS_I(ip), ip->i_d.di_size);
>  
>  	/*
>  	 * Create the directory entry for the symlink.
> -- 
> 2.25.1
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] xfs: set inode size after creating symlink
  2021-01-21 15:19 [PATCH] xfs: set inode size after creating symlink Jeffrey Mitchell
  2021-01-21 18:41 ` Darrick J. Wong
  2021-01-21 19:58 ` Brian Foster
@ 2021-01-22  8:02 ` Christoph Hellwig
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-01-22  8:02 UTC (permalink / raw)
  To: Jeffrey Mitchell; +Cc: Darrick J . Wong, linux-xfs, linux-kernel

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-22  8:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21 15:19 [PATCH] xfs: set inode size after creating symlink Jeffrey Mitchell
2021-01-21 18:41 ` Darrick J. Wong
2021-01-21 19:21   ` Jeffrey Mitchell
2021-01-21 19:58 ` Brian Foster
2021-01-22  8:02 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).