Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <lkp@intel.com>
Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
Acked-by: Paul E. McKenney <paulmck@kernel.org> (RCU viewpoint)
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>

authored by

Madhuparna Bhowmik and committed by
Mimi Zohar
770f6058 2e3a34e9

+11 -4
+1 -1
security/integrity/evm/evm_crypto.c
··· 207 207 data->hdr.length = crypto_shash_digestsize(desc->tfm); 208 208 209 209 error = -ENODATA; 210 - list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) { 210 + list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) { 211 211 bool is_ima = false; 212 212 213 213 if (strcmp(xattr->name, XATTR_NAME_IMA) == 0)
+2 -2
security/integrity/evm/evm_main.c
··· 97 97 if (!(inode->i_opflags & IOP_XATTR)) 98 98 return -EOPNOTSUPP; 99 99 100 - list_for_each_entry_rcu(xattr, &evm_config_xattrnames, list) { 100 + list_for_each_entry_lockless(xattr, &evm_config_xattrnames, list) { 101 101 error = __vfs_getxattr(dentry, inode, xattr->name, NULL, 0); 102 102 if (error < 0) { 103 103 if (error == -ENODATA) ··· 228 228 struct xattr_list *xattr; 229 229 230 230 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) { 232 232 if ((strlen(xattr->name) == namelen) 233 233 && (strncmp(req_xattr_name, xattr->name, namelen) == 0)) { 234 234 found = 1;
+8 -1
security/integrity/evm/evm_secfs.c
··· 232 232 goto out; 233 233 } 234 234 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 + */ 236 243 mutex_lock(&xattr_list_mutex); 237 244 list_for_each_entry(tmp, &evm_config_xattrnames, list) { 238 245 if (strcmp(xattr->name, tmp->name) == 0) {