Created attachment 223712 [details] fbsd-fork-dbreg.c It seems that when a process forks, the new child process inherits debug registers from the parent. Not sure if this is desirable but it's certainly different than e.g. Linux and NetBSD do (both clear dbregs in the new process). This currently breaks e.g. GDB that doesn't account for this. If the process has any watchpoints set before forking, the watchpoints leak to child process when it's being detached, and it crashes with SIGTRAP afterwards. I'm attaching yet another variant of my cheap reproducer script™. It sets dbreg on the parent process before fork, and then reads dbreg from the child after fork. The results I get are: dr0 = 0x204690 // set in parent process dr7 = 00000013 dr0 = 0x204690 // read in child process dr7 = 00000413
See https://reviews.freebsd.org/D29496 In particular, please note the question in the follow-up, about behavior for the new thread.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=8223717ce62c1ad0becc34ce69fe2d1771f3ba05 commit 8223717ce62c1ad0becc34ce69fe2d1771f3ba05 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-03-30 15:40:02 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-03-30 23:07:35 +0000 x86: clear %db registers in new process Reported by: MichaŠGórny <mgorny@gentoo.org> PR: 254661 Reviewed by: emaste, jhb MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D29496 sys/amd64/amd64/vm_machdep.c | 8 ++++++++ sys/i386/i386/vm_machdep.c | 8 ++++++++ 2 files changed, 16 insertions(+)
I haven't tested but could you double-check whether the same problem doesn't affect arm64?
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=5524122ee3b78b3a9bba1d0a0d9b8ac080a8e6d8 commit 5524122ee3b78b3a9bba1d0a0d9b8ac080a8e6d8 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-03-30 15:40:02 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-04-06 00:47:34 +0000 x86: clear %db registers in new process PR: 254661 (cherry picked from commit 8223717ce62c1ad0becc34ce69fe2d1771f3ba05) sys/amd64/amd64/vm_machdep.c | 8 ++++++++ sys/i386/i386/vm_machdep.c | 8 ++++++++ 2 files changed, 16 insertions(+)
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=1fd001db9c330f133708f3c04c8852f8b07cfed9 commit 1fd001db9c330f133708f3c04c8852f8b07cfed9 Author: Mitchell Horne <mhorne@FreeBSD.org> AuthorDate: 2021-04-07 19:23:46 +0000 Commit: Mitchell Horne <mhorne@FreeBSD.org> CommitDate: 2021-04-08 12:41:41 +0000 arm64: clear debug register state on fork Following the analogous change for amd64 and i386 in 8223717ce62c, ensure that new processes start with these registers inactive. PR: 254661 Reported by: MichaŠGórny Reviewed by: kib, emaste MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29630 sys/arm64/arm64/vm_machdep.c | 3 +++ 1 file changed, 3 insertions(+)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=17b0a38d96feb77d4b019ab9108b2c5050273823 commit 17b0a38d96feb77d4b019ab9108b2c5050273823 Author: Mitchell Horne <mhorne@FreeBSD.org> AuthorDate: 2021-04-07 19:23:46 +0000 Commit: Mitchell Horne <mhorne@FreeBSD.org> CommitDate: 2021-04-16 13:47:32 +0000 arm64: clear debug register state on fork Following the analogous change for amd64 and i386 in 8223717ce62c, ensure that new processes start with these registers inactive. PR: 254661 Reported by: MichaŠGórny Reviewed by: kib, emaste Sponsored by: The FreeBSD Foundation (cherry picked from commit 1fd001db9c330f133708f3c04c8852f8b07cfed9) sys/arm64/arm64/vm_machdep.c | 3 +++ 1 file changed, 3 insertions(+)
^Triage: assign to committer that resolved.