svn commit: r347533 - in head/sys: compat/linux modules/linux_common
Tijl Coosemans
tijl at FreeBSD.org
Sun May 19 17:05:22 UTC 2019
On Mon, 13 May 2019 17:48:16 +0000 (UTC) Dmitry Chagin
<dchagin at FreeBSD.org> wrote:
> Author: dchagin
> Date: Mon May 13 17:48:16 2019
> New Revision: 347533
> URL: https://svnweb.freebsd.org/changeset/base/347533
>
> Log:
> Our bsd_to_linux_sockaddr() and linux_to_bsd_sockaddr() functions
> alter the userspace sockaddr to convert the format between linux and BSD versions.
> That's the minimum 3 of copyin/copyout operations for one syscall.
>
> Also some syscall uses linux_sa_put() and linux_getsockaddr() when load
> sockaddr to userspace or from userspace accordingly.
>
> To avoid this chaos, especially converting sockaddr in the userspace,
> rewrite these 4 functions to convert sockaddr only in kernel and leave
> only 2 of this functions.
>
> Also in order to reduce duplication between MD parts of the Linuxulator put
> struct sockaddr conversion functions that are MI out into linux_common module.
>
> PR: 232920
> MFC after: 2 weeks
> Differential Revision: https://reviews.freebsd.org/D20157
>
> Modified:
> head/sys/compat/linux/linux.c
> head/sys/compat/linux/linux.h
> head/sys/compat/linux/linux_common.h
> head/sys/compat/linux/linux_socket.c
> head/sys/compat/linux/linux_socket.h
> head/sys/modules/linux_common/Makefile
>
> Modified: head/sys/compat/linux/linux_socket.c
> ==============================================================================
> --- head/sys/compat/linux/linux_socket.c Mon May 13 16:38:48 2019 (r347532)
> +++ head/sys/compat/linux/linux_socket.c Mon May 13 17:48:16 2019 (r347533)
> @@ -1282,6 +1110,8 @@ linux_recvmsg_common(struct thread *td, l_int s, struc
> struct mbuf *control = NULL;
> struct mbuf **controlp;
> struct timeval *ftmvl;
> + struct l_sockaddr *lsa;
> + struct sockaddr *sa;
> l_timeval ltmvl;
> caddr_t outbuf;
> void *data;
> @@ -1305,36 +1135,34 @@ linux_recvmsg_common(struct thread *td, l_int s, struc
> return (error);
>
> if (msg->msg_name) {
> - error = linux_to_bsd_sockaddr((struct sockaddr *)msg->msg_name,
> - msg->msg_namelen);
> - if (error != 0)
> - goto bad;
> + sa = malloc(msg->msg_namelen, M_SONAME, M_WAITOK);
> + msg->msg_name = sa;
> }
>
> uiov = msg->msg_iov;
> msg->msg_iov = iov;
> controlp = (msg->msg_control != NULL) ? &control : NULL;
> - error = kern_recvit(td, s, msg, UIO_USERSPACE, controlp);
> + error = kern_recvit(td, s, msg, UIO_SYSSPACE, controlp);
> msg->msg_iov = uiov;
> if (error != 0)
> goto bad;
>
> - error = bsd_to_linux_msghdr(msg, &linux_msg);
> - if (error != 0)
> - goto bad;
> -
> - if (linux_msg.msg_name) {
> - error = bsd_to_linux_sockaddr((struct sockaddr *)
> - PTRIN(linux_msg.msg_name));
> + if (sa) {
sa may be uninitialised here.
More information about the svn-src-all
mailing list