CRED: Use creds in file structs
David Howells [Thu, 13 Nov 2008 23:39:25 +0000 (10:39 +1100)]
Attach creds to file structs and discard f_uid/f_gid.

file_operations::open() methods (such as hppfs_open()) should use file->f_cred
rather than current_cred().  At the moment file->f_cred will be current_cred()
at this point.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>

arch/mips/kernel/vpe.c
drivers/isdn/hysdn/hysdn_procconf.c
fs/coda/file.c
fs/file_table.c
fs/hppfs/hppfs.c
include/linux/fs.h
net/ipv4/netfilter/ipt_LOG.c
net/ipv6/netfilter/ip6t_LOG.c
net/netfilter/nfnetlink_log.c
net/netfilter/xt_owner.c
net/sched/cls_flow.c

index 972b2d2..09786e4 100644 (file)
@@ -1085,8 +1085,8 @@ static int vpe_open(struct inode *inode, struct file *filp)
        v->load_addr = NULL;
        v->len = 0;
 
-       v->uid = filp->f_uid;
-       v->gid = filp->f_gid;
+       v->uid = filp->f_cred->fsuid;
+       v->gid = filp->f_cred->fsgid;
 
 #ifdef CONFIG_MIPS_APSP_KSPD
        /* get kspd to tell us when a syscall_exit happens */
index 484299b..8f9f491 100644 (file)
@@ -246,7 +246,8 @@ hysdn_conf_open(struct inode *ino, struct file *filep)
        }
        if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL))
                hysdn_addlog(card, "config open for uid=%d gid=%d mode=0x%x",
-                            filep->f_uid, filep->f_gid, filep->f_mode);
+                            filep->f_cred->fsuid, filep->f_cred->fsgid,
+                            filep->f_mode);
 
        if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
                /* write only access -> write boot file or conf line */
@@ -331,7 +332,8 @@ hysdn_conf_close(struct inode *ino, struct file *filep)
        }
        if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL))
                hysdn_addlog(card, "config close for uid=%d gid=%d mode=0x%x",
-                            filep->f_uid, filep->f_gid, filep->f_mode);
+                            filep->f_cred->fsuid, filep->f_cred->fsgid,
+                            filep->f_mode);
 
        if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
                /* write only access -> write boot file or conf line */
index 29137ff..5a87699 100644 (file)
@@ -174,7 +174,7 @@ int coda_release(struct inode *coda_inode, struct file *coda_file)
        BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
 
        err = venus_close(coda_inode->i_sb, coda_i2f(coda_inode),
-                         coda_flags, coda_file->f_uid);
+                         coda_flags, coda_file->f_cred->fsuid);
 
        host_inode = cfi->cfi_container->f_path.dentry->d_inode;
        cii = ITOC(coda_inode);
index bc4563f..0fbcacc 100644 (file)
@@ -36,7 +36,9 @@ static struct percpu_counter nr_files __cacheline_aligned_in_smp;
 
 static inline void file_free_rcu(struct rcu_head *head)
 {
-       struct file *f =  container_of(head, struct file, f_u.fu_rcuhead);
+       struct file *f = container_of(head, struct file, f_u.fu_rcuhead);
+
+       put_cred(f->f_cred);
        kmem_cache_free(filp_cachep, f);
 }
 
@@ -121,8 +123,7 @@ struct file *get_empty_filp(void)
        INIT_LIST_HEAD(&f->f_u.fu_list);
        atomic_long_set(&f->f_count, 1);
        rwlock_init(&f->f_owner.lock);
-       f->f_uid = cred->fsuid;
-       f->f_gid = cred->fsgid;
+       f->f_cred = get_cred(cred);
        eventpoll_init_file(f);
        /* f->f_version: 0 */
        return f;
