* invalid addresses -EFAULT is returned. On a success 0 is returned.
*/
-int move_addr_to_kernel(void __user *uaddr, int ulen, void *kaddr)
+int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr *kaddr)
{
- if (ulen < 0 || ulen > MAX_SOCK_ADDR)
+ if (ulen < 0 || ulen > sizeof(struct sockaddr_storage))
return -EINVAL;
if (ulen == 0)
return 0;
* specified. Zero is returned for a success.
*/
-int move_addr_to_user(void *kaddr, int klen, void __user *uaddr,
+int move_addr_to_user(struct sockaddr *kaddr, int klen, void __user *uaddr,
int __user *ulen)
{
int err;
return err;
if (len > klen)
len = klen;
- if (len < 0 || len > MAX_SOCK_ADDR)
+ if (len < 0 || len > sizeof(struct sockaddr_storage))
return -EINVAL;
if (len) {
if (audit_sockaddr(klen, kaddr))
asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen)
{
struct socket *sock;
- char address[MAX_SOCK_ADDR];
+ struct sockaddr_storage address;
int err, fput_needed;
sock = sockfd_lookup_light(fd, &err, &fput_needed);
if (sock) {
- err = move_addr_to_kernel(umyaddr, addrlen, address);
+ err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
if (err >= 0) {
err = security_socket_bind(sock,
- (struct sockaddr *)address,
+ (struct sockaddr *)&address,
addrlen);
if (!err)
err = sock->ops->bind(sock,
(struct sockaddr *)
- address, addrlen);
+ &address, addrlen);
}
fput_light(sock->file, fput_needed);
}
struct socket *sock, *newsock;
struct file *newfile;
int err, len, newfd, fput_needed;
- char address[MAX_SOCK_ADDR];
+ struct sockaddr_storage address;
sock = sockfd_lookup_light(fd, &err, &fput_needed);
if (!sock)
goto out_fd;
if (upeer_sockaddr) {
- if (newsock->ops->getname(newsock, (struct sockaddr *)address,
+ if (newsock->ops->getname(newsock, (struct sockaddr *)&address,
&len, 2) < 0) {
err = -ECONNABORTED;
goto out_fd;
}
- err = move_addr_to_user(address, len, upeer_sockaddr,
- upeer_addrlen);
+ err = move_addr_to_user((struct sockaddr *)&address,
+ len, upeer_sockaddr, upeer_addrlen);
if (err < 0)
goto out_fd;
}
int addrlen)
{
struct socket *sock;
- char address[MAX_SOCK_ADDR];
+ struct sockaddr_storage address;
int err, fput_needed;
sock = sockfd_lookup_light(fd, &err, &fput_needed);
if (!sock)
goto out;
- err = move_addr_to_kernel(uservaddr, addrlen, address);
+ err = move_addr_to_kernel(uservaddr, addrlen, (struct sockaddr *)&address);
if (err < 0)
goto out_put;
err =
- security_socket_connect(sock, (struct sockaddr *)address, addrlen);
+ security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
if (err)
goto out_put;
- err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen,
+ err = sock->ops->connect(sock, (struct sockaddr *)&address, addrlen,
sock->file->f_flags);
out_put:
fput_light(sock->file, fput_needed);
int __user *usockaddr_len)
{
struct socket *sock;
- char address[MAX_SOCK_ADDR];
+ struct sockaddr_storage address;
int len, err, fput_needed;
sock = sockfd_lookup_light(fd, &err, &fput_needed);
if (err)
goto out_put;
- err = sock->ops->getname(sock, (struct sockaddr *)address, &len, 0);
+ err = sock->ops->getname(sock, (struct sockaddr *)&address, &len, 0);
if (err)
goto out_put;
- err = move_addr_to_user(address, len, usockaddr, usockaddr_len);
+ err = move_addr_to_user((struct sockaddr *)&address, len, usockaddr, usockaddr_len);
out_put:
fput_light(sock->file, fput_needed);
int __user *usockaddr_len)
{
struct socket *sock;
- char address[MAX_SOCK_ADDR];
+ struct sockaddr_storage address;
int len, err, fput_needed;
sock = sockfd_lookup_light(fd, &err, &fput_needed);
}
err =
- sock->ops->getname(sock, (struct sockaddr *)address, &len,
+ sock->ops->getname(sock, (struct sockaddr *)&address, &len,
1);
if (!err)
- err = move_addr_to_user(address, len, usockaddr,
+ err = move_addr_to_user((struct sockaddr *)&address, len, usockaddr,
usockaddr_len);
fput_light(sock->file, fput_needed);
}
int addr_len)
{
struct socket *sock;
- char address[MAX_SOCK_ADDR];
+ struct sockaddr_storage address;
int err;
struct msghdr msg;
struct iovec iov;
msg.msg_controllen = 0;
msg.msg_namelen = 0;
if (addr) {
- err = move_addr_to_kernel(addr, addr_len, address);
+ err = move_addr_to_kernel(addr, addr_len, (struct sockaddr *)&address);
if (err < 0)
goto out_put;
- msg.msg_name = address;
+ msg.msg_name = (struct sockaddr *)&address;
msg.msg_namelen = addr_len;
}
if (sock->file->f_flags & O_NONBLOCK)
struct socket *sock;
struct iovec iov;
struct msghdr msg;
- char address[MAX_SOCK_ADDR];
+ struct sockaddr_storage address;
int err, err2;
int fput_needed;
msg.msg_iov = &iov;
iov.iov_len = size;
iov.iov_base = ubuf;
- msg.msg_name = address;
- msg.msg_namelen = MAX_SOCK_ADDR;
+ msg.msg_name = (struct sockaddr *)&address;
+ msg.msg_namelen = sizeof(address);
if (sock->file->f_flags & O_NONBLOCK)
flags |= MSG_DONTWAIT;
err = sock_recvmsg(sock, &msg, size, flags);
if (err >= 0 && addr != NULL) {
- err2 = move_addr_to_user(address, msg.msg_namelen, addr, addr_len);
+ err2 = move_addr_to_user((struct sockaddr *)&address,
+ msg.msg_namelen, addr, addr_len);
if (err2 < 0)
err = err2;
}
struct compat_msghdr __user *msg_compat =
(struct compat_msghdr __user *)msg;
struct socket *sock;
- char address[MAX_SOCK_ADDR];
+ struct sockaddr_storage address;
struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
unsigned char ctl[sizeof(struct cmsghdr) + 20]
__attribute__ ((aligned(sizeof(__kernel_size_t))));
/* This will also move the address data into kernel space */
if (MSG_CMSG_COMPAT & flags) {
- err = verify_compat_iovec(&msg_sys, iov, address, VERIFY_READ);
+ err = verify_compat_iovec(&msg_sys, iov,
+ (struct sockaddr *)&address,
+ VERIFY_READ);
} else
- err = verify_iovec(&msg_sys, iov, address, VERIFY_READ);
+ err = verify_iovec(&msg_sys, iov,
+ (struct sockaddr *)&address,
+ VERIFY_READ);
if (err < 0)
goto out_freeiov;
total_len = err;
int fput_needed;
/* kernel mode address */
- char addr[MAX_SOCK_ADDR];
+ struct sockaddr_storage addr;
/* user mode address pointers */
struct sockaddr __user *uaddr;
uaddr = (__force void __user *)msg_sys.msg_name;
uaddr_len = COMPAT_NAMELEN(msg);
if (MSG_CMSG_COMPAT & flags) {
- err = verify_compat_iovec(&msg_sys, iov, addr, VERIFY_WRITE);
+ err = verify_compat_iovec(&msg_sys, iov,
+ (struct sockaddr *)&addr,
+ VERIFY_WRITE);
} else
- err = verify_iovec(&msg_sys, iov, addr, VERIFY_WRITE);
+ err = verify_iovec(&msg_sys, iov,
+ (struct sockaddr *)&addr,
+ VERIFY_WRITE);
if (err < 0)
goto out_freeiov;
total_len = err;
len = err;
if (uaddr != NULL) {
- err = move_addr_to_user(addr, msg_sys.msg_namelen, uaddr,
+ err = move_addr_to_user((struct sockaddr *)&addr,
+ msg_sys.msg_namelen, uaddr,
uaddr_len);
if (err < 0)
goto out_freeiov;