From owner-freebsd-hackers@freebsd.org Sun Jun 9 20:21:13 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 875A615A9136 for ; Sun, 9 Jun 2019 20:21:13 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic310-24.consmr.mail.ne1.yahoo.com (sonic310-24.consmr.mail.ne1.yahoo.com [66.163.186.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 11F0D85297 for ; Sun, 9 Jun 2019 20:21:10 +0000 (UTC) (envelope-from marklmi@yahoo.com) X-YMail-OSG: o6ItHmQVM1kb14a9SPIsFrDISJ_9A5D8ElQEIKhiiLUH6QouRxxxogrwiZeF0bY 1YpluyU3wrKgEOEuwBZ.ABICSob4SX5Yk1wfq4QzPtEOocEaV5yvpswbwSsQb239KC9lrZ4Je2rj KZH6xFMqTPvJmL7PK8EhPXd7tq563yM.TPqdS3clXzNjgajZKQu38q7EdQozfDBkErNZFRSIJetl ZS_o7nTMilx.0OXb3cl9DGX1i7p562VQwxLzpaJdHFSuKfW77bpdFzdC6Q8UP7BHJeLOsRJC.XL1 8Z3KJJUmxWkyZtzjCLVbjr2P2kEhDU0SfzfThIAeNaep5SgZu7P1JkhDbbooAp0Hf4xi2pzG31Yr H2L8oloBVFp7ISWJTbPCq6r6ne73BOLZ7_Z9CY52lONd0DGrCfOA3KwfD6q8iWvY36P.1h5lko06 cPdR.loRwtyf.7xqEJJ4TSgBDPbhpuKgGdQ1ybY8cP_YBjlqhZhEqm3uOxjoSiMTSCtTIEZNjZVa UUCzgQRfIHUHlFaavVAZBqg3zwKcATMqEM6OwmS03rV2ZqWYUTQvR_G3TLLF0sz0jNxKSxYNdm4e inZP.gy65XkOql1Ecqcvu8S4XgEEIqNKNtZPGZpKxolkEfUx8DSPPVdoxTF6sNod69UozTd1XKPx 8kQyFjYNTcN9XCbPq8u3B1vg0KCHBgE65k34gWOgmyFvD4OtgQEHn.b8Gqxz0tgr1qO_SEUrwwA8 gDVHBUL8WRsrGtZKA8_oumgzlR_w30x4XZA3RiP1G.v4wv.kOpPvInevozthT7Qo__ZhVfNvN3VH UF6mutUv8fFNGzS3TmyqeCvL0MSkFN.QOgZ9cSrkqWNbzBe5uukSGG_kC71vDIy0c3wg_GRVpGcf Z6DQ1VGVDjt7utT3IYOj8WcWR2DdOf2qVKzwOL3hMFDWGD7iWt7oleLD_C_uW6kLB6VCtnyblTe_ a0YYdACroPGx9.vgTqdbXan.uaGprxUzpRpfqAO0pMvYvuRvkAi2CcrVUYUN0FGABPuvQ4F4iCSS eCqgsOWdNOeiVZHE2xIQxDDynsRKi00CJaMXhyogGkUT8s0_uMJ_juwW8RiiJBHfNLniXT0XdafW PQNZizO0ST2ItopzOnjkP5HNA8Z4tHkvlppMYYnpdnHjQbbPxelAGCKiW.KMGAeGkBlC4UJIsEEI BLPK_f0Sms6JLev3SIIb1YSi.hxjfTqXeArwXEM_0ws3jftk6XpcxBNYMx1iMICwXJ1IpE8AA Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Sun, 9 Jun 2019 20:21:03 +0000 Received: from c-67-170-167-181.hsd1.or.comcast.net (EHLO [192.168.1.115]) ([67.170.167.181]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 06cd87487dd4d8a17a49f1b444bcbc53; Sun, 09 Jun 2019 20:10:55 +0000 (UTC) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: crash of 32-bit powerpc -r347549 kernel built via system-clang-8, _init_tls is where the initial DIAGNOSTICS-reported SIGSEGV happens Date: Sun, 9 Jun 2019 13:10:53 -0700 References: <8F272F27-0BC3-402A-810A-4608162F9EEE@yahoo.com> <35F598E5-2400-4768-8B39-BC5F9B051443@yahoo.com> To: FreeBSD Hackers , FreeBSD PowerPC ML In-Reply-To: <35F598E5-2400-4768-8B39-BC5F9B051443@yahoo.com> Message-Id: <141293A3-0111-4E08-AA76-2F9DBBEA5A58@yahoo.com> X-Mailer: Apple Mail (2.3445.104.11) X-Rspamd-Queue-Id: 11F0D85297 X-Spamd-Bar: / X-Spamd-Result: default: False [-0.51 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ptr:yahoo.com]; MV_CASE(0.50)[]; FREEMAIL_FROM(0.00)[yahoo.com]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[yahoo.com:+]; MX_GOOD(-0.01)[cached: mta6.am0.yahoodns.net]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-0.83)[-0.833,0]; DMARC_POLICY_ALLOW(-0.50)[yahoo.com,reject]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[yahoo.com]; ASN(0.00)[asn:36646, ipnet:66.163.184.0/21, country:US]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[yahoo.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[yahoo.com:s=s2048]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-0.64)[-0.638,0]; MIME_GOOD(-0.10)[text/plain]; IP_SCORE(0.97)[ip: (2.47), ipnet: 66.163.184.0/21(1.35), asn: 36646(1.08), country: US(-0.06)]; NEURAL_SPAM_MEDIUM(0.50)[0.504,0]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[205.186.163.66.list.dnswl.org : 127.0.5.0] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Jun 2019 20:21:13 -0000 [Never mind: I found exec_setregs = /usr/src/sys/powerpc/powerpc/exec_machdep.c and were it is used.] On 2019-Jun-9, at 01:49, Mark Millard wrote: > So far I've not been able to find the code that is supposed > to establish the value of environ in /sbin/init as matching > the value of arginfo->ps_envstr from the exec_copyout_strings > use by do_execve in the kernel. >=20 > Anyone know where to point me to for what I seem to have > missed? >=20 > The issue driving the question is having the *sp++ in > _init_tls code below get SIGSEGV on 32-bit FreeBSD when > built via system-clang-8 and devel/powerpc64-binutils: >=20 > sp =3D (Elf_Addr *) environ; > while (*sp++ !=3D 0) > ; >=20 >=20 > The below is relevant detail that I've found. >=20 > _start in /sbin/init 's instance of lib/csu/powerpc/crt1.c > calls _init_tls that is from lib/libc/gen/tls.c but first > might assign to environ : >=20 > . . . > #include "ignore_init.c" > . . . > void > _start(int argc, char **argv, char **env, > const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void), > struct ps_strings *ps_strings) > { >=20 >=20 > handle_argv(argc, argv, env); >=20 > if (ps_strings !=3D (struct ps_strings *)0) > __ps_strings =3D ps_strings; >=20 > if (&_DYNAMIC !=3D NULL) > atexit(cleanup); > else > _init_tls(); >=20 > #ifdef GCRT > atexit(_mcleanup); > monstartup(&eprol, &etext); > #endif >=20 > handle_static_init(argc, argv, env); > exit(main(argc, argv, env)); > } >=20 > lib/csu/common/ignore_init.c has: >=20 > char **environ; > . . . > static inline void > handle_argv(int argc, char *argv[], char **env) > { > const char *s; >=20 > if (environ =3D=3D NULL) > environ =3D env; > if (argc > 0 && argv[0] !=3D NULL) { > __progname =3D argv[0]; > for (s =3D __progname; *s !=3D '\0'; s++) { > if (*s =3D=3D '/') > __progname =3D s + 1; > } > } > } >=20 > So _start's char**env argument might be used to assign > environ. But either way I've not managed to find the > binding to the kernel exec_copyout_strings operation. >=20 > _init_tls has the *sp++ loop that I referenced earlier: >=20 > extern char **environ; >=20 > void > _init_tls(void) > { > #ifndef PIC > Elf_Addr *sp; > Elf_Auxinfo *aux, *auxp; > Elf_Phdr *phdr; > size_t phent, phnum; > int i; > void *tls; >=20 > sp =3D (Elf_Addr *) environ; > while (*sp++ !=3D 0) > ; > . . . >=20 >=20 > On the kernel side for invoking /sbin/init is . . . >=20 > =46rom /usr/src/sys/sys/imgact.h : >=20 > struct image_args { > char *buf; /* pointer to string buffer */ > void *bufkva; /* cookie for string buffer KVA */ > char *begin_argv; /* beginning of argv in buf */ > char *begin_envv; /* (interal use only) beginning of envv = in buf, > * access with = exec_args_get_begin_envv(). */ > char *endp; /* current `end' pointer of arg & env = strings */ > char *fname; /* pointer to filename of executable = (system space) */ > char *fname_buf; /* pointer to optional malloc(M_TEMP) = buffer */ > int stringspace; /* space left in arg & env buffer */ > int argc; /* count of argument strings */ > int envc; /* count of environment strings */ > int fd; /* file descriptor of the executable */ > struct filedesc *fdp; /* new file descriptor table */ > }; >=20 > do_execve from sys/kern/kern_exec.c has use, including envc > but avoiding begin_envv (via starting from begin_argv): >=20 > static int > do_execve(struct thread *td, struct image_args *args, struct mac = *mac_p) > { > . . . > /* > * Copy out strings (args and env) and initialize stack base. > */ > stack_base =3D (*p->p_sysent->sv_copyout_strings)(imgp); >=20 >=20 > The exec_copyout_strings code (accessed via ->sv_copyout_strings) > does >=20 > stack_base =3D (register_t *)vectp; >=20 > stringp =3D imgp->args->begin_argv; > argc =3D imgp->args->argc; > envc =3D imgp->args->envc; > . . . >=20 > /* a null vector table pointer separates the argp's from the = envp's */ > suword(vectp++, 0); >=20 > suword(&arginfo->ps_envstr, (long)(intptr_t)vectp); > suword32(&arginfo->ps_nenvstr, envc); >=20 > /* > * Fill in environment portion of vector table. > */ > for (; envc > 0; --envc) { > suword(vectp++, (long)(intptr_t)destp); > while (*stringp++ !=3D 0) > destp++; > destp++; > } >=20 > /* end of vector table is a null pointer */ > suword(vectp, 0); > . . . >=20 > (=46rom what I've seen for /sbin/init being invoked, envc=3D=3D0 .) >=20 > The use involves struct ps_strings from /usr/src/sys/sys/exec.h : >=20 > struct ps_strings { > char **ps_argvstr; /* first of 0 or more argument strings = */ > unsigned int ps_nargvstr; /* the number of argument strings */ > char **ps_envstr; /* first of 0 or more environment = strings */ > unsigned int ps_nenvstr; /* the number of environment strings = */ > }; >=20 >=20 > The initialization of the begin_envv and envc for much of > the code seems to trace back to: >=20 > static void > start_init(void *dummy) > { > struct image_args args; > . . . > while ((path =3D strsep(&tmp_init_path, ":")) !=3D NULL) { > if (bootverbose) > printf("start_init: trying %s\n", path); >=20 > memset(&args, 0, sizeof(args)); > . . . I found it: /usr/src/sys/powerpc/powerpc/exec_machdep.c has exec_setregs that is accessed (via sv_setregs). This sets up arguments for _start . =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)