Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 31333
b: refs/heads/master
c: 877ce7c
h: refs/heads/master
i:
  31331: be4b9cf
v: v3
  • Loading branch information
Catherine Zhang authored and David S. Miller committed Jun 29, 2006
1 parent 6fd8283 commit e21ac74
Show file tree
Hide file tree
Showing 27 changed files with 91 additions and 4 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: d6b4991ad5d1a9840e12db507be1a6593def01fe
refs/heads/master: 877ce7c1b3afd69a9b1caeb1b9964c992641f52a
1 change: 1 addition & 0 deletions trunk/include/asm-alpha/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define SCM_TIMESTAMP SO_TIMESTAMP

#define SO_PEERSEC 30
#define SO_PASSSEC 34

/* Security levels - as per NRL IPv6 - don't actually do anything */
#define SO_SECURITY_AUTHENTICATION 19
Expand Down
1 change: 1 addition & 0 deletions trunk/include/asm-arm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-arm26/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-cris/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_SOCKET_H */

Expand Down
1 change: 1 addition & 0 deletions trunk/include/asm-frv/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_SOCKET_H */

1 change: 1 addition & 0 deletions trunk/include/asm-h8300/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-i386/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-ia64/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_IA64_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-m32r/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_M32R_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-m68k/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-mips/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ To add: #define SO_REUSEPORT 0x0200 /* Allow local address and port reuse. */
#define SO_PEERSEC 30
#define SO_SNDBUFFORCE 31
#define SO_RCVBUFFORCE 33
#define SO_PASSSEC 34

#ifdef __KERNEL__

Expand Down
1 change: 1 addition & 0 deletions trunk/include/asm-parisc/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 0x401c

#define SO_PEERSEC 0x401d
#define SO_PASSSEC 0x401e

#endif /* _ASM_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-powerpc/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_POWERPC_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-s390/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-sh/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* __ASM_SH_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-sparc/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define SCM_TIMESTAMP SO_TIMESTAMP

#define SO_PEERSEC 0x001e
#define SO_PASSSEC 0x001f

/* Security levels - as per NRL IPv6 - don't actually do anything */
#define SO_SECURITY_AUTHENTICATION 0x5001
Expand Down
1 change: 1 addition & 0 deletions trunk/include/asm-sparc64/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define SCM_TIMESTAMP SO_TIMESTAMP

#define SO_PEERSEC 0x001e
#define SO_PASSSEC 0x001f

/* Security levels - as per NRL IPv6 - don't actually do anything */
#define SO_SECURITY_AUTHENTICATION 0x5001
Expand Down
1 change: 1 addition & 0 deletions trunk/include/asm-v850/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* __V850_SOCKET_H__ */
1 change: 1 addition & 0 deletions trunk/include/asm-x86_64/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
#define SO_ACCEPTCONN 30

#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _ASM_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/asm-xtensa/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@

#define SO_ACCEPTCONN 30
#define SO_PEERSEC 31
#define SO_PASSSEC 34

#endif /* _XTENSA_SOCKET_H */
1 change: 1 addition & 0 deletions trunk/include/linux/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef enum {
#define SOCK_ASYNC_WAITDATA 1
#define SOCK_NOSPACE 2
#define SOCK_PASSCRED 3
#define SOCK_PASSSEC 4

#ifndef ARCH_HAS_SOCKET_TYPES
/**
Expand Down
6 changes: 6 additions & 0 deletions trunk/include/net/af_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ struct unix_address {
struct unix_skb_parms {
struct ucred creds; /* Skb credentials */
struct scm_fp_list *fp; /* Passed files */
#ifdef CONFIG_SECURITY_NETWORK
char *secdata; /* Security context */
u32 seclen; /* Security length */
#endif
};

#define UNIXCB(skb) (*(struct unix_skb_parms*)&((skb)->cb))
#define UNIXCREDS(skb) (&UNIXCB((skb)).creds)
#define UNIXSECDATA(skb) (&UNIXCB((skb)).secdata)
#define UNIXSECLEN(skb) (&UNIXCB((skb)).seclen)

#define unix_state_rlock(s) spin_lock(&unix_sk(s)->lock)
#define unix_state_runlock(s) spin_unlock(&unix_sk(s)->lock)
Expand Down
17 changes: 17 additions & 0 deletions trunk/include/net/scm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ struct scm_cookie
{
struct ucred creds; /* Skb credentials */
struct scm_fp_list *fp; /* Passed files */
#ifdef CONFIG_SECURITY_NETWORK
char *secdata; /* Security context */
u32 seclen; /* Security length */
#endif
unsigned long seq; /* Connection seqno */
};

