Skip to content

Commit b4c7f2e

Browse files
committed
Merge tag 'integrity-v6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity
Pull integrity subsystem updates from Mimi Zohar: "An i_version change, one bug fix, and three kernel doc fixes: - instead of IMA detecting file change by directly accesssing i_version, it now calls vfs_getattr_nosec(). - fix a race condition when inserting a new node in the iint rb-tree" * tag 'integrity-v6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity: ima: Fix build warnings evm: Fix build warnings evm: Complete description of evm_inode_setattr() integrity: Fix possible multiple allocation in integrity_inode_get() IMA: use vfs_getattr_nosec to get the i_version
2 parents 21953eb + 95526d1 commit b4c7f2e

7 files changed

Lines changed: 32 additions & 16 deletions

File tree

security/integrity/evm/evm_crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static const char evm_hmac[] = "hmac(sha1)";
4040
/**
4141
* evm_set_key() - set EVM HMAC key from the kernel
4242
* @key: pointer to a buffer with the key data
43-
* @size: length of the key data
43+
* @keylen: length of the key data
4444
*
4545
* This function allows setting the EVM HMAC key from the kernel
4646
* without using the "encrypted" key subsystem keys. It can be used

security/integrity/evm/evm_main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ int evm_protected_xattr_if_enabled(const char *req_xattr_name)
318318
/**
319319
* evm_read_protected_xattrs - read EVM protected xattr names, lengths, values
320320
* @dentry: dentry of the read xattrs
321-
* @inode: inode of the read xattrs
322321
* @buffer: buffer xattr names, lengths or values are copied to
323322
* @buffer_size: size of buffer
324323
* @type: n: names, l: lengths, v: values
@@ -390,6 +389,7 @@ int evm_read_protected_xattrs(struct dentry *dentry, u8 *buffer,
390389
* @xattr_name: requested xattr
391390
* @xattr_value: requested xattr value
392391
* @xattr_value_len: requested xattr value length
392+
* @iint: inode integrity metadata
393393
*
394394
* Calculate the HMAC for the given dentry and verify it against the stored
395395
* security.evm xattr. For performance, use the xattr value and length
@@ -795,7 +795,9 @@ static int evm_attr_change(struct mnt_idmap *idmap,
795795

796796
/**
797797
* evm_inode_setattr - prevent updating an invalid EVM extended attribute
798+
* @idmap: idmap of the mount
798799
* @dentry: pointer to the affected dentry
800+
* @attr: iattr structure containing the new file attributes
799801
*
800802
* Permit update of file attributes when files have a valid EVM signature,
801803
* except in the case of them having an immutable portable signature.

security/integrity/iint.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ static struct integrity_iint_cache *__integrity_iint_find(struct inode *inode)
4343
else if (inode > iint->inode)
4444
n = n->rb_right;
4545
else
46-
break;
46+
return iint;
4747
}
48-
if (!n)
49-
return NULL;
5048

51-
return iint;
49+
return NULL;
5250
}
5351

5452
/*
@@ -113,10 +111,15 @@ struct integrity_iint_cache *integrity_inode_get(struct inode *inode)
113111
parent = *p;
114112
test_iint = rb_entry(parent, struct integrity_iint_cache,
115113
rb_node);
116-
if (inode < test_iint->inode)
114+
if (inode < test_iint->inode) {
117115
p = &(*p)->rb_left;
118-
else
116+
} else if (inode > test_iint->inode) {
119117
p = &(*p)->rb_right;
118+
} else {
119+
write_unlock(&integrity_iint_lock);
120+
kmem_cache_free(iint_cache, iint);
121+
return test_iint;
122+
}
120123
}
121124

122125
iint->inode = inode;

security/integrity/ima/ima_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <linux/fs.h>
1414
#include <linux/xattr.h>
1515
#include <linux/evm.h>
16-
#include <linux/iversion.h>
1716
#include <linux/fsverity.h>
1817

1918
#include "ima.h"
@@ -246,10 +245,11 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
246245
struct inode *inode = file_inode(file);
247246
const char *filename = file->f_path.dentry->d_name.name;
248247
struct ima_max_digest_data hash;
248+
struct kstat stat;
249249
int result = 0;
250250
int length;
251251
void *tmpbuf;
252-
u64 i_version;
252+
u64 i_version = 0;
253253

254254
/*
255255
* Always collect the modsig, because IMA might have already collected
@@ -268,7 +268,10 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
268268
* to an initial measurement/appraisal/audit, but was modified to
269269
* assume the file changed.
270270
*/
271-
i_version = inode_query_iversion(inode);
271+
result = vfs_getattr_nosec(&file->f_path, &stat, STATX_CHANGE_COOKIE,
272+
AT_STATX_SYNC_AS_STAT);
273+
if (!result && (stat.result_mask & STATX_CHANGE_COOKIE))
274+
i_version = stat.change_cookie;
272275
hash.hdr.algo = algo;
273276
hash.hdr.length = hash_digest_size[algo];
274277

