Skip to content

Commit 770f605

Browse files
Madhuparna Bhowmikmimizohar
authored andcommitted
evm: Fix RCU list related warnings
This patch fixes the following warning and few other instances of traversal of evm_config_xattrnames list: [ 32.848432] ============================= [ 32.848707] WARNING: suspicious RCU usage [ 32.848966] 5.7.0-rc1-00006-ga8d5875ce5f0b #1 Not tainted [ 32.849308] ----------------------------- [ 32.849567] security/integrity/evm/evm_main.c:231 RCU-list traversed in non-reader section!! Since entries are only added to the list and never deleted, use list_for_each_entry_lockless() instead of list_for_each_entry_rcu for traversing the list. Also, add a relevant comment in evm_secfs.c to indicate this fact. Reported-by: kernel test robot <[email protected]> Suggested-by: Paul E. McKenney <[email protected]> Signed-off-by: Madhuparna Bhowmik <[email protected]> Acked-by: Paul E. McKenney <[email protected]> (RCU viewpoint) Signed-off-by: Mimi Zohar <[email protected]>
1 parent 2e3a34e commit 770f605

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

security/integrity/evm/evm_crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
207207
data->hdr.length = crypto_shash_digestsize(desc->tfm);
208208

209209
error = -ENODATA;
210-
list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) {
210+
list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) {
211211
bool is_ima = false;
212212

213213
if (strcmp(xattr->name, XATTR_NAME_IMA) == 0)

security/integrity/evm/evm_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int evm_find_protected_xattrs(struct dentry *dentry)
9797
if (!(inode->i_opflags & IOP_XATTR))
9898
return -EOPNOTSUPP;
9999

100-
list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) {
100+
list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) {
101101
error = __vfs_getxattr(dentry, inode, xattr->name, NULL, 0);
102102
if (error < 0) {
103103
if (error == -ENODATA)
@@ -228,7 +228,7 @@ static int evm_protected_xattr(const char *req_xattr_name)
228228
struct xattr_list *xattr;
229229

230230
namelen = strlen(req_xattr_name);
231-
list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) {
231+
list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) {
232232
if ((strlen(xattr->name) == namelen)
233233
&& (strncmp(req_xattr_name, xattr->name, namelen) == 0)) {
234234
found = 1;

security/integrity/evm/evm_secfs.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,14 @@ static ssize_t evm_write_xattrs(struct file *file, const char __user *buf,
232232
goto out;
233233
}
234234

235-
/* Guard against races in evm_read_xattrs */
235+
/*
236+
* xattr_list_mutex guards against races in evm_read_xattrs().
237+
* Entries are only added to the evm_config_xattrnames list
238+
* and never deleted. Therefore, the list is traversed
239+
* using list_for_each_entry_lockless() without holding
240+
* the mutex in evm_calc_hmac_or_hash(), evm_find_protected_xattrs()
241+
* and evm_protected_xattr().
242+
*/
236243
mutex_lock(&xattr_list_mutex);
237244
list_for_each_entry(tmp, &evm_config_xattrnames, list) {
238245
if (strcmp(xattr->name, tmp->name) == 0) {

0 commit comments

Comments
 (0)