index 795e2c1..b278f7f 100644 (file)
@@ -426,7 +426,7 @@ static int file_mode(int fmode)
 
 static int hppfs_open(struct inode *inode, struct file *file)
 {
-       const struct cred *cred = current_cred();
+       const struct cred *cred = file->f_cred;
        struct hppfs_private *data;
        struct vfsmount *proc_mnt;
        struct dentry *proc_dentry;
@@ -490,7 +490,7 @@ static int hppfs_open(struct inode *inode, struct file *file)
 
 static int hppfs_dir_open(struct inode *inode, struct file *file)
 {
-       const struct cred *cred = current_cred();
+       const struct cred *cred = file->f_cred;
        struct hppfs_private *data;
        struct vfsmount *proc_mnt;
        struct dentry *proc_dentry;
index 3bfec13..c0fb6d8 100644 (file)
@@ -827,7 +827,7 @@ struct file {
        fmode_t                 f_mode;
        loff_t                  f_pos;
        struct fown_struct      f_owner;
-       unsigned int            f_uid, f_gid;
+       const struct cred       *f_cred;
        struct file_ra_state    f_ra;
 
        u64                     f_version;
index fc6ce04..7b5dbe1 100644 (file)
@@ -340,8 +340,8 @@ static void dump_packet(const struct nf_loginfo *info,
                read_lock_bh(&skb->sk->sk_callback_lock);
                if (skb->sk->sk_socket && skb->sk->sk_socket->file)
                        printk("UID=%u GID=%u ",
-                               skb->sk->sk_socket->file->f_uid,
-                               skb->sk->sk_socket->file->f_gid);
+                               skb->sk->sk_socket->file->f_cred->fsuid,
+                               skb->sk->sk_socket->file->f_cred->fsgid);
                read_unlock_bh(&skb->sk->sk_callback_lock);
        }
 
index caa441d..871d157 100644 (file)
@@ -364,8 +364,8 @@ static void dump_packet(const struct nf_loginfo *info,
                read_lock_bh(&skb->sk->sk_callback_lock);
                if (skb->sk->sk_socket && skb->sk->sk_socket->file)
                        printk("UID=%u GID=%u ",
-                               skb->sk->sk_socket->file->f_uid,
-                               skb->sk->sk_socket->file->f_gid);
+                               skb->sk->sk_socket->file->f_cred->fsuid,
+                               skb->sk->sk_socket->file->f_cred->fsgid);
                read_unlock_bh(&skb->sk->sk_callback_lock);
        }
 
index 41e0105..38f9efd 100644 (file)
@@ -474,8 +474,9 @@ __build_packet_message(struct nfulnl_instance *inst,
        if (skb->sk) {
                read_lock_bh(&skb->sk->sk_callback_lock);
                if (skb->sk->sk_socket && skb->sk->sk_socket->file) {
-                       __be32 uid = htonl(skb->sk->sk_socket->file->f_uid);
-                       __be32 gid = htonl(skb->sk->sk_socket->file->f_gid);
+                       struct file *file = skb->sk->sk_socket->file;
+                       __be32 uid = htonl(file->f_cred->fsuid);
+                       __be32 gid = htonl(file->f_cred->fsgid);
                        /* need to unlock here since NLA_PUT may goto */
                        read_unlock_bh(&skb->sk->sk_callback_lock);
                        NLA_PUT_BE32(inst->skb, NFULA_UID, uid);
index f19ebd9..22b2a5e 100644 (file)
@@ -34,12 +34,12 @@ owner_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par)
                return false;
 
        if (info->match & IPT_OWNER_UID)
-               if ((filp->f_uid != info->uid) ^
+               if ((filp->f_cred->fsuid != info->uid) ^
                    !!(info->invert & IPT_OWNER_UID))
                        return false;
 
        if (info->match & IPT_OWNER_GID)
-               if ((filp->f_gid != info->gid) ^
+               if ((filp->f_cred->fsgid != info->gid) ^
                    !!(info->invert & IPT_OWNER_GID))
                        return false;
 
@@ -60,12 +60,12 @@ owner_mt6_v0(const struct sk_buff *skb, const struct xt_match_param *par)
                return false;
 
        if (info->match & IP6T_OWNER_UID)
-               if ((filp->f_uid != info->uid) ^
+               if ((filp->f_cred->fsuid != info->uid) ^
                    !!(info->invert & IP6T_OWNER_UID))
                        return false;
 
        if (info->match & IP6T_OWNER_GID)
-               if ((filp->f_gid != info->gid) ^
+               if ((filp->f_cred->fsgid != info->gid) ^
                    !!(info->invert & IP6T_OWNER_GID))
                        return false;
 
@@ -93,14 +93,14 @@ owner_mt(const struct sk_buff *skb, const struct xt_match_param *par)
                       (XT_OWNER_UID | XT_OWNER_GID)) == 0;
 
        if (info->match & XT_OWNER_UID)
-               if ((filp->f_uid >= info->uid_min &&
-                   filp->f_uid <= info->uid_max) ^
+               if ((filp->f_cred->fsuid >= info->uid_min &&
+                   filp->f_cred->fsuid <= info->uid_max) ^
                    !(info->invert & XT_OWNER_UID))
                        return false;
 
        if (info->match & XT_OWNER_GID)
-               if ((filp->f_gid >= info->gid_min &&
-                   filp->f_gid <= info->gid_max) ^
+               if ((filp->f_cred->fsgid >= info->gid_min &&
+                   filp->f_cred->fsgid <= info->gid_max) ^
                    !(info->invert & XT_OWNER_GID))
                        return false;
 
index 0ebaff6..0ef4e30 100644 (file)
@@ -260,14 +260,14 @@ static u32 flow_get_rtclassid(const struct sk_buff *skb)
 static u32 flow_get_skuid(const struct sk_buff *skb)
 {
        if (skb->sk && skb->sk->sk_socket && skb->sk->sk_socket->file)
-               return skb->sk->sk_socket->file->f_uid;
+               return skb->sk->sk_socket->file->f_cred->fsuid;
        return 0;
 }
 
 static u32 flow_get_skgid(const struct sk_buff *skb)
 {
        if (skb->sk && skb->sk->sk_socket && skb->sk->sk_socket->file)
-               return skb->sk->sk_socket->file->f_gid;
+               return skb->sk->sk_socket->file->f_cred->fsgid;
        return 0;
 }