Skip to content

Commit 5d1f0e8

Browse files
Christoph Hellwigtyhicks
authored andcommitted
ecryptfs: factor out a ecryptfs_iattr_to_lower helper
Prepare for using the code to create a lower struct iattr in multiple places. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Tyler Hicks <[email protected]>
1 parent 081447e commit 5d1f0e8

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

fs/ecryptfs/inode.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,20 @@ static const char *ecryptfs_get_link(struct dentry *dentry,
677677
return buf;
678678
}
679679

680+
static void ecryptfs_iattr_to_lower(struct iattr *lower_ia,
681+
const struct iattr *ia)
682+
{
683+
memcpy(lower_ia, ia, sizeof(*lower_ia));
684+
if (ia->ia_valid & ATTR_FILE)
685+
lower_ia->ia_file = ecryptfs_file_to_lower(ia->ia_file);
686+
/*
687+
* If the mode change is for clearing setuid/setgid bits, allow the lower
688+
* file system to interpret this in its own way.
689+
*/
690+
if (lower_ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
691+
lower_ia->ia_valid &= ~ATTR_MODE;
692+
}
693+
680694
/**
681695
* upper_size_to_lower_size
682696
* @crypt_stat: Crypt_stat associated with file
@@ -921,21 +935,13 @@ static int ecryptfs_setattr(struct mnt_idmap *idmap,
921935
if (rc)
922936
goto out;
923937

924-
memcpy(&lower_ia, ia, sizeof(lower_ia));
925-
if (ia->ia_valid & ATTR_FILE)
926-
lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file);
938+
ecryptfs_iattr_to_lower(&lower_ia, ia);
927939
if (ia->ia_valid & ATTR_SIZE) {
928940
rc = truncate_upper(dentry, ia, &lower_ia);
929941
if (rc < 0)
930942
goto out;
931943
}
932944

933-
/*
934-
* mode change is for clearing setuid/setgid bits. Allow lower fs
935-
* to interpret this in its own way.
936-
*/
937-
if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
938-
lower_ia.ia_valid &= ~ATTR_MODE;
939945

940946
inode_lock(d_inode(lower_dentry));
941947
rc = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia, NULL);

0 commit comments

Comments
 (0)