Re: [PATCH] ecryptfs: Add missing gotos in ecryptfs_read_metadata
Tyler Hicks <[email protected]>
| Newsgroups | org.kernel.vger.ecryptfs,org.kernel.vger.linux-kernel,org.kernel.vger.stable |
|---|---|
| Message-ID | <aWVJyRtk-7Wijd8J@yaupon> |
On 2026-01-11 01:36:52, Thorsten Blum wrote: > Add two missing goto statements to exit ecryptfs_read_metadata() when an > error occurs. > > The first goto is required; otherwise ECRYPTFS_METADATA_IN_XATTR may be > set when xattr metadata is enabled even though parsing the metadata > failed. The second goto is not strictly necessary, but it makes the > error path explicit instead of relying on falling through to 'out'. Hey Thorsten - It seems like there's a bug here but I don't think this is the actual bug. At the top of ecryptfs_read_metadata(), we call ecryptfs_copy_mount_wide_flags_to_inode_flags() to copy the mount-wide crypt_stat flags to the inode's crypt_stat flags. Therefore, the current code is already redundant in setting ECRYPTFS_METADATA_IN_XATTR after ecryptfs_read_headers_virt(). No matter if it succeeds or fails. This logic is confusing but, IIRC, the goal is to handle files with header metadata and files with xattr metadata within the same mount. I think the real bug may be that we're not clearing the inode's ECRYPTFS_METADATA_IN_XATTR flag when the mount crypt stat has the ECRYPTFS_XATTR_METADATA_ENABLED flag set and ecryptfs_read_headers_virt() returns success. I haven't looked at what impact that has elsewhere in the code. However, it has been a long time since I've looked at this code. I'd like your thoughts. Thanks! Tyler > > Cc: [email protected] > Fixes: dd2a3b7ad98f ("[PATCH] eCryptfs: Generalize metadata read/write") > Signed-off-by: Thorsten Blum <[email protected]> > --- > fs/ecryptfs/crypto.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c > index 260f8a4938b0..d49cdf7292ab 100644 > --- a/fs/ecryptfs/crypto.c > +++ b/fs/ecryptfs/crypto.c > @@ -1328,6 +1328,7 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry) > "file xattr region either, inode %lu\n", > ecryptfs_inode->i_ino); > rc = -EINVAL; > + goto out; > } > if (crypt_stat->mount_crypt_stat->flags > & ECRYPTFS_XATTR_METADATA_ENABLED) { > @@ -1340,6 +1341,7 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry) > "this like an encrypted file, inode %lu\n", > ecryptfs_inode->i_ino); > rc = -EINVAL; > + goto out; > } > } > out: > -- > Thorsten Blum <[email protected]> > GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4 >