Date: Wed, 2 Sep 2020 16:21:28 +0000 (UTC) From: Gordon Tetlow <gordon@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-releng@freebsd.org Subject: svn commit: r365253 - in releng: 11.3/sys/compat/linux 11.4/sys/compat/linux 12.1/sys/compat/linux Message-ID: <202009021621.082GLSVd034066@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gordon Date: Wed Sep 2 16:21:27 2020 New Revision: 365253 URL: https://svnweb.freebsd.org/changeset/base/365253 Log: Fix FreeBSD Linux ABI kernel panic. Approved by: so Security: FreeBSD-EN-20:17.linuxthread Modified: releng/11.3/sys/compat/linux/linux_emul.c releng/11.4/sys/compat/linux/linux_emul.c releng/12.1/sys/compat/linux/linux_emul.c Modified: releng/11.3/sys/compat/linux/linux_emul.c ============================================================================== --- releng/11.3/sys/compat/linux/linux_emul.c Wed Sep 2 16:03:33 2020 (r365252) +++ releng/11.3/sys/compat/linux/linux_emul.c Wed Sep 2 16:21:27 2020 (r365253) @@ -261,22 +261,13 @@ linux_common_execve(struct thread *td, struct image_ar void linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp) { - struct thread *td = curthread; + struct thread *td; struct thread *othertd; #if defined(__amd64__) struct linux_pemuldata *pem; #endif - /* - * In a case of execing from Linux binary properly detach - * other threads from the user space. - */ - if (__predict_false(SV_PROC_ABI(p) == SV_ABI_LINUX)) { - FOREACH_THREAD_IN_PROC(p, othertd) { - if (td != othertd) - (p->p_sysent->sv_thread_detach)(othertd); - } - } + td = curthread; /* * In a case of execing to Linux binary we create Linux @@ -284,11 +275,32 @@ linux_proc_exec(void *arg __unused, struct proc *p, st */ if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) == SV_ABI_LINUX)) { - - if (SV_PROC_ABI(p) == SV_ABI_LINUX) + if (SV_PROC_ABI(p) == SV_ABI_LINUX) { + /* + * Process already was under Linuxolator + * before exec. Update emuldata to reflect + * single-threaded cleaned state after exec. + */ linux_proc_init(td, NULL, 0); - else + } else { + /* + * We are switching the process to Linux emulator. + */ linux_proc_init(td, td, 0); + + /* + * Create a transient td_emuldata for all suspended + * threads, so that p->p_sysent->sv_thread_detach() == + * linux_thread_detach() can find expected but unused + * emuldata. + */ + FOREACH_THREAD_IN_PROC(td->td_proc, othertd) { + if (othertd != td) { + linux_proc_init(td, othertd, + LINUX_CLONE_THREAD); + } + } + } #if defined(__amd64__) /* * An IA32 executable which has executable stack will have the Modified: releng/11.4/sys/compat/linux/linux_emul.c ============================================================================== --- releng/11.4/sys/compat/linux/linux_emul.c Wed Sep 2 16:03:33 2020 (r365252) +++ releng/11.4/sys/compat/linux/linux_emul.c Wed Sep 2 16:21:27 2020 (r365253) @@ -261,22 +261,13 @@ linux_common_execve(struct thread *td, struct image_ar void linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp) { - struct thread *td = curthread; + struct thread *td; struct thread *othertd; #if defined(__amd64__) struct linux_pemuldata *pem; #endif - /* - * In a case of execing from Linux binary properly detach - * other threads from the user space. - */ - if (__predict_false(SV_PROC_ABI(p) == SV_ABI_LINUX)) { - FOREACH_THREAD_IN_PROC(p, othertd) { - if (td != othertd) - (p->p_sysent->sv_thread_detach)(othertd); - } - } + td = curthread; /* * In a case of execing to Linux binary we create Linux @@ -284,11 +275,32 @@ linux_proc_exec(void *arg __unused, struct proc *p, st */ if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) == SV_ABI_LINUX)) { - - if (SV_PROC_ABI(p) == SV_ABI_LINUX) + if (SV_PROC_ABI(p) == SV_ABI_LINUX) { + /* + * Process already was under Linuxolator + * before exec. Update emuldata to reflect + * single-threaded cleaned state after exec. + */ linux_proc_init(td, NULL, 0); - else + } else { + /* + * We are switching the process to Linux emulator. + */ linux_proc_init(td, td, 0); + + /* + * Create a transient td_emuldata for all suspended + * threads, so that p->p_sysent->sv_thread_detach() == + * linux_thread_detach() can find expected but unused + * emuldata. + */ + FOREACH_THREAD_IN_PROC(td->td_proc, othertd) { + if (othertd != td) { + linux_proc_init(td, othertd, + LINUX_CLONE_THREAD); + } + } + } #if defined(__amd64__) /* * An IA32 executable which has executable stack will have the Modified: releng/12.1/sys/compat/linux/linux_emul.c ============================================================================== --- releng/12.1/sys/compat/linux/linux_emul.c Wed Sep 2 16:03:33 2020 (r365252) +++ releng/12.1/sys/compat/linux/linux_emul.c Wed Sep 2 16:21:27 2020 (r365253) @@ -261,22 +261,13 @@ linux_common_execve(struct thread *td, struct image_ar void linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp) { - struct thread *td = curthread; + struct thread *td; struct thread *othertd; #if defined(__amd64__) struct linux_pemuldata *pem; #endif - /* - * In a case of execing from Linux binary properly detach - * other threads from the user space. - */ - if (__predict_false(SV_PROC_ABI(p) == SV_ABI_LINUX)) { - FOREACH_THREAD_IN_PROC(p, othertd) { - if (td != othertd) - (p->p_sysent->sv_thread_detach)(othertd); - } - } + td = curthread; /* * In a case of execing to Linux binary we create Linux @@ -284,11 +275,32 @@ linux_proc_exec(void *arg __unused, struct proc *p, st */ if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) == SV_ABI_LINUX)) { - - if (SV_PROC_ABI(p) == SV_ABI_LINUX) + if (SV_PROC_ABI(p) == SV_ABI_LINUX) { + /* + * Process already was under Linuxolator + * before exec. Update emuldata to reflect + * single-threaded cleaned state after exec. + */ linux_proc_init(td, NULL, 0); - else + } else { + /* + * We are switching the process to Linux emulator. + */ linux_proc_init(td, td, 0); + + /* + * Create a transient td_emuldata for all suspended + * threads, so that p->p_sysent->sv_thread_detach() == + * linux_thread_detach() can find expected but unused + * emuldata. + */ + FOREACH_THREAD_IN_PROC(td->td_proc, othertd) { + if (othertd != td) { + linux_proc_init(td, othertd, + LINUX_CLONE_THREAD); + } + } + } #if defined(__amd64__) /* * An IA32 executable which has executable stack will have the
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202009021621.082GLSVd034066>