Skip to content

Commit b65a9cf

Browse files
author
Al Viro
committed
Untangling ima mess, part 2: deal with counters
* do ima_get_count() in __dentry_open() * stop doing that in followups * move ima_path_check() to right after nameidata_to_filp() * don't bump counters on it Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 0552f87 commit b65a9cf

6 files changed

Lines changed: 28 additions & 43 deletions

File tree

‎fs/cachefiles/rdwr.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <linux/mount.h>
1313
#include <linux/file.h>
14-
#include <linux/ima.h>
1514
#include "internal.h"
1615

1716
/*
@@ -923,7 +922,6 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
923922
if (IS_ERR(file)) {
924923
ret = PTR_ERR(file);
925924
} else {
926-
ima_counts_get(file);
927925
ret = -EIO;
928926
if (file->f_op->write) {
929927
pos = (loff_t) page->index << PAGE_SHIFT;

‎fs/ecryptfs/main.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <linux/key.h>
3636
#include <linux/parser.h>
3737
#include <linux/fs_stack.h>
38-
#include <linux/ima.h>
3938
#include "ecryptfs_kernel.h"
4039

4140
/**
@@ -119,7 +118,6 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
119118
const struct cred *cred = current_cred();
120119
struct ecryptfs_inode_info *inode_info =
121120
ecryptfs_inode_to_private(ecryptfs_dentry->d_inode);
122-
int opened_lower_file = 0;
123121
int rc = 0;
124122

125123
mutex_lock(&inode_info->lower_file_mutex);
@@ -136,12 +134,9 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
136134
"for lower_dentry [0x%p] and lower_mnt [0x%p]; "
137135
"rc = [%d]\n", lower_dentry, lower_mnt, rc);
138136
inode_info->lower_file = NULL;
139-
} else
140-
opened_lower_file = 1;
137+
}
141138
}
142139
mutex_unlock(&inode_info->lower_file_mutex);
143-
if (opened_lower_file)
144-
ima_counts_get(inode_info->lower_file);
145140
return rc;
146141
}
147142

‎fs/namei.c‎

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,14 +1461,7 @@ int may_open(struct path *path, int acc_mode, int flag)
14611461
/*
14621462
* Ensure there are no outstanding leases on the file.
14631463
*/
1464-
error = break_lease(inode, flag);
1465-
if (error)
1466-
return error;
1467-
1468-
return ima_path_check(path, acc_mode ?
1469-
acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC) :
1470-
ACC_MODE(flag) & (MAY_READ | MAY_WRITE),
1471-
IMA_COUNT_UPDATE);
1464+
return break_lease(inode, flag);
14721465
}
14731466

14741467
static int handle_truncate(struct path *path)
@@ -1688,13 +1681,17 @@ struct file *do_filp_open(int dfd, const char *pathname,
16881681
goto exit;
16891682
}
16901683
filp = nameidata_to_filp(&nd, open_flag);
1691-
if (IS_ERR(filp))
1692-
ima_counts_put(&nd.path,
1693-
acc_mode & (MAY_READ | MAY_WRITE |
1694-
MAY_EXEC));
16951684
mnt_drop_write(nd.path.mnt);
16961685
if (nd.root.mnt)
16971686
path_put(&nd.root);
1687+
if (!IS_ERR(filp)) {
1688+
error = ima_path_check(&filp->f_path, filp->f_mode &
1689+
(MAY_READ | MAY_WRITE | MAY_EXEC), 0);
1690+
if (error) {
1691+
fput(filp);
1692+
filp = ERR_PTR(error);
1693+
}
1694+
}
16981695
return filp;
16991696
}
17001697

@@ -1748,27 +1745,24 @@ struct file *do_filp_open(int dfd, const char *pathname,
17481745
goto exit;
17491746
}
17501747
filp = nameidata_to_filp(&nd, open_flag);
1751-
if (IS_ERR(filp)) {
1752-
ima_counts_put(&nd.path,
1753-
acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC));
1754-
if (will_truncate)
1755-
mnt_drop_write(nd.path.mnt);
1756-
if (nd.root.mnt)
1757-
path_put(&nd.root);
1758-
return filp;
1759-
}
1760-
1761-
if (acc_mode & MAY_WRITE)
1762-
vfs_dq_init(nd.path.dentry->d_inode);
1763-
1764-
if (will_truncate) {
1765-
error = handle_truncate(&nd.path);
1748+
if (!IS_ERR(filp)) {
1749+
error = ima_path_check(&filp->f_path, filp->f_mode &
1750+
(MAY_READ | MAY_WRITE | MAY_EXEC), 0);
17661751
if (error) {
1767-
mnt_drop_write(nd.path.mnt);
17681752
fput(filp);
1769-
if (nd.root.mnt)
1770-
path_put(&nd.root);
1771-
return ERR_PTR(error);
1753+
filp = ERR_PTR(error);
1754+
}
1755+
}
1756+
if (!IS_ERR(filp)) {
1757+
if (acc_mode & MAY_WRITE)
1758+
vfs_dq_init(nd.path.dentry->d_inode);
1759+
1760+
if (will_truncate) {
1761+
error = handle_truncate(&nd.path);
1762+
if (error) {
1763+
fput(filp);
1764+
filp = ERR_PTR(error);
1765+
}
17721766
}
17731767
}
17741768
/*

‎fs/nfsd/vfs.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,6 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
744744
flags, current_cred());
745745
if (IS_ERR(*filp))
746746
host_err = PTR_ERR(*filp);
747-
else
748-
ima_counts_get(*filp);
749747
out_nfserr:
750748
err = nfserrno(host_err);
751749
out:

‎fs/open.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/audit.h>
3131
#include <linux/falloc.h>
3232
#include <linux/fs_struct.h>
33+
#include <linux/ima.h>
3334

3435
#include "internal.h"
3536

@@ -857,6 +858,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
857858
if (error)
858859
goto cleanup_all;
859860
}
861+
ima_counts_get(f);
860862

861863
f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
862864

‎ipc/mqueue.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <linux/nsproxy.h>
3333
#include <linux/pid.h>
3434
#include <linux/ipc_namespace.h>
35-
#include <linux/ima.h>
3635

3736
#include <net/sock.h>
3837
#include "util.h"
@@ -734,7 +733,6 @@ SYSCALL_DEFINE4(mq_open, const char __user *, u_name, int, oflag, mode_t, mode,
734733
error = PTR_ERR(filp);
735734
goto out_putfd;
736735
}
737-
ima_counts_get(filp);
738736

739737
fd_install(fd, filp);
740738
goto out_upsem;

0 commit comments

Comments
 (0)