Skip to content

Commit

Permalink
Merge branch 'bugfixes' of git://git.kernel.org/pub/scm/linux/kernel/…
Browse files Browse the repository at this point in the history
…git/jmorris/security-testing-2.6

* 'bugfixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6:
  integrity: add ima_counts_put (updated)
  integrity: ima audit hash_exists fix
  integrity: ima mq_open imbalance msg fix
  • Loading branch information
Linus Torvalds committed Jun 29, 2009
2 parents e717f33 + 94e5d71 commit bb1e9b8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
7 changes: 7 additions & 0 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,10 @@ struct file *do_filp_open(int dfd, const char *pathname,
goto exit;
}
filp = nameidata_to_filp(&nd, open_flag);
if (IS_ERR(filp))
ima_counts_put(&nd.path,
acc_mode & (MAY_READ | MAY_WRITE |
MAY_EXEC));
mnt_drop_write(nd.path.mnt);
if (nd.root.mnt)
path_put(&nd.root);
Expand Down Expand Up @@ -1817,6 +1821,9 @@ struct file *do_filp_open(int dfd, const char *pathname,
goto exit;
}
filp = nameidata_to_filp(&nd, open_flag);
if (IS_ERR(filp))
ima_counts_put(&nd.path,
acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC));
/*
* It is now safe to drop the mnt write
* because the filp has had a write taken
Expand Down
6 changes: 6 additions & 0 deletions include/linux/ima.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern int ima_path_check(struct path *path, int mask, int update_counts);
extern void ima_file_free(struct file *file);
extern int ima_file_mmap(struct file *file, unsigned long prot);
extern void ima_counts_get(struct file *file);
extern void ima_counts_put(struct path *path, int mask);

#else
static inline int ima_bprm_check(struct linux_binprm *bprm)
Expand Down Expand Up @@ -60,5 +61,10 @@ static inline void ima_counts_get(struct file *file)
{
return;
}

static inline void ima_counts_put(struct path *path, int mask)
{
return;
}
#endif /* CONFIG_IMA_H */
#endif /* _LINUX_IMA_H */
2 changes: 2 additions & 0 deletions ipc/mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <linux/nsproxy.h>
#include <linux/pid.h>
#include <linux/ipc_namespace.h>
#include <linux/ima.h>

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

fd_install(fd, filp);
goto out_upsem;
Expand Down
29 changes: 28 additions & 1 deletion security/integrity/ima/ima_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,34 @@ static int process_measurement(struct file *file, const unsigned char *filename,
}

/*
* ima_opens_get - increment file counts
* ima_counts_put - decrement file counts
*
* File counts are incremented in ima_path_check. On file open
* error, such as ETXTBSY, decrement the counts to prevent
* unnecessary imbalance messages.
*/
void ima_counts_put(struct path *path, int mask)
{
struct inode *inode = path->dentry->d_inode;
struct ima_iint_cache *iint;

if (!ima_initialized || !S_ISREG(inode->i_mode))
return;
iint = ima_iint_find_insert_get(inode);
if (!iint)
return;

mutex_lock(&iint->mutex);
iint->opencount--;
if ((mask & MAY_WRITE) || (mask == 0))
iint->writecount--;
else if (mask & (MAY_READ | MAY_EXEC))
iint->readcount--;
mutex_unlock(&iint->mutex);
}

/*
* ima_counts_get - increment file counts
*
* - for IPC shm and shmat file.
* - for nfsd exported files.
Expand Down
3 changes: 2 additions & 1 deletion security/integrity/ima/ima_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ int ima_add_template_entry(struct ima_template_entry *entry, int violation,
}
out:
mutex_unlock(&ima_extend_list_mutex);
integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode, entry->template_name,
integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode,
entry->template.file_name,
op, audit_cause, result, audit_info);
return result;
}

0 comments on commit bb1e9b8

Please sign in to comment.