Skip to content

Commit db1d1e8

Browse files
jtlaytonmimizohar
authored andcommitted
IMA: use vfs_getattr_nosec to get the i_version
IMA currently accesses the i_version out of the inode directly when it does a measurement. This is fine for most simple filesystems, but can be problematic with more complex setups (e.g. overlayfs). Make IMA instead call vfs_getattr_nosec to get this info. This allows the filesystem to determine whether and how to report the i_version, and should allow IMA to work properly with a broader class of filesystems in the future. Reported-and-Tested-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent f1fcbaa commit db1d1e8

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

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)

0 commit comments

Comments
 (0)