Module: xenomai-3
Branch: next
Commit: 0ecd81230effbd292bfe45efee5e6d563439f00d
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=0ecd81230effbd292bfe45efee5e6d563439f00d

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Dec  6 13:17:20 2017 +0100

net/tcp: recvmsg: remove direct references to user memory

---

 kernel/drivers/net/stack/ipv4/tcp/tcp.c |   45 +++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c 
b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index f01399d..6c1f38d 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -1668,7 +1668,7 @@ static int rt_tcp_accept(struct tcp_socket *ts, struct 
sockaddr *addr,
     ts->is_accepted = 1;
     rtdm_lock_put_irqrestore(&ts->socket_lock, context);
 
-    ret = rt_socket_fd(&ts->sock)->fd;
+    //    ret = rt_socket_fd(&ts->sock)->fd;
 
  err:
     /* it is not critical to leave this unlocked
@@ -2069,20 +2069,43 @@ static ssize_t rt_tcp_write(struct rtdm_fd *fd, const 
void *buf, size_t nbyte)
  */
 static ssize_t rt_tcp_recvmsg(struct rtdm_fd *fd, struct user_msghdr *msg, int 
msg_flags)
 {
-    size_t len;
-    void *buf;
+       struct iovec iov_fast[RTDM_IOV_FASTMAX], *iov;
+       struct user_msghdr _msg;
+       ssize_t ret;
+       size_t len;
+       void *buf;
 
-    if (msg_flags)
-       return -EOPNOTSUPP;
+       if (msg_flags)
+               return -EOPNOTSUPP;
 
-    /* loop over all vectors to be implemented */
-    if (msg->msg_iovlen != 1)
-       return -EOPNOTSUPP;
+       msg = rtnet_get_arg(fd, &_msg, msg, sizeof(*msg));
+       if (IS_ERR(msg))
+               return PTR_ERR(msg);
 
-    len = msg->msg_iov[0].iov_len;
-    buf = msg->msg_iov[0].iov_base;
+       /* loop over all vectors to be implemented */
+       if (msg->msg_iovlen != 1)
+               return -EOPNOTSUPP;
+
+       ret = rtdm_get_iovec(fd, &iov, msg, iov_fast);
+       if (ret)
+               return ret;
 
-    return rt_tcp_read(fd, buf, len);
+       len = iov[0].iov_len;
+       if (len > 0) {
+               buf = xnmalloc(len);
+               if (buf == NULL) {
+                       ret = -ENOMEM;
+                       goto out;
+               }
+               ret = rtdm_copy_from_user(fd, buf, iov[0].iov_base, len);
+               if (!ret)
+                       ret = rt_tcp_read(fd, buf, len);
+               xnfree(buf);
+       }
+out:
+       rtdm_drop_iovec(iov, iov_fast);
+
+       return ret;
 }
 
 /***


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to