Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Jan 2018 20:27:22 +0000
From:      bugzilla-noreply@freebsd.org
To:        freebsd-bugs@FreeBSD.org
Subject:   [Bug 225105] Linux static golang binaries crash at startup
Message-ID:  <bug-225105-8-eIYuBjDNm5@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-225105-8@https.bugs.freebsd.org/bugzilla/>
References:  <bug-225105-8@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D225105

--- Comment #4 from Conrad Meyer <cem@freebsd.org> ---
(In reply to Edward Tomasz Napierala from comment #1)
I think r313993 did (sort of) introduce this bug.  I'm curious why revertin=
g it
does not fix the issue.  I think one problem may be the lack of
set_pcb_flags(pcb, PCB_FULL_IRET) in linux_set_cloned_tls().

Here's the problem: AMD64_SET_FSBASE expects a pointer to a pointer:

          case AMD64_SET_FSBASE:
                  error =3D copyin(uap->parms, &a64base, sizeof(a64base));
                  if (!error) {
                          if (a64base < VM_MAXUSER_ADDRESS) {
                                  set_pcb_flags(pcb, PCB_FULL_IRET);
                                  pcb->pcb_fsbase =3D a64base;
                                  td->td_frame->tf_fs =3D _ufssel;
                          } else
                                  error =3D EINVAL;
                  }
                  break;

linux_arch_prctl() after r313993 is just passing in the pointer value itsel=
f:

        case LINUX_ARCH_SET_FS:
                bsd_args.op =3D AMD64_SET_FSBASE;
                bsd_args.parms =3D (void *)args->addr;
                error =3D sysarch(td, &bsd_args);

Previously, it would set the value args->addr directly:


        case LINUX_ARCH_SET_FS:
                error =3D linux_set_cloned_tls(td, (void *)args->addr);
...
linux_set_cloned_tls(struct thread *td, void *desc)
{
...
        pcb =3D td->td_pcb;
        pcb->pcb_fsbase =3D (register_t)desc;


Please try this patch:

--- a/sys/amd64/linux/linux_machdep.c
+++ b/sys/amd64/linux/linux_machdep.c
@@ -234,14 +234,14 @@ linux_arch_prctl(struct thread *td, struct
linux_arch_prctl_args *args)
        switch (args->code) {
        case LINUX_ARCH_SET_GS:
                bsd_args.op =3D AMD64_SET_GSBASE;
-               bsd_args.parms =3D (void *)args->addr;
+               bsd_args.parms =3D (void *)&args->addr;
                error =3D sysarch(td, &bsd_args);
                if (error =3D=3D EINVAL)
                        error =3D EPERM;
                break;
        case LINUX_ARCH_SET_FS:
                bsd_args.op =3D AMD64_SET_FSBASE;
-               bsd_args.parms =3D (void *)args->addr;
+               bsd_args.parms =3D (void *)&args->addr;
                error =3D sysarch(td, &bsd_args);
                if (error =3D=3D EINVAL)
                        error =3D EPERM;


I would also consider changing linux_set_cloned_tls to match sysarch()
AMD64_SET_FSBASE:

@@ -271,6 +271,7 @@ linux_set_cloned_tls(struct thread *td, void *desc)
                return (EPERM);

        pcb =3D td->td_pcb;
+       set_pcb_flags(pcb, PCB_FULL_IRET);
        pcb->pcb_fsbase =3D (register_t)desc;
        td->td_frame->tf_fs =3D _ufssel;



Or better yet, just invoking sysarch() as well:

@@ -265,14 +265,13 @@ linux_arch_prctl(struct thread *td, struct
linux_arch_prctl_args *args)
 int
 linux_set_cloned_tls(struct thread *td, void *desc)
 {
-       struct pcb *pcb;
-
-       if ((uint64_t)desc >=3D VM_MAXUSER_ADDRESS)
-               return (EPERM);
-
-       pcb =3D td->td_pcb;
-       pcb->pcb_fsbase =3D (register_t)desc;
-       td->td_frame->tf_fs =3D _ufssel;
+       struct sysarch_args bsd_args;
+       int error;

-       return (0);
+       bsd_args.op =3D AMD64_SET_FSBASE;
+       bsd_args.parms =3D (void *)&desc;
+       error =3D sysarch(td, &bsd_args);
+       if (error =3D=3D EINVAL)
+               error =3D EPERM;
+       return (error);
 }

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-225105-8-eIYuBjDNm5>