security/integrity/ima/ima_main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <linux/slab.h>
2525
#include <linux/xattr.h>
2626
#include <linux/ima.h>
27-
#include <linux/iversion.h>
2827
#include <linux/fs.h>
2928

3029
#include "ima.h"
@@ -164,11 +163,16 @@ static void ima_check_last_writer(struct integrity_iint_cache *iint,
164163

165164
mutex_lock(&iint->mutex);
166165
if (atomic_read(&inode->i_writecount) == 1) {
166+
struct kstat stat;
167+
167168
update = test_and_clear_bit(IMA_UPDATE_XATTR,
168169
&iint->atomic_flags);
169-
if (!IS_I_VERSION(inode) ||
170-
!inode_eq_iversion(inode, iint->version) ||
171-
(iint->flags & IMA_NEW_FILE)) {
170+
if ((iint->flags & IMA_NEW_FILE) ||
171+
vfs_getattr_nosec(&file->f_path, &stat,
172+
STATX_CHANGE_COOKIE,
173+
AT_STATX_SYNC_AS_STAT) ||
174+
!(stat.result_mask & STATX_CHANGE_COOKIE) ||
175+
stat.change_cookie != iint->version) {
172176
iint->flags &= ~(IMA_DONE_MASK | IMA_NEW_FILE);
173177
iint->measured_pcrs = 0;
174178
if (update)

security/integrity/ima/ima_modsig.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ int ima_read_modsig(enum ima_hooks func, const void *buf, loff_t buf_len,
8989

9090
/**
9191
* ima_collect_modsig - Calculate the file hash without the appended signature.
92+
* @modsig: parsed module signature
93+
* @buf: data to verify the signature on
94+
* @size: data size
9295
*
9396
* Since the modsig is part of the file contents, the hash used in its signature
9497
* isn't the same one ordinarily calculated by IMA. Therefore PKCS7 code

security/integrity/ima/ima_policy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ static int get_subaction(struct ima_rule_entry *rule, enum ima_hooks func)
721721
* @secid: LSM secid of the task to be validated
722722
* @func: IMA hook identifier
723723
* @mask: requested action (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
724+
* @flags: IMA actions to consider (e.g. IMA_MEASURE | IMA_APPRAISE)
724725
* @pcr: set the pcr to extend
725726
* @template_desc: the template that should be used for this rule
726727
* @func_data: func specific data, may be NULL
@@ -1915,7 +1916,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
19151916

19161917
/**
19171918
* ima_parse_add_rule - add a rule to ima_policy_rules
1918-
* @rule - ima measurement policy rule
1919+
* @rule: ima measurement policy rule
19191920
*
19201921
* Avoid locking by allowing just one writer at a time in ima_write_policy()
19211922
* Returns the length of the rule parsed, an error code on failure

0 commit comments

Comments
 (0)