]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
Merge branch 'ima-memory-use-fixes'
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 26 Oct 2010 18:37:48 +0000 (11:37 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 26 Oct 2010 18:37:48 +0000 (11:37 -0700)
* ima-memory-use-fixes:
  IMA: fix the ToMToU logic
  IMA: explicit IMA i_flag to remove global lock on inode_delete
  IMA: drop refcnt from ima_iint_cache since it isn't needed
  IMA: only allocate iint when needed
  IMA: move read counter into struct inode
  IMA: use i_writecount rather than a private counter
  IMA: use inode->i_lock to protect read and write counters
  IMA: convert internal flags from long to char
  IMA: use unsigned int instead of long for counters
  IMA: drop the inode opencount since it isn't needed for operation
  IMA: use rbtree instead of radix tree for inode information cache

1  2 
include/linux/fs.h
security/security.c

diff --combined include/linux/fs.h
index 4f34ff6e55585b365db2c419c878e46c67d6d9b0,bb77843de9d65630799fd1e4d413a58037504db8..bb20373d0b46c91d0c132c389f7e5f3eaf21d8bc
@@@ -135,12 -135,12 +135,12 @@@ struct inodes_stat_t 
   *                    immediately after submission. The write equivalent
   *                    of READ_SYNC.
   * WRITE_ODIRECT_PLUG Special case write for O_DIRECT only.
 - * WRITE_BARRIER      Like WRITE_SYNC, but tells the block layer that all
 - *                    previously submitted writes must be safely on storage
 - *                    before this one is started. Also guarantees that when
 - *                    this write is complete, it itself is also safely on
 - *                    storage. Prevents reordering of writes on both sides
 - *                    of this IO.
 + * WRITE_FLUSH                Like WRITE_SYNC but with preceding cache flush.
 + * WRITE_FUA          Like WRITE_SYNC but data is guaranteed to be on
 + *                    non-volatile media on completion.
 + * WRITE_FLUSH_FUA    Combination of WRITE_FLUSH and FUA. The IO is preceded
 + *                    by a cache flush and data is guaranteed to be on
 + *                    non-volatile media on completion.
   *
   */
  #define RW_MASK                       REQ_WRITE
  #define WRITE_SYNC            (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_UNPLUG)
  #define WRITE_ODIRECT_PLUG    (WRITE | REQ_SYNC)
  #define WRITE_META            (WRITE | REQ_META)
 -#define WRITE_BARRIER         (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_UNPLUG | \
 -                               REQ_HARDBARRIER)
 -
 -/*
 - * These aren't really reads or writes, they pass down information about
 - * parts of device that are now unused by the file system.
 - */
 -#define DISCARD_NOBARRIER     (WRITE | REQ_DISCARD)
 -#define DISCARD_BARRIER               (WRITE | REQ_DISCARD | REQ_HARDBARRIER)
 -#define DISCARD_SECURE                (DISCARD_NOBARRIER | REQ_SECURE)
 +#define WRITE_FLUSH           (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_UNPLUG | \
 +                               REQ_FLUSH)
 +#define WRITE_FUA             (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_UNPLUG | \
 +                               REQ_FUA)
 +#define WRITE_FLUSH_FUA               (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_UNPLUG | \
 +                               REQ_FLUSH | REQ_FUA)
  
  #define SEL_IN                1
  #define SEL_OUT               2
  #define S_NOCMTIME    128     /* Do not update file c/mtime */
  #define S_SWAPFILE    256     /* Do not truncate: swapon got its bmaps */
  #define S_PRIVATE     512     /* Inode is fs-internal */
+ #define S_IMA         1024    /* Inode has an associated IMA struct */
  
  /*
   * Note that nosuid etc flags are inode-specific: setting some file-system
  #define IS_NOCMTIME(inode)    ((inode)->i_flags & S_NOCMTIME)
  #define IS_SWAPFILE(inode)    ((inode)->i_flags & S_SWAPFILE)
  #define IS_PRIVATE(inode)     ((inode)->i_flags & S_PRIVATE)
+ #define IS_IMA(inode)         ((inode)->i_flags & S_IMA)
  
  /* the read-only stuff doesn't really belong here, but any other place is
     probably as bad and I don't want to create yet another include file. */
@@@ -772,6 -778,10 +774,10 @@@ struct inode 
  
        unsigned int            i_flags;
  
+ #ifdef CONFIG_IMA
+       /* protected by i_lock */
+       unsigned int            i_readcount; /* struct files open RO */
+ #endif
        atomic_t                i_writecount;
  #ifdef CONFIG_SECURITY
        void                    *i_security;
@@@ -1089,6 -1099,10 +1095,6 @@@ struct file_lock 
  
  #include <linux/fcntl.h>
  
 -/* temporary stubs for BKL removal */
 -#define lock_flocks() lock_kernel()
 -#define unlock_flocks() unlock_kernel()
 -
  extern void send_sigio(struct fown_struct *fown, int fd, int band);
  
  #ifdef CONFIG_FILE_LOCKING
