Skip to content

Commit 7e135dc

Browse files
robertosassumimizohar
authored andcommitted
evm: Pass user namespace to set/remove xattr hooks
In preparation for 'evm: Allow setxattr() and setattr() for unmodified metadata', this patch passes mnt_userns to the inode set/remove xattr hooks so that the GID of the inode on an idmapped mount is correctly determined by posix_acl_update_mode(). Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com> Cc: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent cdef685 commit 7e135dc

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

include/linux/evm.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ extern enum integrity_status evm_verifyxattr(struct dentry *dentry,
2323
struct integrity_iint_cache *iint);
2424
extern int evm_inode_setattr(struct dentry *dentry, struct iattr *attr);
2525
extern void evm_inode_post_setattr(struct dentry *dentry, int ia_valid);
26-
extern int evm_inode_setxattr(struct dentry *dentry, const char *name,
26+
extern int evm_inode_setxattr(struct user_namespace *mnt_userns,
27+
struct dentry *dentry, const char *name,
2728
const void *value, size_t size);
2829
extern void evm_inode_post_setxattr(struct dentry *dentry,
2930
const char *xattr_name,
3031
const void *xattr_value,
3132
size_t xattr_value_len);
32-
extern int evm_inode_removexattr(struct dentry *dentry, const char *xattr_name);
33+
extern int evm_inode_removexattr(struct user_namespace *mnt_userns,
34+
struct dentry *dentry, const char *xattr_name);
3335
extern void evm_inode_post_removexattr(struct dentry *dentry,
3436
const char *xattr_name);
3537
extern int evm_inode_init_security(struct inode *inode,
@@ -72,7 +74,8 @@ static inline void evm_inode_post_setattr(struct dentry *dentry, int ia_valid)
7274
return;
7375
}
7476

75-
static inline int evm_inode_setxattr(struct dentry *dentry, const char *name,
77+
static inline int evm_inode_setxattr(struct user_namespace *mnt_userns,
78+
struct dentry *dentry, const char *name,
7679
const void *value, size_t size)
7780
{
7881
return 0;
@@ -86,7 +89,8 @@ static inline void evm_inode_post_setxattr(struct dentry *dentry,
8689
return;
8790
}
8891

89-
static inline int evm_inode_removexattr(struct dentry *dentry,
92+
static inline int evm_inode_removexattr(struct user_namespace *mnt_userns,
93+
struct dentry *dentry,
9094
const char *xattr_name)
9195
{
9296
return 0;

security/integrity/evm/evm_main.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ static enum integrity_status evm_verify_current_integrity(struct dentry *dentry)
342342
* For posix xattr acls only, permit security.evm, even if it currently
343343
* doesn't exist, to be updated unless the EVM signature is immutable.
344344
*/
345-
static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name,
345+
static int evm_protect_xattr(struct user_namespace *mnt_userns,
346+
struct dentry *dentry, const char *xattr_name,
346347
const void *xattr_value, size_t xattr_value_len)
347348
{
348349
enum integrity_status evm_status;
@@ -406,6 +407,7 @@ static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name,
406407

407408
/**
408409
* evm_inode_setxattr - protect the EVM extended attribute
410+
* @mnt_userns: user namespace of the idmapped mount
409411
* @dentry: pointer to the affected dentry
410412
* @xattr_name: pointer to the affected extended attribute name
411413
* @xattr_value: pointer to the new extended attribute value
@@ -417,8 +419,9 @@ static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name,
417419
* userspace from writing HMAC value. Writing 'security.evm' requires
418420
* requires CAP_SYS_ADMIN privileges.
419421
*/
420-
int evm_inode_setxattr(struct dentry *dentry, const char *xattr_name,
421-
const void *xattr_value, size_t xattr_value_len)
422+
int evm_inode_setxattr(struct user_namespace *mnt_userns, struct dentry *dentry,
423+
const char *xattr_name, const void *xattr_value,
424+
size_t xattr_value_len)
422425
{
423426
const struct evm_ima_xattr_data *xattr_data = xattr_value;
424427

@@ -435,27 +438,29 @@ int evm_inode_setxattr(struct dentry *dentry, const char *xattr_name,
435438
xattr_data->type != EVM_XATTR_PORTABLE_DIGSIG)
436439
return -EPERM;
437440
}
438-
return evm_protect_xattr(dentry, xattr_name, xattr_value,
441+
return evm_protect_xattr(mnt_userns, dentry, xattr_name, xattr_value,
439442
xattr_value_len);
440443
}
441444

442445
/**
443446
* evm_inode_removexattr - protect the EVM extended attribute
447+
* @mnt_userns: user namespace of the idmapped mount
444448
* @dentry: pointer to the affected dentry
445449
* @xattr_name: pointer to the affected extended attribute name
446450
*
447451
* Removing 'security.evm' requires CAP_SYS_ADMIN privileges and that
448452
* the current value is valid.
449453
*/
450-
int evm_inode_removexattr(struct dentry *dentry, const char *xattr_name)
454+
int evm_inode_removexattr(struct user_namespace *mnt_userns,
455+
struct dentry *dentry, const char *xattr_name)
451456
{
452457
/* Policy permits modification of the protected xattrs even though
453458
* there's no HMAC key loaded
454459
*/
455460
if (evm_initialized & EVM_ALLOW_METADATA_WRITES)
456461
return 0;
457462

458-
return evm_protect_xattr(dentry, xattr_name, NULL, 0);
463+
return evm_protect_xattr(mnt_userns, dentry, xattr_name, NULL, 0);
459464
}
460465

461466
static void evm_reset_status(struct inode *inode)

security/security.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ int security_inode_setxattr(struct user_namespace *mnt_userns,
13541354
ret = ima_inode_setxattr(dentry, name, value, size);
13551355
if (ret)
13561356
return ret;
1357-
return evm_inode_setxattr(dentry, name, value, size);
1357+
return evm_inode_setxattr(mnt_userns, dentry, name, value, size);
13581358
}
13591359

13601360
void security_inode_post_setxattr(struct dentry *dentry, const char *name,
@@ -1399,7 +1399,7 @@ int security_inode_removexattr(struct user_namespace *mnt_userns,
13991399
ret = ima_inode_removexattr(dentry, name);
14001400
if (ret)
14011401
return ret;
1402-
return evm_inode_removexattr(dentry, name);
1402+
return evm_inode_removexattr(mnt_userns, dentry, name);
14031403
}
14041404

14051405
int security_inode_need_killpriv(struct dentry *dentry)

0 commit comments

Comments
 (0)