aboutsummaryrefslogtreecommitdiffstats
path: root/net/socket.c
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2012-03-11 08:51:50 -0400
committerDavid S. Miller <davem@davemloft.net>2012-03-11 22:11:22 -0400
commit43db362d3adda9e0a915ddb9a8d1a41186e19179 (patch)
tree83f00b1c09a4f54c43f94da7afb3064923415394 /net/socket.c
parent8b2aaedee4eaa94e816144ed54b9707b96be29f8 (diff)
net: get rid of some pointless casts to sockaddr
The following 4 functions: move_addr_to_kernel move_addr_to_user verify_iovec verify_compat_iovec are always effectively called with a sockaddr_storage. Make this explicit by changing their signature. This removes a large number of casts from sockaddr_storage to sockaddr. Signed-off-by: Maciej Żenczykowski <maze@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/socket.c')
-rw-r--r--net/socket.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/net/socket.c b/net/socket.c
index 28a96af484b4..12a48d846223 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -181,7 +181,7 @@ static DEFINE_PER_CPU(int, sockets_in_use);
181 * invalid addresses -EFAULT is returned. On a success 0 is returned. 181 * invalid addresses -EFAULT is returned. On a success 0 is returned.
182 */ 182 */
183 183
184int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr *kaddr) 184int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_storage *kaddr)
185{ 185{
186 if (ulen < 0 || ulen > sizeof(struct sockaddr_storage)) 186 if (ulen < 0 || ulen > sizeof(struct sockaddr_storage))
187 return -EINVAL; 187 return -EINVAL;
@@ -209,7 +209,7 @@ int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr *kaddr)
209 * specified. Zero is returned for a success. 209 * specified. Zero is returned for a success.
210 */ 210 */
211 211
212static int move_addr_to_user(struct sockaddr *kaddr, int klen, 212static int move_addr_to_user(struct sockaddr_storage *kaddr, int klen,
213 void __user *uaddr, int __user *ulen) 213 void __user *uaddr, int __user *ulen)
214{ 214{
215 int err; 215 int err;
@@ -1449,7 +1449,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
1449 1449
1450 sock = sockfd_lookup_light(fd, &err, &fput_needed); 1450 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1451 if (sock) { 1451 if (sock) {
1452 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address); 1452 err = move_addr_to_kernel(umyaddr, addrlen, &address);
1453 if (err >= 0) { 1453 if (err >= 0) {
1454 err = security_socket_bind(sock, 1454 err = security_socket_bind(sock,
1455 (struct sockaddr *)&address, 1455 (struct sockaddr *)&address,
@@ -1556,7 +1556,7 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
1556 err = -ECONNABORTED; 1556 err = -ECONNABORTED;
1557 goto out_fd; 1557 goto out_fd;
1558 } 1558 }
1559 err = move_addr_to_user((struct sockaddr *)&address, 1559 err = move_addr_to_user(&address,
1560 len, upeer_sockaddr, upeer_addrlen); 1560 len, upeer_sockaddr, upeer_addrlen);
1561 if (err < 0) 1561 if (err < 0)
1562 goto out_fd; 1562 goto out_fd;
@@ -1605,7 +1605,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
1605 sock = sockfd_lookup_light(fd, &err, &fput_needed); 1605 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1606 if (!sock) 1606 if (!sock)
1607 goto out; 1607 goto out;
1608 err = move_addr_to_kernel(uservaddr, addrlen, (struct sockaddr *)&address); 1608 err = move_addr_to_kernel(uservaddr, addrlen, &address);
1609 if (err < 0) 1609 if (err < 0)
1610 goto out_put; 1610 goto out_put;
1611 1611
@@ -1645,7 +1645,7 @@ SYSCALL_DEFINE3(getsockname, int, fd, struct sockaddr __user *, usockaddr,
1645 err = sock->ops->getname(sock, (struct sockaddr *)&address, &len, 0); 1645 err = sock->ops->getname(sock, (struct sockaddr *)&address, &len, 0);
1646 if (err) 1646 if (err)
1647 goto out_put; 1647 goto out_put;
1648 err = move_addr_to_user((struct sockaddr *)&address, len, usockaddr, usockaddr_len); 1648 err = move_addr_to_user(&address, len, usockaddr, usockaddr_len);
1649 1649
1650out_put: 1650out_put:
1651 fput_light(sock->file, fput_needed); 1651 fput_light(sock->file, fput_needed);
@@ -1677,7 +1677,7 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
1677 sock->ops->getname(sock, (struct sockaddr *)&address, &len, 1677 sock->ops->getname(sock, (struct sockaddr *)&address, &len,
1678 1); 1678 1);
1679 if (!err) 1679 if (!err)
1680 err = move_addr_to_user((struct sockaddr *)&address, len, usockaddr, 1680 err = move_addr_to_user(&address, len, usockaddr,
1681 usockaddr_len); 1681 usockaddr_len);
1682 fput_light(sock->file, fput_needed); 1682 fput_light(sock->file, fput_needed);
1683 } 1683 }
@@ -1716,7 +1716,7 @@ SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
1716 msg.msg_controllen = 0; 1716 msg.msg_controllen = 0;
1717 msg.msg_namelen = 0; 1717 msg.msg_namelen = 0;
1718 if (addr) { 1718 if (addr) {
1719 err = move_addr_to_kernel(addr, addr_len, (struct sockaddr *)&address); 1719 err = move_addr_to_kernel(addr, addr_len, &address);
1720 if (err < 0) 1720 if (err < 0)
1721 goto out_put; 1721 goto out_put;
1722 msg.msg_name = (struct sockaddr *)&address; 1722 msg.msg_name = (struct sockaddr *)&address;
@@ -1779,7 +1779,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
1779 err = sock_recvmsg(sock, &msg, size, flags); 1779 err = sock_recvmsg(sock, &msg, size, flags);
1780 1780
1781 if (err >= 0 && addr != NULL) { 1781 if (err >= 0 && addr != NULL) {
1782 err2 = move_addr_to_user((struct sockaddr *)&address, 1782 err2 = move_addr_to_user(&address,
1783 msg.msg_namelen, addr, addr_len); 1783 msg.msg_namelen, addr, addr_len);
1784 if (err2 < 0) 1784 if (err2 < 0)
1785 err = err2; 1785 err = err2;
@@ -1933,13 +1933,9 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
1933 1933
1934 /* This will also move the address data into kernel space */ 1934 /* This will also move the address data into kernel space */
1935 if (MSG_CMSG_COMPAT & flags) { 1935 if (MSG_CMSG_COMPAT & flags) {
1936 err = verify_compat_iovec(msg_sys, iov, 1936 err = verify_compat_iovec(msg_sys, iov, &address, VERIFY_READ);
1937 (struct sockaddr *)&address,
1938 VERIFY_READ);
1939 } else 1937 } else
1940 err = verify_iovec(msg_sys, iov, 1938 err = verify_iovec(msg_sys, iov, &address, VERIFY_READ);
1941 (struct sockaddr *)&address,
1942 VERIFY_READ);
1943 if (err < 0) 1939 if (err < 0)
1944 goto out_freeiov; 1940 goto out_freeiov;
1945 total_len = err; 1941 total_len = err;
@@ -2143,13 +2139,9 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
2143 uaddr = (__force void __user *)msg_sys->msg_name; 2139 uaddr = (__force void __user *)msg_sys->msg_name;
2144 uaddr_len = COMPAT_NAMELEN(msg); 2140 uaddr_len = COMPAT_NAMELEN(msg);
2145 if (MSG_CMSG_COMPAT & flags) { 2141 if (MSG_CMSG_COMPAT & flags) {
2146 err = verify_compat_iovec(msg_sys, iov, 2142 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
2147 (struct sockaddr *)&addr,
2148 VERIFY_WRITE);
2149 } else 2143 } else
2150 err = verify_iovec(msg_sys, iov, 2144 err = verify_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
2151 (struct sockaddr *)&addr,
2152 VERIFY_WRITE);
2153 if (err < 0) 2145 if (err < 0)
2154 goto out_freeiov; 2146 goto out_freeiov;
2155 total_len = err; 2147 total_len = err;
@@ -2166,7 +2158,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
2166 len = err; 2158 len = err;
2167 2159
2168 if (uaddr != NULL) { 2160 if (uaddr != NULL) {
2169 err = move_addr_to_user((struct sockaddr *)&addr, 2161 err = move_addr_to_user(&addr,
2170 msg_sys->msg_namelen, uaddr, 2162 msg_sys->msg_namelen, uaddr,
2171 uaddr_len); 2163 uaddr_len);
2172 if (err < 0) 2164 if (err < 0)