Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 512762 - dev-libs/libgcrypt-1.6.1-r1[abi_x86_x32] - segmentation fault with gpg2 on x32 profile.
Summary: dev-libs/libgcrypt-1.6.1-r1[abi_x86_x32] - segmentation fault with gpg2 on x3...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Library (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Crypto team [DISABLED]
URL: https://bugs.g10code.com/gnupg/issue1676
Whiteboard:
Keywords:
: 499338 (view as bug list)
Depends on:
Blocks: x32
  Show dependency tree
 
Reported: 2014-06-08 15:53 UTC by Thibaud CANALE
Modified: 2014-08-05 10:16 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (file_512762.txt,5.73 KB, text/plain)
2014-06-08 15:53 UTC, Thibaud CANALE
Details
build.log of app-crypt/gnupg-2.0.23 (app-crypt:gnupg-2.0.23:20140608-133623.log,138.47 KB, text/x-log)
2014-06-08 15:56 UTC, Thibaud CANALE
Details
strace of the test during emerging app-crypt/gnupg-2.0.23 (gnupg-2.0.23_strace.log,10.28 KB, text/x-log)
2014-06-08 16:00 UTC, Thibaud CANALE
Details
config.log of app-crypt/gnupg-2.0.25 (app-crypt:gnupg-2.0.25_config.log,224.00 KB, text/plain)
2014-07-23 12:12 UTC, Thibaud CANALE
Details
Diff to an ebuild for libcrypt which disable assembly code. (file_512762.txt,1.39 KB, text/plain)
2014-07-23 12:51 UTC, Thibaud CANALE
Details
gdb ../../g10/gpg2, with -O0 (file_512762.txt,4.15 KB, text/plain)
2014-07-27 13:55 UTC, Thibaud CANALE
Details
libgcrypt-1.6.1-x32-compat.patch (libgcrypt-1.6.1-x32-compat.patch,724 bytes, patch)
2014-07-29 17:09 UTC, Kristian Fiskerstrand (RETIRED)
Details | Diff
/var/tmp/portage/dev-libs/libgcrypt-1.6.1-r1/work/libgcrypt-1.6.1-abi_x86_x32.x32/config.log (libgcrypt-1.6.1-abi_x86_x32.x32.config.log,98.07 KB, text/plain)
2014-07-29 19:22 UTC, Thibaud CANALE
Details
/var/tmp/portage/dev-libs/libgcrypt-1.6.1-r1/work/libgcrypt-1.6.1-abi_x86_64.amd64/config.log (libgcrypt-1.6.1-abi_x86_64.amd64.config.log,98.41 KB, text/plain)
2014-07-29 19:23 UTC, Thibaud CANALE
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thibaud CANALE 2014-06-08 15:53:52 UTC
Created attachment 378510 [details]
emerge --info

Hello,

When trying to compile app-crypt/gnupg (version 2.0.22 or 2.0.23, exact same behavior), when dev-libs/libgcrypt-1.6.1-r1 is installed (I required this version because of my system under x32 profile and therefore the need of ABI_X86), app-crypt/gnupg will fail when it is testing if the compilation is correct (see the log):


../../g10/gpg2 --homedir . --quiet --yes --no-permission-warning --import ./pubdemo.asc

gpg: signal Segmentation fault caught ... exiting


When I do a strace of the above command, I can see this:

/var/tmp/portage/app-crypt/gnupg-2.0.23/work/gnupg-2.0.23/tests/openpgp# strace ../../g10/gpg2 --homedir . --quiet --yes --no-permission-warning --import ./pubdemo.asc

../..
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xf79fb000} ---
../..

Maybe the problem is from app-crypt/gnupg, and this bug is showing us a bug in its source code.

Steps to Reproduce:
1. emerge libgcrypt with version >= 1.6.1-r1
2. re-emerge app-crypt/gnupg-2*

Reproducible:
Under x32 profile, always, but success on no-x32 profiles
Comment 1 Thibaud CANALE 2014-06-08 15:56:50 UTC
Created attachment 378512 [details]
build.log of app-crypt/gnupg-2.0.23

Build of the emerging app-crypt/gnupg-2.0.23, where we can see line 819 the test failure:

