Commit 3f551f94 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by David S. Miller

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: default avatarEric W. Biederman <ebiederm@xmission.com>
Acked-by: default avatarPavel Emelyanov <xemul@openvz.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5c1469de
...@@ -24,6 +24,9 @@ struct __kernel_sockaddr_storage { ...@@ -24,6 +24,9 @@ struct __kernel_sockaddr_storage {
#include <linux/types.h> /* pid_t */ #include <linux/types.h> /* pid_t */
#include <linux/compiler.h> /* __user */ #include <linux/compiler.h> /* __user */
struct pid;
struct cred;
#define __sockaddr_check_size(size) \ #define __sockaddr_check_size(size) \
BUILD_BUG_ON(((size) > sizeof(struct __kernel_sockaddr_storage))) BUILD_BUG_ON(((size) > sizeof(struct __kernel_sockaddr_storage)))
...@@ -309,6 +312,8 @@ struct ucred { ...@@ -309,6 +312,8 @@ struct ucred {
#define IPX_TYPE 1 #define IPX_TYPE 1
#ifdef __KERNEL__ #ifdef __KERNEL__
extern void cred_to_ucred(struct pid *pid, const struct cred *cred, struct ucred *ucred);
extern int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len); extern int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len);
extern int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov, extern int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov,
int offset, int len); int offset, int len);
......
...@@ -110,6 +110,7 @@ ...@@ -110,6 +110,7 @@
#include <linux/tcp.h> #include <linux/tcp.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/user_namespace.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/system.h> #include <asm/system.h>
...@@ -749,6 +750,19 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -749,6 +750,19 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
EXPORT_SYMBOL(sock_setsockopt); EXPORT_SYMBOL(sock_setsockopt);
void cred_to_ucred(struct pid *pid, const struct cred *cred,
struct ucred *ucred)
{
ucred->pid = pid_vnr(pid);
ucred->uid = ucred->gid = -1;
if (cred) {
struct user_namespace *current_ns = current_user_ns();
ucred->uid = user_ns_map_uid(current_ns, cred, cred->euid);
ucred->gid = user_ns_map_gid(current_ns, cred, cred->egid);
}
}
int sock_getsockopt(struct socket *sock, int level, int optname, int sock_getsockopt(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen) char __user *optval, int __user *optlen)
{ {
......
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