aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2010-06-12 23:28:59 -0400
committerDavid S. Miller <davem@davemloft.net>2010-06-16 17:55:35 -0400
commit3f551f9436c05a3b5eccdd6e94733df5bb98d2a5 (patch)
treeee5a9148797994682a4553e817e96b721303f3ec
parent5c1469de7545a35a16ff2b902e217044a7d2f8a5 (diff)
sock: Introduce cred_to_ucred
To keep the coming code clear and to allow both the sock code and the scm code to share the logic introduce a fuction to translate from struct cred to struct ucred. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Acked-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/socket.h5
-rw-r--r--net/core/sock.c14
2 files changed, 19 insertions, 0 deletions
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 032a19eb61b1..a2fada9becb6 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -24,6 +24,9 @@ struct __kernel_sockaddr_storage {
24#include <linux/types.h> /* pid_t */ 24#include <linux/types.h> /* pid_t */
25#include <linux/compiler.h> /* __user */ 25#include <linux/compiler.h> /* __user */
26 26
27struct pid;
28struct cred;
29
27#define __sockaddr_check_size(size) \ 30#define __sockaddr_check_size(size) \
28 BUILD_BUG_ON(((size) > sizeof(struct __kernel_sockaddr_storage))) 31 BUILD_BUG_ON(((size) > sizeof(struct __kernel_sockaddr_storage)))
29 32
@@ -309,6 +312,8 @@ struct ucred {
309#define IPX_TYPE 1 312#define IPX_TYPE 1
310 313
311#ifdef __KERNEL__ 314#ifdef __KERNEL__
315extern void cred_to_ucred(struct pid *pid, const struct cred *cred, struct ucred *ucred);
316
312extern int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len); 317extern int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len);
313extern int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov, 318extern int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov,
314 int offset, int len); 319 int offset, int len);
diff --git a/net/core/sock.c b/net/core/sock.c
index f9ce0db41cd6..db8335ad7559 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -110,6 +110,7 @@
110#include <linux/tcp.h> 110#include <linux/tcp.h>
111#include <linux/init.h> 111#include <linux/init.h>
112#include <linux/highmem.h> 112#include <linux/highmem.h>
113#include <linux/user_namespace.h>
113 114
114#include <asm/uaccess.h> 115#include <asm/uaccess.h>
115#include <asm/system.h> 116#include <asm/system.h>
@@ -749,6 +750,19 @@ set_rcvbuf:
749EXPORT_SYMBOL(sock_setsockopt); 750EXPORT_SYMBOL(sock_setsockopt);
750 751
751 752
753void cred_to_ucred(struct pid *pid, const struct cred *cred,
754 struct ucred *ucred)
755{
756 ucred->pid = pid_vnr(pid);
757 ucred->uid = ucred->gid = -1;
758 if (cred) {
759 struct user_namespace *current_ns = current_user_ns();
760
761 ucred->uid = user_ns_map_uid(current_ns, cred, cred->euid);
762 ucred->gid = user_ns_map_gid(current_ns, cred, cred->egid);
763 }
764}
765
752int sock_getsockopt(struct socket *sock, int level, int optname, 766int sock_getsockopt(struct socket *sock, int level, int optname,
753 char __user *optval, int __user *optlen) 767 char __user *optval, int __user *optlen)
754{ 768{