In /var/tmp/portage/app-crypt/gnupg-2.0.23/work/gnupg-2.0.23/tests/openpgp:

../../g10/gpg2 --homedir . --quiet --yes --no-permission-warning --import ./pubdemo.asc

gpg: signal Segmentation fault caught ... exiting
Comment 2 Thibaud CANALE 2014-06-08 16:00:40 UTC
Created attachment 378514 [details]
strace of the test during emerging app-crypt/gnupg-2.0.23

When emerging app-crypt/gnupg-2.0.23, the following command is executed, in /var/tmp/portage/app-crypt/gnupg-2.0.23/work/gnupg-2.0.23/tests/openpgp:


../../g10/gpg2 --homedir . --quiet --yes --no-permission-warning --import ./pubdemo.asc

but the result is a segmentation fault:
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xf79fb000} ---
Comment 3 Thibaud CANALE 2014-07-23 09:36:22 UTC
Any updates, please?

I could do a coredump, but I am not very aware of "how to do", during a compilation.
Comment 4 Thibaud CANALE 2014-07-23 12:12:59 UTC
Created attachment 381430 [details]
config.log of app-crypt/gnupg-2.0.25

/var/tmp/portage/app-crypt/gnupg-2.0.25/work/gnupg-2.0.25/config.log
Comment 5 Thibaud CANALE 2014-07-23 12:51:01 UTC
Created attachment 381434 [details]
Diff to an ebuild for libcrypt which disable assembly code.

Good news everyone!

Thanks to K_F, he discovered the problem was related to assembly code. So he made an ebuild which disable asm, see attachment.