Expand Down Expand Up @@ -48,6 +52,17 @@ static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
return __scm_send(sock, msg, scm);
}

#ifdef CONFIG_SECURITY_NETWORK
static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm)
{
if (test_bit(SOCK_PASSSEC, &sock->flags) && scm->secdata != NULL)
put_cmsg(msg, SOL_SOCKET, SCM_SECURITY, scm->seclen, scm->secdata);
}
#else
static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm)
{ }
#endif /* CONFIG_SECURITY_NETWORK */

static __inline__ void scm_recv(struct socket *sock, struct msghdr *msg,
struct scm_cookie *scm, int flags)
{
Expand All @@ -62,6 +77,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_passec(sock, msg, scm);

if (!scm->fp)
return;

Expand Down
11 changes: 11 additions & 0 deletions trunk/net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
ret = -ENONET;
break;

case SO_PASSSEC:
if (valbool)
set_bit(SOCK_PASSSEC, &sock->flags);
else
clear_bit(SOCK_PASSSEC, &sock->flags);
break;

/* We implement the SO_SNDLOWAT etc to
not be settable (1003.1g 5.3) */
default:
Expand Down Expand Up @@ -723,6 +730,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
v.val = sk->sk_state == TCP_LISTEN;
break;

case SO_PASSSEC:
v.val = test_bit(SOCK_PASSSEC, &sock->flags) ? 1 : 0;
break;

case SO_PEERSEC:
return security_socket_getpeersec_stream(sock, optval, optlen, len);

Expand Down
27 changes: 27 additions & 0 deletions trunk/net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ static atomic_t unix_nr_socks = ATOMIC_INIT(0);

#define UNIX_ABSTRACT(sk) (unix_sk(sk)->addr->hash != UNIX_HASH_SIZE)

#ifdef CONFIG_SECURITY_NETWORK
static void unix_get_peersec_dgram(struct sk_buff *skb)
{
int err;

err = security_socket_getpeersec_dgram(skb, UNIXSECDATA(skb),
UNIXSECLEN(skb));
if (err)
*(UNIXSECDATA(skb)) = NULL;
}

static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb)
{
scm->secdata = *UNIXSECDATA(skb);
scm->seclen = *UNIXSECLEN(skb);
}
#else
static void unix_get_peersec_dgram(struct sk_buff *skb)
{ }

static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb)
{ }
#endif /* CONFIG_SECURITY_NETWORK */

/*
* SMP locking strategy:
* hash table is protected with spinlock unix_table_lock
Expand Down Expand Up @@ -1291,6 +1315,8 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
if (siocb->scm->fp)
unix_attach_fds(siocb->scm, skb);

unix_get_peersec_dgram(skb);

skb->h.raw = skb->data;
err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
if (err)
Expand Down Expand Up @@ -1570,6 +1596,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
memset(&tmp_scm, 0, sizeof(tmp_scm));
}
siocb->scm->creds = *UNIXCREDS(skb);
unix_set_secdata(siocb->scm, skb);

if (!(flags & MSG_PEEK))
{
Expand Down
11 changes: 8 additions & 3 deletions trunk/security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include <linux/sysctl.h>
#include <linux/audit.h>
#include <linux/string.h>
#include <linux/selinux.h>

#include "avc.h"
#include "objsec.h"
Expand Down Expand Up @@ -3420,7 +3421,13 @@ static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *op
static int selinux_socket_getpeersec_dgram(struct sk_buff *skb, char **secdata, u32 *seclen)
{
int err = 0;
u32 peer_sid = selinux_socket_getpeer_dgram(skb);
u32 peer_sid;

if (skb->sk->sk_family == PF_UNIX)
selinux_get_inode_sid(SOCK_INODE(skb->sk->sk_socket),
&peer_sid);
else
peer_sid = selinux_socket_getpeer_dgram(skb);

if (peer_sid == SECSID_NULL)
return -EINVAL;
Expand All @@ -3432,8 +3439,6 @@ static int selinux_socket_getpeersec_dgram(struct sk_buff *skb, char **secdata,
return 0;
}



static int selinux_sk_alloc_security(struct sock *sk, int family, gfp_t priority)
{
return sk_alloc_security(sk, family, priority);
Expand Down

0 comments on commit e21ac74

Please sign in to comment.