Skip to content

Commit 4b899da

Browse files
agruenbaAl Viro
authored andcommitted
ecryptfs: Switch to generic xattr handlers
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent bba0bd3 commit 4b899da

3 files changed

Lines changed: 51 additions & 14 deletions

File tree

‎fs/ecryptfs/ecryptfs_kernel.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,4 +715,6 @@ int ecryptfs_set_f_namelen(long *namelen, long lower_namelen,
715715
int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat,
716716
loff_t offset);
717717

718+
extern const struct xattr_handler *ecryptfs_xattr_handlers[];
719+
718720
#endif /* #ifndef ECRYPTFS_KERNEL_H */

‎fs/ecryptfs/inode.c‎

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,19 +1066,22 @@ ecryptfs_listxattr(struct dentry *dentry, char *list, size_t size)
10661066
return rc;
10671067
}
10681068

1069-
static int ecryptfs_removexattr(struct dentry *dentry, const char *name)
1069+
static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode,
1070+
const char *name)
10701071
{
10711072
int rc = 0;
10721073
struct dentry *lower_dentry;
1074+
struct inode *lower_inode;
10731075

10741076
lower_dentry = ecryptfs_dentry_to_lower(dentry);
1075-
if (!d_inode(lower_dentry)->i_op->removexattr) {
1077+
lower_inode = ecryptfs_inode_to_lower(inode);
1078+
if (!lower_inode->i_op->removexattr) {
10761079
rc = -EOPNOTSUPP;
10771080
goto out;
10781081
}
1079-
inode_lock(d_inode(lower_dentry));
1080-
rc = d_inode(lower_dentry)->i_op->removexattr(lower_dentry, name);
1081-
inode_unlock(d_inode(lower_dentry));
1082+
inode_lock(lower_inode);
1083+
rc = lower_inode->i_op->removexattr(lower_dentry, name);
1084+
inode_unlock(lower_inode);
10821085
out:
10831086
return rc;
10841087
}
@@ -1089,10 +1092,10 @@ const struct inode_operations ecryptfs_symlink_iops = {
10891092
.permission = ecryptfs_permission,
10901093
.setattr = ecryptfs_setattr,
10911094
.getattr = ecryptfs_getattr_link,
1092-
.setxattr = ecryptfs_setxattr,
1093-
.getxattr = ecryptfs_getxattr,
1095+
.setxattr = generic_setxattr,
1096+
.getxattr = generic_getxattr,
10941097
.listxattr = ecryptfs_listxattr,
1095-
.removexattr = ecryptfs_removexattr
1098+
.removexattr = generic_removexattr
10961099
};
10971100

10981101
const struct inode_operations ecryptfs_dir_iops = {
@@ -1107,18 +1110,49 @@ const struct inode_operations ecryptfs_dir_iops = {
11071110
.rename = ecryptfs_rename,
11081111
.permission = ecryptfs_permission,
11091112
.setattr = ecryptfs_setattr,
1110-
.setxattr = ecryptfs_setxattr,
1111-
.getxattr = ecryptfs_getxattr,
1113+
.setxattr = generic_setxattr,
1114+
.getxattr = generic_getxattr,
11121115
.listxattr = ecryptfs_listxattr,
1113-
.removexattr = ecryptfs_removexattr
1116+
.removexattr = generic_removexattr
11141117
};
11151118

11161119
const struct inode_operations ecryptfs_main_iops = {
11171120
.permission = ecryptfs_permission,
11181121
.setattr = ecryptfs_setattr,
11191122
.getattr = ecryptfs_getattr,
1120-
.setxattr = ecryptfs_setxattr,
1121-
.getxattr = ecryptfs_getxattr,
1123+
.setxattr = generic_setxattr,
1124+
.getxattr = generic_getxattr,
11221125
.listxattr = ecryptfs_listxattr,
1123-
.removexattr = ecryptfs_removexattr
1126+
.removexattr = generic_removexattr
1127+
};
1128+
1129+
static int ecryptfs_xattr_get(const struct xattr_handler *handler,
1130+
struct dentry *dentry, struct inode *inode,
1131+
const char *name, void *buffer, size_t size)
1132+
{
1133+
return ecryptfs_getxattr(dentry, inode, name, buffer, size);
1134+
}
1135+
1136+
static int ecryptfs_xattr_set(const struct xattr_handler *handler,
1137+
struct dentry *dentry, struct inode *inode,
1138+
const char *name, const void *value, size_t size,
1139+
int flags)
1140+
{
1141+
if (value)
1142+
return ecryptfs_setxattr(dentry, inode, name, value, size, flags);
1143+
else {
1144+
BUG_ON(flags != XATTR_REPLACE);
1145+
return ecryptfs_removexattr(dentry, inode, name);
1146+
}
1147+
}
1148+
1149+
const struct xattr_handler ecryptfs_xattr_handler = {
1150+
.prefix = "", /* match anything */
1151+
.get = ecryptfs_xattr_get,
1152+
.set = ecryptfs_xattr_set,
1153+
};
1154+
1155+
const struct xattr_handler *ecryptfs_xattr_handlers[] = {
1156+
&ecryptfs_xattr_handler,
1157+
NULL
11241158
};

‎fs/ecryptfs/main.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
529529
/* ->kill_sb() will take care of sbi after that point */
530530
sbi = NULL;
531531
s->s_op = &ecryptfs_sops;
532+
s->s_xattr = ecryptfs_xattr_handlers;
532533
s->s_d_op = &ecryptfs_dops;
533534

534535
err = "Reading sb failed";

0 commit comments

Comments
 (0)