Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 202977
b: refs/heads/master
c: 257b535
h: refs/heads/master
i:
  202975: 24c292a
v: v3
  • Loading branch information
Eric W. Biederman authored and David S. Miller committed Jun 16, 2010
1 parent e20342f commit 00e57ac
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b47030c71dfd6c8cd5cb6e551b6f7f7cfc96f6a6
refs/heads/master: 257b5358b32f17e0603b6ff57b13610b0e02348f
28 changes: 24 additions & 4 deletions trunk/include/net/scm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ struct scm_fp_list {
};

struct scm_cookie {
struct pid *pid; /* Skb credentials */
const struct cred *cred;
struct scm_fp_list *fp; /* Passed files */
struct ucred creds; /* Skb credentials */
#ifdef CONFIG_SECURITY_NETWORK
Expand All @@ -42,19 +44,35 @@ static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_co
{ }
#endif /* CONFIG_SECURITY_NETWORK */

static __inline__ void scm_set_cred(struct scm_cookie *scm,
struct pid *pid, const struct cred *cred)
{
scm->pid = get_pid(pid);
scm->cred = get_cred(cred);
cred_to_ucred(pid, cred, &scm->creds);
}

static __inline__ void scm_destroy_cred(struct scm_cookie *scm)
{
put_pid(scm->pid);
scm->pid = NULL;

if (scm->cred)
put_cred(scm->cred);
scm->cred = NULL;
}

static __inline__ void scm_destroy(struct scm_cookie *scm)
{
scm_destroy_cred(scm);
if (scm && scm->fp)
__scm_destroy(scm);
}

static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
struct scm_cookie *scm)
{
struct task_struct *p = current;
scm->creds.uid = current_uid();
scm->creds.gid = current_gid();
scm->creds.pid = task_tgid_vnr(p);
scm_set_cred(scm, task_tgid(current), current_cred());
scm->fp = NULL;
unix_get_peersec_dgram(sock, scm);
if (msg->msg_controllen <= 0)
Expand Down Expand Up @@ -96,6 +114,8 @@ static __inline__ void scm_recv(struct socket *sock, struct msghdr *msg,
if (test_bit(SOCK_PASSCRED, &sock->flags))
put_cmsg(msg, SOL_SOCKET, SCM_CREDENTIALS, sizeof(scm->creds), &scm->creds);

scm_destroy_cred(scm);

scm_passec(sock, msg, scm);

if (!scm->fp)
Expand Down
24 changes: 24 additions & 0 deletions trunk/net/core/scm.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,30 @@ int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)
err = scm_check_creds(&p->creds);
if (err)
goto error;

if (pid_vnr(p->pid) != p->creds.pid) {
struct pid *pid;
err = -ESRCH;
pid = find_get_pid(p->creds.pid);
if (!pid)
goto error;
put_pid(p->pid);
p->pid = pid;
}

if ((p->cred->euid != p->creds.uid) ||
(p->cred->egid != p->creds.gid)) {
struct cred *cred;
err = -ENOMEM;
cred = prepare_creds();
if (!cred)
goto error;

cred->uid = cred->euid = p->creds.uid;
cred->gid = cred->egid = p->creds.uid;
put_cred(p->cred);
p->cred = cred;
}
break;
default:
goto error;
Expand Down

0 comments on commit 00e57ac

Please sign in to comment.