diff options
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/net/socket.c b/net/socket.c index 4e396312f8d5..0778c5442411 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -117,7 +117,7 @@ static ssize_t sock_sendpage(struct file *file, struct page *page, | |||
117 | * in the operation structures but are done directly via the socketcall() multiplexor. | 117 | * in the operation structures but are done directly via the socketcall() multiplexor. |
118 | */ | 118 | */ |
119 | 119 | ||
120 | static struct file_operations socket_file_ops = { | 120 | static const struct file_operations socket_file_ops = { |
121 | .owner = THIS_MODULE, | 121 | .owner = THIS_MODULE, |
122 | .llseek = no_llseek, | 122 | .llseek = no_llseek, |
123 | .aio_read = sock_aio_read, | 123 | .aio_read = sock_aio_read, |
@@ -407,24 +407,11 @@ int sock_map_fd(struct socket *sock) | |||
407 | 407 | ||
408 | static struct socket *sock_from_file(struct file *file, int *err) | 408 | static struct socket *sock_from_file(struct file *file, int *err) |
409 | { | 409 | { |
410 | struct inode *inode; | ||
411 | struct socket *sock; | ||
412 | |||
413 | if (file->f_op == &socket_file_ops) | 410 | if (file->f_op == &socket_file_ops) |
414 | return file->private_data; /* set in sock_map_fd */ | 411 | return file->private_data; /* set in sock_map_fd */ |
415 | 412 | ||
416 | inode = file->f_path.dentry->d_inode; | 413 | *err = -ENOTSOCK; |
417 | if (!S_ISSOCK(inode->i_mode)) { | 414 | return NULL; |
418 | *err = -ENOTSOCK; | ||
419 | return NULL; | ||
420 | } | ||
421 | |||
422 | sock = SOCKET_I(inode); | ||
423 | if (sock->file != file) { | ||
424 | printk(KERN_ERR "socki_lookup: socket file changed!\n"); | ||
425 | sock->file = file; | ||
426 | } | ||
427 | return sock; | ||
428 | } | 415 | } |
429 | 416 | ||
430 | /** | 417 | /** |
@@ -1527,8 +1514,9 @@ asmlinkage long sys_sendto(int fd, void __user *buff, size_t len, | |||
1527 | struct file *sock_file; | 1514 | struct file *sock_file; |
1528 | 1515 | ||
1529 | sock_file = fget_light(fd, &fput_needed); | 1516 | sock_file = fget_light(fd, &fput_needed); |
1517 | err = -EBADF; | ||
1530 | if (!sock_file) | 1518 | if (!sock_file) |
1531 | return -EBADF; | 1519 | goto out; |
1532 | 1520 | ||
1533 | sock = sock_from_file(sock_file, &err); | 1521 | sock = sock_from_file(sock_file, &err); |
1534 | if (!sock) | 1522 | if (!sock) |
@@ -1555,6 +1543,7 @@ asmlinkage long sys_sendto(int fd, void __user *buff, size_t len, | |||
1555 | 1543 | ||
1556 | out_put: | 1544 | out_put: |
1557 | fput_light(sock_file, fput_needed); | 1545 | fput_light(sock_file, fput_needed); |
1546 | out: | ||
1558 | return err; | 1547 | return err; |
1559 | } | 1548 | } |
1560 | 1549 | ||
@@ -1586,12 +1575,13 @@ asmlinkage long sys_recvfrom(int fd, void __user *ubuf, size_t size, | |||
1586 | int fput_needed; | 1575 | int fput_needed; |
1587 | 1576 | ||
1588 | sock_file = fget_light(fd, &fput_needed); | 1577 | sock_file = fget_light(fd, &fput_needed); |
1578 | err = -EBADF; | ||
1589 | if (!sock_file) | 1579 | if (!sock_file) |
1590 | return -EBADF; | 1580 | goto out; |
1591 | 1581 | ||
1592 | sock = sock_from_file(sock_file, &err); | 1582 | sock = sock_from_file(sock_file, &err); |
1593 | if (!sock) | 1583 | if (!sock) |
1594 | goto out; | 1584 | goto out_put; |
1595 | 1585 | ||
1596 | msg.msg_control = NULL; | 1586 | msg.msg_control = NULL; |
1597 | msg.msg_controllen = 0; | 1587 | msg.msg_controllen = 0; |
@@ -1610,8 +1600,9 @@ asmlinkage long sys_recvfrom(int fd, void __user *ubuf, size_t size, | |||
1610 | if (err2 < 0) | 1600 | if (err2 < 0) |
1611 | err = err2; | 1601 | err = err2; |
1612 | } | 1602 | } |
1613 | out: | 1603 | out_put: |
1614 | fput_light(sock_file, fput_needed); | 1604 | fput_light(sock_file, fput_needed); |
1605 | out: | ||
1615 | return err; | 1606 | return err; |
1616 | } | 1607 | } |
1617 | 1608 | ||
@@ -2189,7 +2180,7 @@ done: | |||
2189 | } | 2180 | } |
2190 | 2181 | ||
2191 | int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen, | 2182 | int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen, |
2192 | int flags) | 2183 | int flags) |
2193 | { | 2184 | { |
2194 | return sock->ops->connect(sock, addr, addrlen, flags); | 2185 | return sock->ops->connect(sock, addr, addrlen, flags); |
2195 | } | 2186 | } |