@@@ -1127,8 -1141,6 +1133,8 @@@ extern int vfs_setlease(struct file *, 
  extern int lease_modify(struct file_lock **, int);
  extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
  extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
 +extern void lock_flocks(void);
 +extern void unlock_flocks(void);
  #else /* !CONFIG_FILE_LOCKING */
  static inline int fcntl_getlk(struct file *file, struct flock __user *user)
  {
@@@ -1271,14 -1283,6 +1277,14 @@@ static inline int lock_may_write(struc
        return 1;
  }
  
 +static inline void lock_flocks(void)
 +{
 +}
 +
 +static inline void unlock_flocks(void)
 +{
 +}
 +
  #endif /* !CONFIG_FILE_LOCKING */
  
  
@@@ -1386,7 -1390,7 +1392,7 @@@ struct super_block 
         * Saved mount options for lazy filesystems using
         * generic_show_options()
         */
 -      char *s_options;
 +      char __rcu *s_options;
  };
  
  extern struct timespec current_fs_time(struct super_block *sb);
@@@ -2380,8 -2384,6 +2386,8 @@@ extern ssize_t simple_write_to_buffer(v
  
  extern int generic_file_fsync(struct file *, int);
  
 +extern int generic_check_addressable(unsigned, u64);
 +
  #ifdef CONFIG_MIGRATION
  extern int buffer_migrate_page(struct address_space *,
                                struct page *, struct page *);
@@@ -2458,7 -2460,6 +2464,7 @@@ static const struct file_operations __f
        .release = simple_attr_release,                                 \
        .read    = simple_attr_read,                                    \
        .write   = simple_attr_write,                                   \
 +      .llseek  = generic_file_llseek,                                 \
  };
  
  static inline void __attribute__((format(printf, 1, 2)))
diff --combined security/security.c
index b50f472061a43c6ec7fb53781c084fb2cb487dcb,a3b47feccae9ca72680736a06bb8b34ae9b9185a..3ef5e2a7a741aca4b13cd08b571e0a0ca0ee7d72
@@@ -89,12 -89,20 +89,12 @@@ __setup("security=", choose_lsm)
   * Return true if:
   *    -The passed LSM is the one chosen by user at boot time,
   *    -or the passed LSM is configured as the default and the user did not
 - *     choose an alternate LSM at boot time,
 - *    -or there is no default LSM set and the user didn't specify a
 - *     specific LSM and we're the first to ask for registration permission,
 - *    -or the passed LSM is currently loaded.
 + *     choose an alternate LSM at boot time.
   * Otherwise, return false.
   */
  int __init security_module_enable(struct security_operations *ops)
  {
 -      if (!*chosen_lsm)
 -              strncpy(chosen_lsm, ops->name, SECURITY_NAME_MAX);
 -      else if (strncmp(ops->name, chosen_lsm, SECURITY_NAME_MAX))
 -              return 0;
 -
 -      return 1;
 +      return !strcmp(ops->name, chosen_lsm);
  }
  
  /**
@@@ -325,16 -333,8 +325,8 @@@ EXPORT_SYMBOL(security_sb_parse_opts_st
  
  int security_inode_alloc(struct inode *inode)
  {
-       int ret;
        inode->i_security = NULL;
-       ret =  security_ops->inode_alloc_security(inode);
-       if (ret)
-               return ret;
-       ret = ima_inode_alloc(inode);
-       if (ret)
-               security_inode_free(inode);
-       return ret;
+       return security_ops->inode_alloc_security(inode);
  }
  
  void security_inode_free(struct inode *inode)
@@@ -778,9 -778,10 +770,9 @@@ int security_task_setrlimit(struct task
        return security_ops->task_setrlimit(p, resource, new_rlim);
  }
  
 -int security_task_setscheduler(struct task_struct *p,
 -                              int policy, struct sched_param *lp)
 +int security_task_setscheduler(struct task_struct *p)
  {
 -      return security_ops->task_setscheduler(p, policy, lp);
 +      return security_ops->task_setscheduler(p);
  }
  
  int security_task_getscheduler(struct task_struct *p)
@@@ -1136,24 -1137,6 +1128,24 @@@ void security_inet_conn_established(str
        security_ops->inet_conn_established(sk, skb);
  }
  
 +int security_secmark_relabel_packet(u32 secid)
 +{
 +      return security_ops->secmark_relabel_packet(secid);
 +}
 +EXPORT_SYMBOL(security_secmark_relabel_packet);
 +
 +void security_secmark_refcount_inc(void)
 +{
 +      security_ops->secmark_refcount_inc();
 +}
 +EXPORT_SYMBOL(security_secmark_refcount_inc);
 +
 +void security_secmark_refcount_dec(void)
 +{
 +      security_ops->secmark_refcount_dec();
 +}
 +EXPORT_SYMBOL(security_secmark_refcount_dec);
 +
  int security_tun_dev_create(void)
  {
        return security_ops->tun_dev_create();