Commit 82c1f12a authored by Stephen Rothwell's avatar Stephen Rothwell Committed by David S. Miller

[COMPAT] cleanups in net/compat.c and related files

parent 83a0e2be
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/fs_struct.h> #include <linux/fs_struct.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/socket.h> #include <linux/socket.h>
#include <net/compat.h>
#include <asm/oplib.h> #include <asm/oplib.h>
#include <asm/delay.h> #include <asm/delay.h>
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
/* For SOCKET_I */ /* For SOCKET_I */
#include <linux/socket.h> #include <linux/socket.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/compat.h>
/* Use this to get at 32-bit user passed pointers. */ /* Use this to get at 32-bit user passed pointers. */
#define A(__x) \ #define A(__x) \
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/file.h> #include <linux/file.h>
#include <linux/net.h> #include <linux/net.h>
#include <linux/compat.h> #include <linux/compat.h>
#include <net/compat.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/string.h> #include <asm/string.h>
......
...@@ -43,11 +43,9 @@ extern int get_compat_timespec(struct timespec *, struct compat_timespec *); ...@@ -43,11 +43,9 @@ extern int get_compat_timespec(struct timespec *, struct compat_timespec *);
extern int put_compat_timespec(struct timespec *, struct compat_timespec *); extern int put_compat_timespec(struct timespec *, struct compat_timespec *);
struct compat_iovec { struct compat_iovec {
u32 iov_base; compat_uptr_t iov_base;
compat_size_t iov_len; compat_size_t iov_len;
}; };
#else /* no CONFIG_COMPAT */
#define compat_size_t size_t
#endif /* CONFIG_COMPAT */ #endif /* CONFIG_COMPAT */
#endif /* _LINUX_COMPAT_H */ #endif /* _LINUX_COMPAT_H */
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
#include <linux/config.h> /* for CONFIG_COMPAT */
#include <linux/linkage.h> #include <linux/linkage.h>
#include <asm/socket.h> /* arch-dependent defines */ #include <asm/socket.h> /* arch-dependent defines */
#include <linux/sockios.h> /* the SIOCxxx I/O controls */ #include <linux/sockios.h> /* the SIOCxxx I/O controls */
...@@ -239,18 +240,10 @@ struct ucred { ...@@ -239,18 +240,10 @@ struct ucred {
#define MSG_CMSG_COMPAT 0x80000000 /* This message needs 32 bit fixups */ #define MSG_CMSG_COMPAT 0x80000000 /* This message needs 32 bit fixups */
#else #else
#define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */ #define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */
#define compat_msghdr msghdr /* Needed to avoid compiler hoops */
#endif #endif
struct compat_msghdr;
extern int msghdr_from_user_compat_to_kern(struct msghdr *, struct compat_msghdr *);
extern int verify_compat_iovec(struct msghdr *, struct iovec *, char *, int);
extern asmlinkage long compat_sys_sendmsg(int,struct compat_msghdr *,unsigned);
extern asmlinkage long compat_sys_recvmsg(int,struct compat_msghdr *,unsigned);
extern asmlinkage long sys_sendmsg(int fd, struct msghdr *msg, unsigned flags); extern asmlinkage long sys_sendmsg(int fd, struct msghdr *msg, unsigned flags);
extern asmlinkage long sys_recvmsg(int fd, struct msghdr *msg, unsigned flags); extern asmlinkage long sys_recvmsg(int fd, struct msghdr *msg, unsigned flags);
extern asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
char *optval, int *optlen);
...@@ -295,10 +288,6 @@ extern void memcpy_tokerneliovec(struct iovec *iov, unsigned char *kdata, int le ...@@ -295,10 +288,6 @@ extern void memcpy_tokerneliovec(struct iovec *iov, unsigned char *kdata, int le
extern int move_addr_to_user(void *kaddr, int klen, void *uaddr, int *ulen); extern int move_addr_to_user(void *kaddr, int klen, void *uaddr, int *ulen);
extern int move_addr_to_kernel(void *uaddr, int ulen, void *kaddr); extern int move_addr_to_kernel(void *uaddr, int ulen, void *kaddr);
extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data); extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data);
extern int put_cmsg_compat(struct msghdr*, int level, int type, int len, void *data);
extern void cmsg_compat_recvmsg_fixup(struct msghdr *kmsg, unsigned long orig_cmsg_uptr);
extern int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg,
unsigned char *stackbuf, int stackbuf_size);
#endif #endif
#endif /* not kernel and not glibc */ #endif /* not kernel and not glibc */
......
#ifndef NET_COMPAT_H
#define NET_COMPAT_H
#include <linux/config.h>
#if defined(CONFIG_COMPAT)
#include <linux/compat.h>
struct compat_msghdr {
compat_uptr_t msg_name;
s32 msg_namelen;
compat_uptr_t msg_iov;
compat_size_t msg_iovlen;
compat_uptr_t msg_control;
compat_size_t msg_controllen;
u32 msg_flags;
};
struct compat_cmsghdr {
compat_size_t cmsg_len;
s32 cmsg_level;
s32 cmsg_type;
};
#else /* defined(CONFIG_COMPAT) */
#define compat_msghdr msghdr /* to avoid compiler warnings */
#endif /* defined(CONFIG_COMPAT) */
extern int get_compat_msghdr(struct msghdr *, struct compat_msghdr *);
extern int verify_compat_iovec(struct msghdr *, struct iovec *, char *, int);
extern asmlinkage long compat_sys_sendmsg(int,struct compat_msghdr *,unsigned);
extern asmlinkage long compat_sys_recvmsg(int,struct compat_msghdr *,unsigned);
extern asmlinkage long compat_sys_getsockopt(int, int, int, char *, int *);
extern int put_cmsg_compat(struct msghdr*, int, int, int, void *);
extern int put_compat_msg_controllen(struct msghdr *, struct compat_msghdr *,
unsigned long);
extern int cmsghdr_from_user_compat_to_kern(struct msghdr *, unsigned char *,
int);
#endif /* NET_COMPAT_H */
#ifndef NET_COMPAT_SOCKET_H
#define NET_COMPAT_SOCKET_H 1
#include <linux/compat.h>
#if defined(CONFIG_COMPAT)
/* XXX This really belongs in some header file... -DaveM */
#define MAX_SOCK_ADDR 128 /* 108 for Unix domain -
16 for IP, 16 for IPX,
24 for IPv6,
about 80 for AX.25 */
struct compat_msghdr {
u32 msg_name;
int msg_namelen;
u32 msg_iov;
compat_size_t msg_iovlen;
u32 msg_control;
compat_size_t msg_controllen;
unsigned msg_flags;
};
struct compat_cmsghdr {
compat_size_t cmsg_len;
int cmsg_level;
int cmsg_type;
};
/* Bleech... */
#define __CMSG_COMPAT_NXTHDR(ctl, len, cmsg, cmsglen) __cmsg_compat_nxthdr((ctl),(len),(cmsg),(cmsglen))
#define CMSG_COMPAT_NXTHDR(mhdr, cmsg, cmsglen) cmsg_compat_nxthdr((mhdr), (cmsg), (cmsglen))
#define CMSG_COMPAT_ALIGN(len) ( ((len)+sizeof(int)-1) & ~(sizeof(int)-1) )
#define CMSG_COMPAT_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))))
#define CMSG_COMPAT_SPACE(len) (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + CMSG_COMPAT_ALIGN(len))
#define CMSG_COMPAT_LEN(len) (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + (len))
#define __CMSG_COMPAT_FIRSTHDR(ctl,len) ((len) >= sizeof(struct compat_cmsghdr) ? \
(struct compat_cmsghdr *)(ctl) : \
(struct compat_cmsghdr *)NULL)
#define CMSG_COMPAT_FIRSTHDR(msg) __CMSG_COMPAT_FIRSTHDR((msg)->msg_control, (msg)->msg_controllen)
static __inline__ struct compat_cmsghdr *__cmsg_compat_nxthdr(void *__ctl, __kernel_size_t __size,
struct compat_cmsghdr *__cmsg, int __cmsg_len)
{
struct compat_cmsghdr * __ptr;
__ptr = (struct compat_cmsghdr *)(((unsigned char *) __cmsg) +
CMSG_COMPAT_ALIGN(__cmsg_len));
if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size)
return NULL;
return __ptr;
}
static __inline__ struct compat_cmsghdr *cmsg_compat_nxthdr (struct msghdr *__msg,
struct compat_cmsghdr *__cmsg,
int __cmsg_len)
{
return __cmsg_compat_nxthdr(__msg->msg_control, __msg->msg_controllen,
__cmsg, __cmsg_len);
}
#endif /* CONFIG_COMPAT */
#endif
This diff is collapsed.
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <net/protocol.h> #include <net/protocol.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/compat.h>
#include <net/scm.h> #include <net/scm.h>
......
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
#endif /* CONFIG_NET_RADIO */ #endif /* CONFIG_NET_RADIO */
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <net/compat_socket.h> #include <net/compat.h>
#include <net/sock.h> #include <net/sock.h>
#include <linux/netfilter.h> #include <linux/netfilter.h>
...@@ -1558,7 +1558,7 @@ asmlinkage long sys_sendmsg(int fd, struct msghdr *msg, unsigned flags) ...@@ -1558,7 +1558,7 @@ asmlinkage long sys_sendmsg(int fd, struct msghdr *msg, unsigned flags)
err = -EFAULT; err = -EFAULT;
if (MSG_CMSG_COMPAT & flags) { if (MSG_CMSG_COMPAT & flags) {
if (msghdr_from_user_compat_to_kern(&msg_sys, msg_compat)) if (get_compat_msghdr(&msg_sys, msg_compat))
return -EFAULT; return -EFAULT;
} else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr))) } else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr)))
return -EFAULT; return -EFAULT;
...@@ -1652,7 +1652,7 @@ asmlinkage long sys_recvmsg(int fd, struct msghdr *msg, unsigned int flags) ...@@ -1652,7 +1652,7 @@ asmlinkage long sys_recvmsg(int fd, struct msghdr *msg, unsigned int flags)
int *uaddr_len; int *uaddr_len;
if (MSG_CMSG_COMPAT & flags) { if (MSG_CMSG_COMPAT & flags) {
if (msghdr_from_user_compat_to_kern(&msg_sys, msg_compat)) if (get_compat_msghdr(&msg_sys, msg_compat))
return -EFAULT; return -EFAULT;
} else } else
if (copy_from_user(&msg_sys,msg,sizeof(struct msghdr))) if (copy_from_user(&msg_sys,msg,sizeof(struct msghdr)))
...@@ -1708,15 +1708,9 @@ asmlinkage long sys_recvmsg(int fd, struct msghdr *msg, unsigned int flags) ...@@ -1708,15 +1708,9 @@ asmlinkage long sys_recvmsg(int fd, struct msghdr *msg, unsigned int flags)
err = __put_user(msg_sys.msg_flags, COMPAT_FLAGS(msg)); err = __put_user(msg_sys.msg_flags, COMPAT_FLAGS(msg));
if (err) if (err)
goto out_freeiov; goto out_freeiov;
if (MSG_CMSG_COMPAT & flags) { if (MSG_CMSG_COMPAT & flags)
unsigned long ucmsg_ptr; err = put_compat_msg_controllen(&msg_sys, msg_compat, cmsg_ptr);
compat_size_t uclen; else
if((unsigned long) msg_sys.msg_control != cmsg_ptr)
cmsg_compat_recvmsg_fixup(&msg_sys, cmsg_ptr);
ucmsg_ptr = ((unsigned long)msg_sys.msg_control);
uclen = (compat_size_t) (ucmsg_ptr - cmsg_ptr);
err = __put_user(uclen, &msg_compat->msg_controllen);
} else
err = __put_user((unsigned long)msg_sys.msg_control-cmsg_ptr, err = __put_user((unsigned long)msg_sys.msg_control-cmsg_ptr,
&msg->msg_controllen); &msg->msg_controllen);
if (err) if (err)
......
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