Commit 8192b0c4 authored by David Howells's avatar David Howells Committed by James Morris

CRED: Wrap task credential accesses in the networking subsystem

Wrap access to task credentials so that they can be separated more easily from
the task_struct during the introduction of COW creds.

Change most current->(|e|s|fs)[ug]id to current_(|e|s|fs)[ug]id().

Change some task->e?[ug]id to task_e?[ug]id().  In some places it makes more
sense to use RCU directly rather than a convenient wrapper; these will be
addressed by later patches.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Reviewed-by: default avatarJames Morris <jmorris@namei.org>
Acked-by: default avatarSerge Hallyn <serue@us.ibm.com>
Cc: netdev@vger.kernel.org
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent 19d65624
...@@ -54,8 +54,8 @@ static __inline__ int scm_send(struct socket *sock, struct msghdr *msg, ...@@ -54,8 +54,8 @@ static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
struct scm_cookie *scm) struct scm_cookie *scm)
{ {
struct task_struct *p = current; struct task_struct *p = current;
scm->creds.uid = p->uid; scm->creds.uid = current_uid();
scm->creds.gid = p->gid; scm->creds.gid = current_gid();
scm->creds.pid = task_tgid_vnr(p); scm->creds.pid = task_tgid_vnr(p);
scm->fp = NULL; scm->fp = NULL;
scm->seq = 0; scm->seq = 0;
......
...@@ -2958,6 +2958,8 @@ static void dev_change_rx_flags(struct net_device *dev, int flags) ...@@ -2958,6 +2958,8 @@ static void dev_change_rx_flags(struct net_device *dev, int flags)
static int __dev_set_promiscuity(struct net_device *dev, int inc) static int __dev_set_promiscuity(struct net_device *dev, int inc)
{ {
unsigned short old_flags = dev->flags; unsigned short old_flags = dev->flags;
uid_t uid;
gid_t gid;
ASSERT_RTNL(); ASSERT_RTNL();
...@@ -2982,15 +2984,17 @@ static int __dev_set_promiscuity(struct net_device *dev, int inc) ...@@ -2982,15 +2984,17 @@ static int __dev_set_promiscuity(struct net_device *dev, int inc)
printk(KERN_INFO "device %s %s promiscuous mode\n", printk(KERN_INFO "device %s %s promiscuous mode\n",
dev->name, (dev->flags & IFF_PROMISC) ? "entered" : dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
"left"); "left");
if (audit_enabled) if (audit_enabled) {
current_uid_gid(&uid, &gid);
audit_log(current->audit_context, GFP_ATOMIC, audit_log(current->audit_context, GFP_ATOMIC,
AUDIT_ANOM_PROMISCUOUS, AUDIT_ANOM_PROMISCUOUS,
"dev=%s prom=%d old_prom=%d auid=%u uid=%u gid=%u ses=%u", "dev=%s prom=%d old_prom=%d auid=%u uid=%u gid=%u ses=%u",
dev->name, (dev->flags & IFF_PROMISC), dev->name, (dev->flags & IFF_PROMISC),
(old_flags & IFF_PROMISC), (old_flags & IFF_PROMISC),
audit_get_loginuid(current), audit_get_loginuid(current),
current->uid, current->gid, uid, gid,
audit_get_sessionid(current)); audit_get_sessionid(current));
}
dev_change_rx_flags(dev, IFF_PROMISC); dev_change_rx_flags(dev, IFF_PROMISC);
} }
......
...@@ -45,10 +45,10 @@ ...@@ -45,10 +45,10 @@
static __inline__ int scm_check_creds(struct ucred *creds) static __inline__ int scm_check_creds(struct ucred *creds)
{ {
if ((creds->pid == task_tgid_vnr(current) || capable(CAP_SYS_ADMIN)) && if ((creds->pid == task_tgid_vnr(current) || capable(CAP_SYS_ADMIN)) &&
((creds->uid == current->uid || creds->uid == current->euid || ((creds->uid == current_uid() || creds->uid == current_euid() ||
creds->uid == current->suid) || capable(CAP_SETUID)) && creds->uid == current_suid()) || capable(CAP_SETUID)) &&
((creds->gid == current->gid || creds->gid == current->egid || ((creds->gid == current_gid() || creds->gid == current_egid() ||
creds->gid == current->sgid) || capable(CAP_SETGID))) { creds->gid == current_sgid()) || capable(CAP_SETGID))) {
return 0; return 0;
} }
return -EPERM; return -EPERM;
......
...@@ -491,8 +491,8 @@ static struct socket *sock_alloc(void) ...@@ -491,8 +491,8 @@ static struct socket *sock_alloc(void)
sock = SOCKET_I(inode); sock = SOCKET_I(inode);
inode->i_mode = S_IFSOCK | S_IRWXUGO; inode->i_mode = S_IFSOCK | S_IRWXUGO;
inode->i_uid = current->fsuid; inode->i_uid = current_fsuid();
inode->i_gid = current->fsgid; inode->i_gid = current_fsgid();
get_cpu_var(sockets_in_use)++; get_cpu_var(sockets_in_use)++;
put_cpu_var(sockets_in_use); put_cpu_var(sockets_in_use);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment