Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 May 2019 11:30:43 +0300
From:      Dmitry Chagin <dchagin@freebsd.org>
To:        =?UTF-8?Q?T=C4=B3l_Coosemans?= <tijl@freebsd.org>
Cc:        Dmitry Chagin <dchagin@freebsd.org>, src-committers <src-committers@freebsd.org>,  svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r347533 - in head/sys: compat/linux modules/linux_common
Message-ID:  <CAC0jpUCdqYU%2BaH%2BvnOXXqH6s02cteV0M%2BpWj8XPPOfaO0ckUvQ@mail.gmail.com>
In-Reply-To: <20190519190511.6e8f436c@kalimero.tijl.coosemans.org>
References:  <201905131748.x4DHmGaH020444@repo.freebsd.org> <20190519190511.6e8f436c@kalimero.tijl.coosemans.org>

next in thread | previous in thread | raw e-mail | index | archive | help
=D0=B2=D1=81, 19 =D0=BC=D0=B0=D1=8F 2019 =D0=B3. =D0=B2 20:05, T=C4=B3l Coo=
semans <tijl@freebsd.org>:

> On Mon, 13 May 2019 17:48:16 +0000 (UTC) Dmitry Chagin
> <dchagin@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 lo=
ad
> >   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 leav=
e
> >   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_commo=
n
> 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
> >
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> > --- 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 =3D 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 =3D linux_to_bsd_sockaddr((struct sockaddr
> *)msg->msg_name,
> > -                 msg->msg_namelen);
> > -             if (error !=3D 0)
> > -                     goto bad;
> > +             sa =3D malloc(msg->msg_namelen, M_SONAME, M_WAITOK);
> > +             msg->msg_name =3D sa;
> >       }
> >
> >       uiov =3D msg->msg_iov;
> >       msg->msg_iov =3D iov;
> >       controlp =3D (msg->msg_control !=3D NULL) ? &control : NULL;
> > -     error =3D kern_recvit(td, s, msg, UIO_USERSPACE, controlp);
> > +     error =3D kern_recvit(td, s, msg, UIO_SYSSPACE, controlp);
> >       msg->msg_iov =3D uiov;
> >       if (error !=3D 0)
> >               goto bad;
> >
> > -     error =3D bsd_to_linux_msghdr(msg, &linux_msg);
> > -     if (error !=3D 0)
> > -             goto bad;
> > -
> > -     if (linux_msg.msg_name) {
> > -             error =3D bsd_to_linux_sockaddr((struct sockaddr *)
> > -                 PTRIN(linux_msg.msg_name));
> > +     if (sa) {
>
> sa may be uninitialised here.
>

yes, I see. thank you. also sa leaks if kern_recvit() returns error. will
fix



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAC0jpUCdqYU%2BaH%2BvnOXXqH6s02cteV0M%2BpWj8XPPOfaO0ckUvQ>