pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg/56559: sudo and gnupg2 memory fault on Loongson/evbmips



>Number:         56559
>Category:       pkg
>Synopsis:       sudo and gnupg2 memory fault (core dumped) when run.
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 20 09:40:00 +0000 2021
>Originator:     manphiz%gmail.com@localhost
>Release:        NetBSD 8.2
>Organization:
>Environment:
System: NetBSD yeeloong-netbsd 8.2 NetBSD 8.2 (LOONGSON) #0: Tue Mar 31 05:08:40 UTC 2020 mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/evbmips/compile/LOONGSON evbmips
Architecture: mips64el
Machine: evbmips
>Description:

	Some binaries from packages built from pkgsrc on
	Loongson/evbmips system result in memory fault (core dumped).
	Examples include sudo, visudo, gpg2, etc.  When running in
	command line, e.g. /usr/pkg/bin/sudo, output looks like below:

,----
| yeeloong-netbsd# sudo
| Memory fault (core dumped)
`----

	I tried to run it in gdb, but it seems the stack is corrupted:

,----
| # gdb /usr/pkg/bin/sudo 
| GNU gdb (GDB) 7.12
| Copyright (C) 2016 Free Software Foundation, Inc.
| License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
| This is free software: you are free to change and redistribute it.
| There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
| and "show warranty" for details.
| This GDB was configured as "mips64el--netbsd".
| Type "show configuration" for configuration details.
| For bug reporting instructions, please see:
| <http://www.gnu.org/software/gdb/bugs/>.
| Find the GDB manual and other documentation resources online at:
| <http://www.gnu.org/software/gdb/documentation/>.
| For help, type "help".
| Type "apropos word" to search for commands related to "word"...
| Reading symbols from /usr/pkg/bin/sudo...(no debugging symbols found)...done.
| (gdb) r
| Starting program: /usr/pkg/bin/sudo 
| 
| Program received signal SIGSEGV, Segmentation fault.
| 0x786d40e8 in _rtld (sp=<optimized out>, relocbase=<optimized out>) at /usr/src/libexec/ld.elf_so/rtld.c:718
| 718                             if ((*real___progname = strrchr(argv[0], '/')) == NULL)
| (gdb) bt
| #0  0x786d40e8 in _rtld (sp=<optimized out>, relocbase=<optimized out>) at /usr/src/libexec/ld.elf_so/rtld.c:718
| #1  0x786d09a4 in rtld_start () from /usr/libexec/ld.elf_so
| Backtrace stopped: frame did not save the PC
`----

	I've searched around this issue, and found this discussion[1]
	which seemed to suggest this was due to GNU_RELRO and a
	default page size of 8KB.  Nick suggested in [2] that a larger
	page size may help fix this and I've experimented locally with
	similar results.

,----
| yeeloong-netbsd$ cat hello.c                                                                                                                                                           | #include <stdio.h>
| 
| int main()
| {
|         printf("Hello, world!\n");
| }
| yeeloong-netbsd$ gcc -g -Wall -Wl,-zrelro hello.c                                                                                                                                      | yeeloong-netbsd$ ./a.out                                                                                                                                                               | Memory fault (core dumped) 
| yeeloong-netbsd$ gcc -g -Wall -Wl,-zrelro -Wl,-zcommon-page-size=0x100000 hello.c 
| yeeloong-netbsd$ ./a.out                                                                                                                                                               | Hello, world!
`----

        The gdb session with the a.out produced above looks similar to
        the one with sudo, so it looks like it's the same issue.

	I tried to modify /usr/pkgsrc/mk/compiler/gcc.mk to append
	this additional linker flag to _RELRO_LDFLAGS but it didn't
	seem to work:

,----
| Index: gcc.mk
| ===================================================================
| RCS file: /cvsroot/pkgsrc/mk/compiler/gcc.mk,v
| retrieving revision 1.232
| diff -u -p -r1.232 gcc.mk
| --- gcc.mk	7 Nov 2021 11:25:33 -0000	1.232
| +++ gcc.mk	20 Dec 2021 09:23:56 -0000
| @@ -393,6 +393,10 @@ _RELRO_LDFLAGS=		-Wl,-zrelro -Wl,-znow
|  _RELRO_LDFLAGS=		-Wl,-zrelro
|  .endif
|  
| +.if !empty(MACHINE_ARCH:Mmips*)
| +_RELRO_LDFLAGS=		-Wl,-zcommon-page-size=0x800000
| +.endif
| +
|  _STACK_CHECK_CFLAGS=	-fstack-check
|  
|  .if ${_PKGSRC_USE_STACK_CHECK} == "yes"
`----

	The approach in the previous patch didn't work as expected.
	Would be great to have a real fix.


>How-To-Repeat:
	Reproducible on Loongson/evbmips.  Those programs work fine on
	an AMD64 virtual machine those.

>Fix:
	Unknown.


[1] https://mail-index.netbsd.org/port-evbmips/2016/09/11/msg000289.html
[2] https://mail-index.netbsd.org/port-evbmips/2016/09/11/msg000291.html


Home | Main Index | Thread Index | Old Index