Skip to content

Commit bf6d0f5

Browse files
author
Mimi Zohar
committed
evm: posix acls modify i_mode
The posix xattr acls are 'system' prefixed, which normally would not affect security.evm. An interesting side affect of writing posix xattr acls is their modifying of the i_mode, which is included in security.evm. This patch updates security.evm when posix xattr acls are written. Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
1 parent a924ce0 commit bf6d0f5

5 files changed

Lines changed: 59 additions & 5 deletions

File tree

‎include/linux/evm.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ extern void evm_inode_post_removexattr(struct dentry *dentry,
3333
extern int evm_inode_init_security(struct inode *inode,
3434
const struct xattr *xattr_array,
3535
struct xattr *evm);
36+
#ifdef CONFIG_FS_POSIX_ACL
37+
extern int posix_xattr_acl(const char *xattrname);
38+
#else
39+
static inline int posix_xattr_acl(const char *xattrname)
40+
{
41+
return 0;
42+
}
43+
#endif
3644
#else
3745
#ifdef CONFIG_INTEGRITY
3846
static inline enum integrity_status evm_verifyxattr(struct dentry *dentry,

‎include/linux/xattr.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
#define XATTR_CAPS_SUFFIX "capability"
5353
#define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
5454

55+
#define XATTR_POSIX_ACL_ACCESS "posix_acl_access"
56+
#define XATTR_NAME_POSIX_ACL_ACCESS XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_ACCESS
57+
#define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
58+
#define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
59+
5560
#ifdef __KERNEL__
5661

5762
#include <linux/types.h>

‎security/integrity/evm/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
obj-$(CONFIG_EVM) += evm.o
55

66
evm-y := evm_main.o evm_crypto.o evm_secfs.o
7+
evm-$(CONFIG_FS_POSIX_ACL) += evm_posix_acl.o

‎security/integrity/evm/evm_main.c‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ static enum integrity_status evm_verify_current_integrity(struct dentry *dentry)
177177
/*
178178
* evm_protect_xattr - protect the EVM extended attribute
179179
*
180-
* Prevent security.evm from being modified or removed.
180+
* Prevent security.evm from being modified or removed without the
181+
* necessary permissions or when the existing value is invalid.
182+
*
183+
* The posix xattr acls are 'system' prefixed, which normally would not
184+
* affect security.evm. An interesting side affect of writing posix xattr
185+
* acls is their modifying of the i_mode, which is included in security.evm.
186+
* For posix xattr acls only, permit security.evm, even if it currently
187+
* doesn't exist, to be updated.
181188
*/
182189
static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name,
183190
const void *xattr_value, size_t xattr_value_len)
@@ -187,9 +194,15 @@ static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name,
187194
if (strcmp(xattr_name, XATTR_NAME_EVM) == 0) {
188195
if (!capable(CAP_SYS_ADMIN))
189196
return -EPERM;
190-
} else if (!evm_protected_xattr(xattr_name))
191-
return 0;
192-
197+
} else if (!evm_protected_xattr(xattr_name)) {
198+
if (!posix_xattr_acl(xattr_name))
199+
return 0;
200+
evm_status = evm_verify_current_integrity(dentry);
201+
if ((evm_status == INTEGRITY_PASS) ||
202+
(evm_status == INTEGRITY_NOLABEL))
203+
return 0;
204+
return -EPERM;
205+
}
193206
evm_status = evm_verify_current_integrity(dentry);
194207
return evm_status == INTEGRITY_PASS ? 0 : -EPERM;
195208
}
@@ -240,7 +253,8 @@ int evm_inode_removexattr(struct dentry *dentry, const char *xattr_name)
240253
void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
241254
const void *xattr_value, size_t xattr_value_len)
242255
{
243-
if (!evm_initialized || !evm_protected_xattr(xattr_name))
256+
if (!evm_initialized || (!evm_protected_xattr(xattr_name)
257+
&& !posix_xattr_acl(xattr_name)))
244258
return;
245259

246260
evm_update_evmxattr(dentry, xattr_name, xattr_value, xattr_value_len);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (C) 2011 IBM Corporation
3+
*
4+
* Author:
5+
* Mimi Zohar <zohar@us.ibm.com>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, version 2 of the License.
10+
*/
11+
12+
#include <linux/module.h>
13+
#include <linux/xattr.h>
14+
15+
int posix_xattr_acl(char *xattr)
16+
{
17+
int xattr_len = strlen(xattr);
18+
19+
if ((strlen(XATTR_NAME_POSIX_ACL_ACCESS) == xattr_len)
20+
&& (strncmp(XATTR_NAME_POSIX_ACL_ACCESS, xattr, xattr_len) == 0))
21+
return 1;
22+
if ((strlen(XATTR_NAME_POSIX_ACL_DEFAULT) == xattr_len)
23+
&& (strncmp(XATTR_NAME_POSIX_ACL_DEFAULT, xattr, xattr_len) == 0))
24+
return 1;
25+
return 0;
26+
}

0 commit comments

Comments
 (0)