Skip to content

Commit 6be5cc5

Browse files
Dmitry KasatkinMimi Zohar
authored andcommitted
evm: add support for different security.evm data types
EVM protects a file's security extended attributes(xattrs) against integrity attacks. The current patchset maintains an HMAC-sha1 value across the security xattrs, storing the value as the extended attribute 'security.evm'. We anticipate other methods for protecting the security extended attributes. This patch reserves the first byte of 'security.evm' as a place holder for the type of method. Changelog v6: - move evm_ima_xattr_type definition to security/integrity/integrity.h - defined a structure for the EVM xattr called evm_ima_xattr_data (based on Serge Hallyn's suggestion) - removed unnecessary memset Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@nokia.com> Signed-off-by: Mimi Zohar <zohar@us.ibm.com> Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
1 parent 66dbc32 commit 6be5cc5

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

‎include/linux/integrity.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum integrity_status {
1919
INTEGRITY_UNKNOWN,
2020
};
2121

22+
/* List of EVM protected security xattrs */
2223
#ifdef CONFIG_INTEGRITY
2324
extern int integrity_inode_alloc(struct inode *inode);
2425
extern void integrity_inode_free(struct inode *inode);

‎security/integrity/evm/evm_crypto.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,17 @@ int evm_update_evmxattr(struct dentry *dentry, const char *xattr_name,
141141
const char *xattr_value, size_t xattr_value_len)
142142
{
143143
struct inode *inode = dentry->d_inode;
144-
u8 hmac[SHA1_DIGEST_SIZE];
144+
struct evm_ima_xattr_data xattr_data;
145145
int rc = 0;
146146

147147
rc = evm_calc_hmac(dentry, xattr_name, xattr_value,
148-
xattr_value_len, hmac);
149-
if (rc == 0)
148+
xattr_value_len, xattr_data.digest);
149+
if (rc == 0) {
150+
xattr_data.type = EVM_XATTR_HMAC;
150151
rc = __vfs_setxattr_noperm(dentry, XATTR_NAME_EVM,
151-
hmac, SHA1_DIGEST_SIZE, 0);
152+
&xattr_data,
153+
sizeof(xattr_data), 0);
154+
}
152155
else if (rc == -ENODATA)
153156
rc = inode->i_op->removexattr(dentry, XATTR_NAME_EVM);
154157
return rc;

‎security/integrity/evm/evm_main.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,
5151
size_t xattr_value_len,
5252
struct integrity_iint_cache *iint)
5353
{
54-
char hmac_val[SHA1_DIGEST_SIZE];
54+
struct evm_ima_xattr_data xattr_data;
5555
int rc;
5656

5757
if (iint->hmac_status != INTEGRITY_UNKNOWN)
5858
return iint->hmac_status;
5959

60-
memset(hmac_val, 0, sizeof hmac_val);
6160
rc = evm_calc_hmac(dentry, xattr_name, xattr_value,
62-
xattr_value_len, hmac_val);
61+
xattr_value_len, xattr_data.digest);
6362
if (rc < 0)
6463
return INTEGRITY_UNKNOWN;
6564

66-
rc = vfs_xattr_cmp(dentry, XATTR_NAME_EVM, hmac_val, sizeof hmac_val,
67-
GFP_NOFS);
65+
xattr_data.type = EVM_XATTR_HMAC;
66+
rc = vfs_xattr_cmp(dentry, XATTR_NAME_EVM, (u8 *)&xattr_data,
67+
sizeof xattr_data, GFP_NOFS);
6868
if (rc < 0)
6969
goto err_out;
7070
iint->hmac_status = INTEGRITY_PASS;

‎security/integrity/integrity.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
/* iint cache flags */
1919
#define IMA_MEASURED 0x01
2020

21+
enum evm_ima_xattr_type {
22+
IMA_XATTR_DIGEST = 0x01,
23+
EVM_XATTR_HMAC,
24+
EVM_IMA_XATTR_DIGSIG,
25+
};
26+
27+
struct evm_ima_xattr_data {
28+
u8 type;
29+
u8 digest[SHA1_DIGEST_SIZE];
30+
} __attribute__((packed));
31+
2132
/* integrity data associated with an inode */
2233
struct integrity_iint_cache {
2334
struct rb_node rb_node; /* rooted in integrity_iint_tree */

0 commit comments

Comments
 (0)