Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c51bb00 authored by Dmitry Kasatkin's avatar Dmitry Kasatkin Committed by Mimi Zohar
Browse files

evm: fix potential race when removing xattrs



EVM needs to be atomically updated when removing xattrs.
Otherwise concurrent EVM verification may fail in between.
This patch fixes by moving i_mutex unlocking after calling
EVM hook. fsnotify_xattr() is also now called while locked
the same way as it is done in __vfs_setxattr_noperm.

Changelog:
- remove unused 'inode' variable.

Signed-off-by: default avatarDmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
parent 5101a185
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -298,18 +298,18 @@ vfs_removexattr(struct dentry *dentry, const char *name)


	mutex_lock(&inode->i_mutex);
	mutex_lock(&inode->i_mutex);
	error = security_inode_removexattr(dentry, name);
	error = security_inode_removexattr(dentry, name);
	if (error) {
	if (error)
		mutex_unlock(&inode->i_mutex);
		goto out;
		return error;
	}


	error = inode->i_op->removexattr(dentry, name);
	error = inode->i_op->removexattr(dentry, name);
	mutex_unlock(&inode->i_mutex);


	if (!error) {
	if (!error) {
		fsnotify_xattr(dentry);
		fsnotify_xattr(dentry);
		evm_inode_post_removexattr(dentry, name);
		evm_inode_post_removexattr(dentry, name);
	}
	}

out:
	mutex_unlock(&inode->i_mutex);
	return error;
	return error;
}
}
EXPORT_SYMBOL_GPL(vfs_removexattr);
EXPORT_SYMBOL_GPL(vfs_removexattr);
+3 −4
Original line number Original line Diff line number Diff line
@@ -387,17 +387,16 @@ void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
 * @xattr_name: pointer to the affected extended attribute name
 * @xattr_name: pointer to the affected extended attribute name
 *
 *
 * Update the HMAC stored in 'security.evm' to reflect removal of the xattr.
 * Update the HMAC stored in 'security.evm' to reflect removal of the xattr.
 *
 * No need to take the i_mutex lock here, as this function is called from
 * vfs_removexattr() which takes the i_mutex.
 */
 */
void evm_inode_post_removexattr(struct dentry *dentry, const char *xattr_name)
void evm_inode_post_removexattr(struct dentry *dentry, const char *xattr_name)
{
{
	struct inode *inode = d_backing_inode(dentry);

	if (!evm_initialized || !evm_protected_xattr(xattr_name))
	if (!evm_initialized || !evm_protected_xattr(xattr_name))
		return;
		return;


	mutex_lock(&inode->i_mutex);
	evm_update_evmxattr(dentry, xattr_name, NULL, 0);
	evm_update_evmxattr(dentry, xattr_name, NULL, 0);
	mutex_unlock(&inode->i_mutex);
}
}


/**
/**