Now app-crypt/gnupg can be compiled, and works (I didn't make a lot of test, but signing, cypehring and verifying are working).

Thanks a lot.
Comment 6 Alon Bar-Lev (RETIRED) gentoo-dev 2014-07-23 12:59:35 UTC
So x86 is not working with asm and amd64 is? Or both fail?
Comment 7 Thibaud CANALE 2014-07-23 13:02:58 UTC
(In reply to Alon Bar-Lev from comment #6)
> So x86 is not working with asm and amd64 is? Or both fail?

I am currently on x86_x32 (multilib), on my server with x86_64 (multilib), it works, but I didn't try with x86_32.

So, to be clear, it works on 64 for sure, it works on x32 with --disable-asm, no idea with 32.
Comment 8 Kristian Fiskerstrand (RETIRED) gentoo-dev 2014-07-23 13:06:55 UTC
(In reply to Alon Bar-Lev from comment #6)
> So x86 is not working with asm and amd64 is? Or both fail?

I believe x86 works as well, amd64 certainly does - note that this is x32, I haven't done any debugging as to how the detection for it is actually done in libgcrypt.

The ebuild was just a quick test to have the ability to flip asm on/off at will. It should definitely default to ON if a use flag is introduced for the behavior more generally. Alternatively disabling asm can be done for x32 similar to how it is done for darwin etc today.
Comment 9 Alon Bar-Lev (RETIRED) gentoo-dev 2014-07-23 13:09:56 UTC
disable asm is not the right solution, the root cause should be found and fixed. probably the asm code thinks it is in 64bit mode.
Comment 10 Kristian Fiskerstrand (RETIRED) gentoo-dev 2014-07-23 13:16:20 UTC
(In reply to Alon Bar-Lev from comment #9)
> disable asm is not the right solution, the root cause should be found and
> fixed. probably the asm code thinks it is in 64bit mode.

Indeed, that is my guess as well.
Comment 11 Kristian Fiskerstrand (RETIRED) gentoo-dev 2014-07-24 11:44:02 UTC
For reference I found this in the archive http://comments.gmane.org/gmane.comp.encryption.gpg.libgcrypt.devel/2611 . Seems we don't currently carry the historical patch that would allow x32 to operate. 

http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/dev-libs/libgcrypt/files/libgcrypt-1.5.0-x32.patch?hideattic=0&view=markup

See also bug 427726
Comment 12 Thibaud CANALE 2014-07-27 13:39:09 UTC
Some related bugs:

bug 506672
bug 499338
Comment 13 Thibaud CANALE 2014-07-27 13:55:15 UTC
Created attachment 381646 [details]
gdb ../../g10/gpg2, with -O0

Providing the same informations than bug 499338 comment 3.

Used -O0 when compiling.
Comment 14 Kristian Fiskerstrand (RETIRED) gentoo-dev 2014-07-29 17:09:17 UTC
Created attachment 381826 [details, diff]
libgcrypt-1.6.1-x32-compat.patch

Attaching a possible fix .
Comment 15 Alon Bar-Lev (RETIRED) gentoo-dev 2014-07-29 17:26:07 UTC
much better! :)
Comment 16 Kristian Fiskerstrand (RETIRED) gentoo-dev 2014-07-29 17:26:45 UTC
+*libgcrypt-1.6.1-r2 (29 Jul 2014)
+
+  29 Jul 2014; Kristian Fiskerstrand <k_f@gentoo.org>
+  +files/libgcrypt-1.6.1-x32-compat.patch, +libgcrypt-1.6.1-r2.ebuild:
+  Revbump to add patch to fix segfaults for x32 ABIs. Fixes bug #512762
Comment 17 Alon Bar-Lev (RETIRED) gentoo-dev 2014-07-29 17:29:46 UTC
please open upstream bug, and attach the patch.

https://bugs.g10code.com/

attach bug url to this bug.
Comment 18 Alon Bar-Lev (RETIRED) gentoo-dev 2014-07-29 18:20:13 UTC
*** Bug 499338 has been marked as a duplicate of this bug. ***
Comment 19 Kristian Fiskerstrand (RETIRED) gentoo-dev 2014-07-29 18:34:48 UTC
(In reply to Alon Bar-Lev from comment #17)
> please open upstream bug, and attach the patch.
> 
> https://bugs.g10code.com/
> 
> attach bug url to this bug.

Upstream bug: https://bugs.g10code.com/gnupg/issue1676
Comment 20 Thibaud CANALE 2014-07-29 19:22:00 UTC
Created attachment 381834 [details]
/var/tmp/portage/dev-libs/libgcrypt-1.6.1-r1/work/libgcrypt-1.6.1-abi_x86_x32.x32/config.log

Adding config.log files.

First the x32.
Comment 21 Thibaud CANALE 2014-07-29 19:23:07 UTC
Created attachment 381836 [details]
/var/tmp/portage/dev-libs/libgcrypt-1.6.1-r1/work/libgcrypt-1.6.1-abi_x86_64.amd64/config.log

and here the amd64 version.
Comment 22 Alon Bar-Lev (RETIRED) gentoo-dev 2014-07-29 19:28:45 UTC
thanks!

I think that indeed we should make the build system use the i585 in case of x32.
Comment 23 Kristian Fiskerstrand (RETIRED) gentoo-dev 2014-07-29 19:32:20 UTC
(In reply to Alon Bar-Lev from comment #22)
> thanks!
> 
> I think that indeed we should make the build system use the i585 in case of
> x32.

I'm not entirely sure that'd work, one reason being what is discussed re x32 in http://lists.x.org/archives/xorg-devel/2011-December/028164.html: 

"amd64 instruction set is not a superset of i386, otherwise __amd64__ would not exist at all.
- amd64 can't address certain "small" register forms (like %bh)
- can't encode many legacy instructions (decimal ones for example: DAA, DAS, etc.)
- can't encode many prefixes (ES, SS overrides, etc.)."

What is interesting is ""64-bit registers can be used to operate on pointers and unsigned long passed or returned in registers since the x32 calling             conversion specifies pointers and unsigned long are zero-extended 
             to 64 bits when passed or returned in registers. "
from https://sourceware.org/glibc/wiki/x32 , which is the reason the current approach makes sense.
Comment 24 Alon Bar-Lev (RETIRED) gentoo-dev 2014-07-29 19:38:54 UTC
ok, I will wait for upstream response... sorry.
Comment 25 Kristian Fiskerstrand (RETIRED) gentoo-dev 2014-08-05 10:16:43 UTC
This patch is now included upstream

http://git.gnupg.org/cgi-bin/gitweb.cgi?p=libgcrypt.git;a=commit;h=a17c29844b63e9e869f7855d901bc9d859234ead