Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 283470 (PR45286) - sigaction() on static/x86_64 sets up invalid sa_restorer field
Summary: sigaction() on static/x86_64 sets up invalid sa_restorer field
Status: RESOLVED FIXED
Alias: PR45286
Product: Gentoo Linux
Classification: Unclassified
Component: Hardened (show other bugs)
Hardware: AMD64 Linux
: High normal with 2 votes (vote)
Assignee: The Gentoo Linux Hardened Team
URL: http://gcc.gnu.org/PR45286
Whiteboard:
Keywords:
: 209979 333173 351843 383599 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-09-02 02:18 UTC by Nick
Modified: 2015-11-22 21:42 UTC (History)
10 users (show)

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


Attachments
emerge --info (emerge_info.log,4.43 KB, text/plain)
2010-03-11 22:18 UTC, Radoslaw Madej (radegand)
Details
signal.tar.bz2 (signal.tar.bz2,92.75 KB, application/octet-stream)
2010-08-14 23:46 UTC, SpanKY
Details
updated patch with the fix for sigaction (glibc-2.11-hardened-pie.patch,1.96 KB, patch)
2010-09-12 22:01 UTC, Magnus Granberg
Details | Diff
patch to give linker a hint for correct relocation info of __restore_rt (glibc-2.11.2-hardened-sigaction.patch,484 bytes, patch)
2011-01-24 23:59 UTC, vina
Details | Diff
This patch has the attachment 260620 in it. (glibc-2.12-hardened-pie.patch,2.70 KB, patch)
2011-01-31 21:44 UTC, Magnus Granberg
Details | Diff
This patch has the attachment 260620 in it. (glibc-2.12-hardened-pie.patch,2.71 KB, patch)
2011-01-31 23:06 UTC, Magnus Granberg
Details | Diff
Patch with fixed spacing (glibc-2.12-hardened-pie.patch,2.50 KB, patch)
2011-01-31 23:57 UTC, Francisco Blas Izquierdo Riera
Details | Diff
Doing things well, forgot a few details :P (glibc-2.12-hardened-pie.patch,2.53 KB, patch)
2011-01-31 23:59 UTC, Francisco Blas Izquierdo Riera
Details | Diff
fix the attribute_hidden on __restore_rt (__restore_rt_attribute_hidden.patch,652 bytes, patch)
2011-03-01 01:21 UTC, Magnus Granberg
Details | Diff
cat /var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/temp/newpatch.patch.out (file1,6.66 KB, text/plain)
2011-07-26 06:55 UTC, darin hensley
Details
emerge --info =sys-fs/cryptsetup-1.1.3-r3 (file1,4.27 KB, text/plain)
2011-07-26 06:56 UTC, darin hensley
Details
make.info, uname -a, emerge --info (file1,1.29 KB, text/plain)
2011-07-26 07:03 UTC, darin hensley
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nick 2009-09-02 02:18:22 UTC
Trying to run the following command always results in the following:

luffy ~ # /sbin/cryptsetup --cipher=aes-cbc-essiv:sha256 -s 256 luksFormat /dev/md0

WARNING!
========
This will overwrite data on /dev/md0 irrevocably.

Are you sure? (Type uppercase yes): YES
Segmentation fault (core dumped)

I have two nearly identical systems (CPU,Mobo,etc) one running gentoo-sources (phoenix) and hardened-sources (luffy). 

Reproducible: Always

Steps to Reproduce:
1. luffy ~ # /sbin/cryptsetup --cipher=aes-cbc-essiv:sha256 -s 256 luksFormat /dev/md0
2. Type "YES"
3. View segfalt

Actual Results:  
luffy ~ # /sbin/cryptsetup --cipher=aes-cbc-essiv:sha256 -s 256 luksFormat /dev/md0

WARNING!
========
This will overwrite data on /dev/md0 irrevocably.

Are you sure? (Type uppercase yes): YES
Segmentation fault (core dumped)

Expected Results:  
After answering YES it should prompt for a pass-phrase.

luffy ~ # emerge --info
Portage 2.1.6.13 (hardened/amd64, gcc-3.4.6, glibc-2.9_p20081201-r2, 2.6.28-hardened-r9 x86_64)
=================================================================
System uname: Linux-2.6.28-hardened-r9-x86_64-AMD_Phenom-tm-_9600_Quad-Core_Processor-with-gentoo-1.12.11.1
Timestamp of tree: Tue, 01 Sep 2009 07:30:02 +0000
app-shells/bash:     3.2_p39
dev-lang/python:     2.6.2-r1
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.6-r2
sys-devel/autoconf:  2.63-r1
sys-devel/automake:  1.10.2
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.27-r2
ACCEPT_KEYWORDS="amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=k8 -O2 -msse3 -pipe -ggdb"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/gconf /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-march=k8 -O2 -msse3 -pipe -ggdb"
DISTDIR="/usr/portage/distfiles"
FEATURES="distlocks fixpackages parallel-fetch protect-owned sandbox sfperms splitdebug strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://gentoo.arcticnetwork.ca/source/ http://mirror.csclub.uwaterloo.ca/gentoo-distfiles/ "
LDFLAGS="-Wl,-O1 -nopie"
MAKEOPTS="-j5"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage"
USE="acl amd64 bash-completion berkdb bzip2 cracklib crypt gnutls hardened ipv6 justify mmx nls nptl nptlonly pam pic readline sse sse2 ssl sysfs tcpd truetype urandom vim-syntax xorg zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x      ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3       trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="mouse keyboard evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" USERLAND="GNU" VIDEO_CARDS="apm ark chips cirrus cyrix dummy fbdev glint i128 intel mach64       mga neomagic nv r128 radeon rendition s3 s3virge savage siliconmotion sis       sisusb tdfx tga trident tseng v4l vesa vga via vmware voodoo"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LANG, LC_ALL, LINGUAS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PORTDIR_OVERLAY

I attempted to do a backtrace but I seem to be doing something wrong:

luffy ~ # /sbin/paxctl -m /sbin/cryptsetup
luffy ~ # /sbin/cryptsetup --cipher=aes-cbc-essiv:sha256 -s 256 luksFormat /dev/md0

WARNING!
========
This will overwrite data on /dev/md0 irrevocably.

Are you sure? (Type uppercase yes): YES
Segmentation fault (core dumped)
luffy ~ # gdb /sbin/cryptsetup --core core
GNU gdb 6.8
Copyright (C) 2008 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 "x86_64-pc-linux-gnu"...
Core was generated by `/sbin/cryptsetup --cipher=aes-cbc-essiv:sha256 -s 256 luksFormat /dev/md0'.
Program terminated with signal 11, Segmentation fault.
[New process 31962]
#0  0x000000000040baa6 in sigvtalarm (foo=26) at pbkdf.c:89
89      pbkdf.c: No such file or directory.
        in pbkdf.c
(gdb) bt full
#0  0x000000000040baa6 in sigvtalarm (foo=26) at pbkdf.c:89
No locals.
#1  0x0000000000000000 in ?? ()
No symbol table info available.
(gdb)

This doesn't really give much information and I can't figure out why symbols are not included.

luffy ~ # strace /sbin/cryptsetup --cipher=aes-cbc-essiv:sha256 -s 256 luksFormat /dev/md0
execve("/sbin/cryptsetup", ["/sbin/cryptsetup", "--cipher=aes-cbc-essiv:sha256", "-s", "256", "luksFormat", "/dev/md0"], [/* 25 vars */]) = 0
uname({sys="Linux", node="luffy", ...}) = 0
brk(0)                                  = 0x7317a0
brk(0x732710)                           = 0x732710
arch_prctl(ARCH_SET_FS, 0x732050)       = 0
open("/dev/urandom", O_RDONLY)          = 3
read(3, "q\313\2\21\237\264_\364"..., 8) = 8
close(3)                                = 0
brk(0x753710)                           = 0x753710
brk(0x754000)                           = 0x754000
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(2, "\nWARNING!\n========\n"..., 19
WARNING!
========
) = 19
write(2, "This will overwrite data on /dev/"..., 87This will overwrite data on /dev/md0 irrevocably.

Are you sure? (Type uppercase yes): ) = 87
fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x63d987ab9000
read(0, YES
"YES\n"..., 1024)               = 4
mlockall(MCL_CURRENT|MCL_FUTURE)        = 0
open("/dev/md0", O_RDWR|O_EXCL|O_SYNC|O_DIRECT) = 3
close(3)                                = 0
open("/dev/urandom", O_RDONLY)          = 3
read(3, "~G(\222[\304\177\316 t\4\247\242\10\3\262\263\324\1|d'\300\2317\252c\354\336\336\346."..., 32) = 32
read(3, "\333D\310\334\361%\250%\307uA\272\365\361LD\321_\271\312Y$\225n\215;\232D_45\333"..., 32) = 32
open("/dev/urandom", O_RDONLY)          = 4
fcntl(4, F_GETFD)                       = 0
fcntl(4, F_SETFD, FD_CLOEXEC)           = 0
getpid()                                = 31965
getuid()                                = 0
getppid()                               = 31964
read(4, "\306\277\346q\303n\246\224\2I\254i\301\0#\317"..., 16) = 16
gettid()                                = 31965
rt_sigaction(SIGVTALRM, {0x40ba60, [VTALRM], SA_RESTORER|SA_RESTART, 0xf0000000fc0c748}, {SIG_DFL, [], 0}, 8) = 0
setitimer(ITIMER_VIRTUAL, {it_interval={0, 0}, it_value={1, 0}}, NULL) = 0
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV (core dumped) +++

I emerged cryptsetup on phoenix (gentoo-sources) and created a quickpkg and emerged it on luffy (hardened-sources). This worked without issue.

phoenix ~ # emerge --info
Portage 2.1.6.13 (default/linux/amd64/2008.0, gcc-4.1.2, glibc-2.6.1-r0, 2.6.27-gentoo-r7-phoenix-b3 x86_64)
=================================================================
System uname: Linux-2.6.27-gentoo-r7-phoenix-b3-x86_64-AMD_Phenom-tm-_9600_Quad-Core_Processor-with-glibc2.2.5
Timestamp of tree: Fri, 14 Aug 2009 06:15:02 +0000
app-shells/bash:     3.2_p39
dev-lang/python:     2.4.4-r13, 2.5.2-r7
dev-python/pycrypto: 2.0.1-r6
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.63
sys-devel/automake:  1.7.9-r1, 1.9.6-r2, 1.10.2
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.27-r2
ACCEPT_KEYWORDS="amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=k8 -O2 -msse3 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/revdep-rebuild /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-march=k8 -O2 -msse3 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="distlocks fixpackages parallel-fetch protect-owned sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://gentoo.arcticnetwork.ca/source/ http://mirror.csclub.uwaterloo.ca/gentoo-distfiles/ "
LDFLAGS="-Wl,-O1"
MAKEOPTS="-j5"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local/layman/vmware"
SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage"
USE="X acl amd64 apache2 bash-completion berkdb bzip2 cli cracklib crypt dri fortran gdbm gentoo-bashcomp gif gnutls gpm gtk iconv ipv6 isdnlog jpeg mmx mp3 mudflap multilib ncurses nls nptl nptlonly openmp pam pcre perl png pppd python qt3 readline reflection session spell spl sse sse2 ssl svg sysfs tcpd tiff truetype unicode vim-syntax xorg zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" USERLAND="GNU" VIDEO_CARDS="radeonhd radeon"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LANG, LC_ALL, LINGUAS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Lenno Nagel 2009-11-09 13:03:44 UTC
Exactly the same problem here. My workaround to this was that I performed the luksFormat operation on a non-hardened system and copied the contents of the block device in it's encrypted form to my hardened system. Opening the encrypted partition works just fine on hardened.. the only issue is that formatting crashes.

ha-backup ~ # emerge --info
Portage 2.1.6.13 (hardened/linux/amd64/10.0, gcc-4.3.4, glibc-2.10.1-r0, 2.6.28-hardened-r9 x86_64)
=================================================================
System uname: Linux-2.6.28-hardened-r9-x86_64-AMD_Athlon-tm-_64_X2_Dual_Core_Processor_4000+-with-gentoo-1.12.11.1
Timestamp of tree: Mon, 09 Nov 2009 12:30:02 +0000
app-shells/bash:     4.0_p28
dev-lang/python:     2.6.2-r1
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.6-r2
sys-devel/autoconf:  2.63-r1
sys-devel/automake:  1.9.6-r2, 1.10.2
sys-devel/binutils:  2.20
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   2.2.6a
virtual/os-headers:  2.6.27-r2
ACCEPT_KEYWORDS="amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -march=k8"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-O2 -pipe -march=k8"
DISTDIR="/usr/portage/distfiles"
FEATURES="buildpkg distlocks fixpackages parallel-fetch protect-owned sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="ftp://trumpetti.atm.tut.fi/gentoo/ http://trumpetti.atm.tut.fi/gentoo/ ftp://ftp.linux.ee/pub/gentoo/distfiles/"
LDFLAGS="-Wl,-O1"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/etc/utils/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="acl amd64 berkdb bzip2 cli cracklib crypt dri gdbm gpm hardened iconv ipv6 justify mmx modules mudflap multilib ncurses nls nptl nptlonly openmp pam pcre perl pic pppd python readline reflection samba session spl sse sse2 ssl sysfs tcpd urandom usb xorg zeroconf zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" USERLAND="GNU" VIDEO_CARDS="fbdev glint intel mach64 mga neomagic nv r128 radeon savage sis tdfx trident vesa vga via vmware voodoo"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LANG, LC_ALL, LINGUAS, MAKEOPTS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 2 Lenno Nagel 2009-11-09 13:13:51 UTC
Actually, this is a duplicate of bug #163803

Check also http://bugs.gentoo.org/show_bug.cgi?id=163803#c21
Comment 3 Richard Scott 2010-01-27 11:52:44 UTC
sys-fs/cryptsetup-1.0.7-r1 doesn't segfault like sys-fs/cryptsetup-1.0.6-r2 did :-)
Comment 4 Radoslaw Madej (radegand) 2010-03-11 22:17:49 UTC
same here...it also segfaulted when adding new passphrase to an existing encrypted volume:
"cryptsetup[24273] general protection ip:414546 sp:7ce812e04d38 error:0 in cryptsetup[400000+132000]"

However, as per bug 163803 setting USE="dynamic" solved the issue!
Should this flag be enforced on hardened?
Comment 5 Radoslaw Madej (radegand) 2010-03-11 22:18:47 UTC
Created attachment 223227 [details]
emerge --info
Comment 6 Radoslaw Madej (radegand) 2010-03-13 12:49:17 UTC
(In reply to comment #4)
> 
> However, as per bug 163803 setting USE="dynamic" solved the issue!
> Should this flag be enforced on hardened?
> 
Right, there's a problem with this approach though if one's using an encrypted root partition - genkernel requires cryptsetup to be build as static in order to include it in initramfs...which require cryptsetup to be rebuild with 'static' which prevents it from being able to run (change password), which again... :(
Comment 7 Nick 2010-03-14 14:52:25 UTC
(In reply to comment #21)
> USE="dynamic" works for me too.
> 

USE="dynamic" also allows me to use luksFormat on luffy (described in the original report) but this not a viable solution for me as luffy uses an encrypted root.

I've tested both:

Test setup:

dd if=/dev/zero of=luksfs bs=1k count=10k
10240+0 records in
10240+0 records out
10485760 bytes (10 MB) copied, 0.0368618 s, 284 MB/s

losetup /dev/loop/0 luksfs

cryptsetup luksFormat /dev/loop/0

sys-fs/cryptsetup-1.0.7-r1:

This produces the following output:

cryptsetup luksFormat /dev/loop/0

WARNING!
========
This will overwrite data on /dev/loop/0 irrevocably.

Are you sure? (Type uppercase yes): YES
Segmentation fault

strace -s 4096 cryptsetup luksFormat /dev/loop/0
execve("/sbin/cryptsetup", ["cryptsetup", "luksFormat", "/dev/loop/0"], [/* 25 vars */]) = 0
uname({sys="Linux", node="luffy", ...}) = 0
brk(0)                                  = 0x2167000
brk(0x2167f90)                          = 0x2167f90
arch_prctl(ARCH_SET_FS, 0x2167890)      = 0
brk(0x2188f90)                          = 0x2188f90
brk(0x2189000)                          = 0x2189000
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(2, "\nWARNING!\n========\n", 19
WARNING!
========
)  = 19
write(2, "This will overwrite data on /dev/loop/0 irrevocably.\n\nAre you sure? (Type uppercase yes): ", 90This will overwrite data on /dev/loop/0 irrevocably.

Are you sure? (Type uppercase yes): ) = 90
fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feb0d64c000
read(0, YES
"YES\n", 1024)                  = 4
mlockall(MCL_CURRENT|MCL_FUTURE)        = 0
open("/proc/devices", O_RDONLY)         = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feb0d64b000
read(3, "Character devices:\n  1 mem\n  4 /dev/vc/0\n  4 tty\n  4 ttyS\n  5 /dev/tty\n  5 /dev/console\n  5 /dev/ptmx\n  7 vcs\n 10 misc\n 13 input\n 14 sound\n 21 sg\n 29 fb\n116 alsa\n128 ptm\n136 pts\n180 usb\n189 usb_device\n202 cpu/msr\n203 cpu/cpuid\n226 drm\n251 hidraw\n252 usbmon\n253 bsg\n254 rtc\n\nBlock devices:\n  1 ramdisk\n259 blkext\n  7 loop\n  8 sd\n  9 md\n 11 sr\n 65 sd\n 66 sd\n 67 sd\n 68 sd\n 69 sd\n 70 sd\n 71 sd\n128 sd\n129 sd\n130 sd\n131 sd\n132 sd\n133 sd\n134 sd\n135 sd\n253 device-mapper\n254 mdp\n", 1024) = 473
close(3)                                = 0
munmap(0x7feb0d64b000, 4096)            = 0
open("/proc/misc", O_RDONLY)            = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feb0d64b000
read(3, " 59 network_throughput\n 60 network_latency\n 61 cpu_dma_latency\n 62 device-mapper\n144 nvram\n228 hpet\n 63 autofs\n184 microcode\n227 mcelog\n", 1024) = 136
close(3)                                = 0
munmap(0x7feb0d64b000, 4096)            = 0
stat("/dev/mapper/control", {st_mode=S_IFCHR|0660, st_rdev=makedev(10, 62), ...}) = 0
open("/dev/mapper/control", O_RDWR)     = 3
uname({sys="Linux", node="luffy", ...}) = 0
open("/proc/devices", O_RDONLY)         = 4
fstat(4, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feb0d64b000
read(4, "Character devices:\n  1 mem\n  4 /dev/vc/0\n  4 tty\n  4 ttyS\n  5 /dev/tty\n  5 /dev/console\n  5 /dev/ptmx\n  7 vcs\n 10 misc\n 13 input\n 14 sound\n 21 sg\n 29 fb\n116 alsa\n128 ptm\n136 pts\n180 usb\n189 usb_device\n202 cpu/msr\n203 cpu/cpuid\n226 drm\n251 hidraw\n252 usbmon\n253 bsg\n254 rtc\n\nBlock devices:\n  1 ramdisk\n259 blkext\n  7 loop\n  8 sd\n  9 md\n 11 sr\n 65 sd\n 66 sd\n 67 sd\n 68 sd\n 69 sd\n 70 sd\n 71 sd\n128 sd\n129 sd\n130 sd\n131 sd\n132 sd\n133 sd\n134 sd\n135 sd\n253 device-mapper\n254 mdp\n", 1024) = 473
close(4)                                = 0
munmap(0x7feb0d64b000, 4096)            = 0
ioctl(3, DM_VERSION, 0x2168c90)         = 0
ioctl(3, DM_LIST_VERSIONS, 0x2168be0)   = 0
stat("/dev/loop/0", {st_mode=S_IFBLK|0660, st_rdev=makedev(7, 0), ...}) = 0
open("/dev/loop/0", O_RDWR|O_EXCL|O_SYNC|O_DIRECT) = 4
close(4)                                = 0
open("/dev/urandom", O_RDONLY)          = 4
read(4, "\251.\240\232!A\221\2\343_$\251\261u\177\304", 16) = 16
read(4, "\4L\267-d\234\35\275%\252$ST:\252q\tB\n\275\344\202\34\203\272\26)\23)\223\277H", 32) = 32
open("/dev/urandom", O_RDONLY)          = 5
fcntl(5, F_GETFD)                       = 0
fcntl(5, F_SETFD, FD_CLOEXEC)           = 0
getpid()                                = 19410
getuid()                                = 0
read(5, "0\21\220\204)\262\20\337\374\234\2152 \236)\235", 16) = 16
rt_sigaction(SIGVTALRM, {0x40b0c0, [VTALRM], SA_RESTORER|SA_RESTART, 0xf0000000fc0c748}, {SIG_DFL, [], 0}, 8) = 0
setitimer(ITIMER_VIRTUAL, {it_interval={0, 0}, it_value={1, 0}}, NULL) = 0
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Segmentation fault

sys-fs/cryptsetup-1.1.0:

cryptsetup luksFormat /dev/loop/0

WARNING!
========
This will overwrite data on /dev/loop/0 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Segmentation fault

strace -s 4096 cryptsetup luksFormat /dev/loop/0
execve("/sbin/cryptsetup", ["cryptsetup", "luksFormat", "/dev/loop/0"], [/* 25 vars */]) = 0
uname({sys="Linux", node="luffy", ...}) = 0
brk(0)                                  = 0x22ee000
brk(0x22eef90)                          = 0x22eef90
arch_prctl(ARCH_SET_FS, 0x22ee890)      = 0
brk(0x230ff90)                          = 0x230ff90
brk(0x2310000)                          = 0x2310000
mlockall(MCL_CURRENT|MCL_FUTURE)        = 0
getpriority(PRIO_PROCESS, 0)            = 20
setpriority(PRIO_PROCESS, 0, 4294967278) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6eb020a000
write(1, "\n", 1
)                       = 1
write(1, "WARNING!\n", 9WARNING!
)               = 9
write(1, "========\n", 9========
)               = 9
write(1, "This will overwrite data on /dev/loop/0 irrevocably.\n\n", 54This will overwrite data on /dev/loop/0 irrevocably.

) = 54
fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6eb0209000
write(1, "Are you sure? (Type uppercase yes): ", 36Are you sure? (Type uppercase yes): ) = 36
read(0, YES
"YES\n", 1024)                  = 4
stat("/dev/loop/0", {st_mode=S_IFBLK|0660, st_rdev=makedev(7, 0), ...}) = 0
open("/dev/loop/0", O_RDONLY|O_SYNC|O_DIRECT) = 3
ioctl(3, BLKSSZGET, 0x7fffed9a2604)     = 0
fstatfs(3, {f_type=0x1021994, f_bsize=4096, f_blocks=2560, f_bfree=2494, f_bavail=2494, f_files=503289, f_ffree=501259, f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
fstat(3, {st_mode=S_IFBLK|0660, st_rdev=makedev(7, 0), ...}) = 0
open("/proc/mounts", O_RDONLY)          = 4
fstat(4, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6eb0208000
read(4, "rootfs / rootfs rw 0 0\n/dev/mapper/system-root / ext3 rw,noatime,errors=continue,data=ordered 0 0\nproc /proc proc rw,nosuid,nodev,noexec,relatime 0 0\nsysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\nudev /dev tmpfs rw,nosuid,relatime,size=10240k,mode=755 0 0\ndevpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620 0 0\n/dev/mapper/system-usr /usr ext3 rw,noatime,errors=continue,data=ordered 0 0\n/dev/mapper/system-tmp /tmp ext3 rw,noatime,errors=continue,data=ordered 0 0\n/dev/mapper/system-var /var ext3 rw,noatime,errors=continue,data=ordered 0 0\n/dev/mapper/system-home /home ext3 rw,noatime,errors=continue,data=ordered 0 0\nshm /dev/shm tmpfs rw,nosuid,nodev,noexec,relatime 0 0\nusbfs /proc/bus/usb usbfs rw,nosuid,noexec,relatime,devgid=85,devmode=664 0 0\nbinfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0\n/dev/mapper/lvm0-data /data xfs rw,noatime,attr2,noquota 0 0\n/dev/mapper/backup /mnt/backup ext3 rw,relatime,errors=continue,data=ordered 0 0\n", 1024) = 1001
stat("/dev", {st_mode=S_IFDIR|0755, st_size=4000, ...}) = 0
close(4)                                = 0
munmap(0x7f6eb0208000, 4096)            = 0
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 512) = 512
close(3)                                = 0
open("/proc/devices", O_RDONLY)         = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6eb0208000
read(3, "Character devices:\n  1 mem\n  4 /dev/vc/0\n  4 tty\n  4 ttyS\n  5 /dev/tty\n  5 /dev/console\n  5 /dev/ptmx\n  7 vcs\n 10 misc\n 13 input\n 14 sound\n 21 sg\n 29 fb\n116 alsa\n128 ptm\n136 pts\n180 usb\n189 usb_device\n202 cpu/msr\n203 cpu/cpuid\n226 drm\n251 hidraw\n252 usbmon\n253 bsg\n254 rtc\n\nBlock devices:\n  1 ramdisk\n259 blkext\n  7 loop\n  8 sd\n  9 md\n 11 sr\n 65 sd\n 66 sd\n 67 sd\n 68 sd\n 69 sd\n 70 sd\n 71 sd\n128 sd\n129 sd\n130 sd\n131 sd\n132 sd\n133 sd\n134 sd\n135 sd\n253 device-mapper\n254 mdp\n", 1024) = 473
close(3)                                = 0
munmap(0x7f6eb0208000, 4096)            = 0
open("/proc/misc", O_RDONLY)            = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6eb0208000
read(3, " 59 network_throughput\n 60 network_latency\n 61 cpu_dma_latency\n 62 device-mapper\n144 nvram\n228 hpet\n 63 autofs\n184 microcode\n227 mcelog\n", 1024) = 136
close(3)                                = 0
munmap(0x7f6eb0208000, 4096)            = 0
stat("/dev/mapper/control", {st_mode=S_IFCHR|0660, st_rdev=makedev(10, 62), ...}) = 0
open("/dev/mapper/control", O_RDWR)     = 3
uname({sys="Linux", node="luffy", ...}) = 0
open("/proc/devices", O_RDONLY)         = 4
fstat(4, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6eb0208000
read(4, "Character devices:\n  1 mem\n  4 /dev/vc/0\n  4 tty\n  4 ttyS\n  5 /dev/tty\n  5 /dev/console\n  5 /dev/ptmx\n  7 vcs\n 10 misc\n 13 input\n 14 sound\n 21 sg\n 29 fb\n116 alsa\n128 ptm\n136 pts\n180 usb\n189 usb_device\n202 cpu/msr\n203 cpu/cpuid\n226 drm\n251 hidraw\n252 usbmon\n253 bsg\n254 rtc\n\nBlock devices:\n  1 ramdisk\n259 blkext\n  7 loop\n  8 sd\n  9 md\n 11 sr\n 65 sd\n 66 sd\n 67 sd\n 68 sd\n 69 sd\n 70 sd\n 71 sd\n128 sd\n129 sd\n130 sd\n131 sd\n132 sd\n133 sd\n134 sd\n135 sd\n253 device-mapper\n254 mdp\n", 1024) = 473
close(4)                                = 0
munmap(0x7f6eb0208000, 4096)            = 0
ioctl(3, DM_VERSION, 0x22f0100)         = 0
ioctl(3, DM_LIST_VERSIONS, 0x22f0050)   = 0
getuid()                                = 0
geteuid()                               = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
open("/dev/tty", O_RDWR)                = 4
ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(4, "Enter LUKS passphrase: ", 23Enter LUKS passphrase: ) = 23
ioctl(4, SNDCTL_TMR_CONTINUE or TCSETSF, {B38400 opost isig icanon -echo ...}) = 0
read(4, "test\n", 512)                  = 5
ioctl(4, SNDCTL_TMR_CONTINUE or TCSETSF, {B38400 opost isig icanon echo ...}) = 0
write(4, "\n", 1
)                       = 1
close(4)                                = 0
open("/dev/tty", O_RDWR)                = 4
ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(4, "Verify passphrase: ", 19Verify passphrase: )     = 19
ioctl(4, SNDCTL_TMR_CONTINUE or TCSETSF, {B38400 opost isig icanon -echo ...}) = 0
read(4, "test\n", 512)                  = 5
ioctl(4, SNDCTL_TMR_CONTINUE or TCSETSF, {B38400 opost isig icanon echo ...}) = 0
write(4, "\n", 1
)                       = 1
close(4)                                = 0
access("/etc/gcrypt/fips_enabled", F_OK) = -1 ENOENT (No such file or directory)
open("/proc/sys/crypto/fips_enabled", O_RDONLY) = -1 ENOENT (No such file or directory)
mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6eb0205000
getuid()                                = 0
mlock(0x7f6eb0205000, 16384)            = 0
open("/dev/urandom", O_RDONLY)          = 4
read(4, "U!\327\227\363\247%\10\360\304*0\2546\342\250\254\0233\260\6= \374\367@4\337\235\372\231\30", 32) = 32
read(4, "-3\320\270\365\307\2\24C\373(v\23Tn\357\304\223{x\244\324\276BY\203\313\36\345\262_\317", 32) = 32
rt_sigaction(SIGVTALRM, {0x411ac0, [VTALRM], SA_RESTORER|SA_RESTART, 0xf0000000fc0c748}, {SIG_DFL, [], 0}, 8) = 0
setitimer(ITIMER_VIRTUAL, {it_interval={0, 0}, it_value={1, 0}}, NULL) = 0
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Segmentation fault
Comment 8 Radoslaw Madej (radegand) 2010-03-15 20:57:46 UTC
Below are results of running cryptsetup within GDB. It segfaults in pbkdf.c:247 which is a file in the 'luks' directory in cryptsetup source. It fails in the sigvtalarm() function which does a simple (?) assignment between two variables defined at the top of the file. Both vars are defined as:
static volatile uint64_t __PBKDF2_global_j = 0;                           
static volatile uint64_t __PBKDF2_performance = 0;

GDB output:

# gdb --args /sbin/cryptsetup luksFormat /dev/sdb1
GNU gdb (Gentoo 7.1.50.20100309 vanilla) 7.1.50.20100309
Copyright (C) 2010 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 "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /sbin/cryptsetup...done.
(gdb) r
Starting program: /sbin/cryptsetup luksFormat /dev/sdb1

WARNING!
========
This will overwrite data on /dev/sdb1 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase: 
Verify passphrase: 

Program received signal SIGSEGV, Segmentation fault.
0x0000000000413936 in sigvtalarm (foo=26) at pbkdf.c:247
247     }
(gdb) bt
#0  0x0000000000413936 in sigvtalarm (foo=26) at pbkdf.c:247
#1  0x0f0000000fc0c748 in ?? ()
#2  0x0000000000000000 in ?? ()
(gdb) i r
rax            0x0      0
rbx            0x3      3
rcx            0x19     25
rdx            0x7fffffffce80   140737488342656
rsi            0x7fffffffcfb0   140737488342960
rdi            0x1a     26
rbp            0x7fffffffd490   0x7fffffffd490
rsp            0x7fffffffce78   0x7fffffffce78
r8             0x770e5140cf6b6d66       8578883678987054438
r9             0x99f93c86       2583248006
r10            0x0      0
r11            0x0      0
r12            0x7fffffffd2e0   140737488343776
r13            0xffffffff       4294967295
r14            0x1      1
r15            0x7fffffffd4e7   140737488344295
rip            0x413936 0x413936 <sigvtalarm+54>
eflags         0x10206  [ PF IF RF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x63     99
gs             0x0      0
(gdb) x/10i $rip-20
   0x413922 <sigvtalarm+34>:    mov    0x8(%rsp),%rax
   0x413927 <sigvtalarm+39>:    xor    %fs:0x28,%rax
   0x413930 <sigvtalarm+48>:    jne    0x413937 <sigvtalarm+55>
   0x413932 <sigvtalarm+50>:    add    $0x18,%rsp
=> 0x413936 <sigvtalarm+54>:    retq   
   0x413937 <sigvtalarm+55>:    callq  0x49e080 <__stack_chk_fail>
   0x41393c <PBKDF2_HMAC_ready>:        sub    $0x18,%rsp
   0x413940 <PBKDF2_HMAC_ready+4>:      mov    %fs:0x28,%rax
   0x413949 <PBKDF2_HMAC_ready+13>:     mov    %rax,0x8(%rsp)
   0x41394e <PBKDF2_HMAC_ready+18>:     xor    %eax,%eax
(gdb)

I can provide more info if needed but still no idea as to why it happens :) needs someone more knowledgeable...
Comment 9 Radoslaw Madej (radegand) 2010-03-15 22:46:52 UTC
The actual error seems to be at line 270 of the pbkdf.c file as can be observed on the gdb output below:

# gdb --args /sbin/cryptsetup luksFormat /dev/sdb1
GNU gdb (Gentoo 7.1.50.20100309 vanilla) 7.1.50.20100309
Copyright (C) 2010 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 "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /sbin/cryptsetup...done.
(gdb) b PBKDF2_performance_check
Breakpoint 1 at 0x413d45: file pbkdf.c, line 251.
(gdb) r
Starting program: /sbin/cryptsetup luksFormat /dev/sdb1

WARNING!
========
This will overwrite data on /dev/sdb1 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase: 
Verify passphrase: 

Breakpoint 1, PBKDF2_performance_check (hash=0x738c08 "sha1", iter=0x738fc0) at pbkdf.c:251
251     {
(gdb) n
256             if (__PBKDF2_global_j)
(gdb) n
259             if (!PBKDF2_HMAC_ready(hash))
(gdb) n
262             signal(SIGVTALRM,sigvtalarm);
(gdb) n
263             it.it_interval.tv_usec = 0;
(gdb) n
264             it.it_interval.tv_sec = 0;
(gdb) n
265             it.it_value.tv_usec = 0;
(gdb) n
266             it.it_value.tv_sec =  1;
(gdb) n
267             if (setitimer (ITIMER_VIRTUAL, &it, NULL) < 0)
(gdb) n
270             r = pkcs5_pbkdf2(hash, "foo", 3, "bar", 3, ~(0U), 1, &buf, 1);
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0x0000000000413936 in sigvtalarm (foo=26) at pbkdf.c:247
247     }
(gdb) bt
#0  0x0000000000413936 in sigvtalarm (foo=26) at pbkdf.c:247
#1  0x0f0000000fc0c748 in ?? ()
#2  0x0000000000000000 in ?? ()
(gdb) i r
rax            0x0      0
rbx            0x739af0 7576304
rcx            0x7fffffffd180   140737488343424
rdx            0x7fffffffce00   140737488342528
rsi            0x7fffffffcf30   140737488342832
rdi            0x1a     26
rbp            0x2      0x2
rsp            0x7fffffffcdf8   0x7fffffffcdf8
r8             0x77adc954       2007877972
r9             0xf3329947       4080179527
r10            0xa13671d0       2704699856
r11            0xdecce49        233623113
r12            0x739f88 7577480
r13            0x14     20
r14            0x1      1
r15            0x7fffffffd4e7   140737488344295
rip            0x413936 0x413936 <sigvtalarm+54>
eflags         0x10202  [ IF RF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x63     99
gs             0x0      0
(gdb) 


When compiled with USE="dynamic" it passes this instruction fine. 
Comment 10 Anthony Basile gentoo-dev 2010-08-04 22:15:12 UTC
The problem is occurring as part of the code's internal performance benchmarking of pkcs5_pbkdf2.  (This is the Password-Based Key Derivation Function RFC 2898, where many iterations are done on a passphrase to generate the derived key DK.)

The actual seg fault does occur on line 241 when calling sigvtalarm after signal(SIGVTALRM,sigvtalarm) which is set to fire after a 1 second delay.  You can avoid the seg fault by lowering the number of iteration c of pkcs5_pbkdf2 when called on line 270.  If one replaces

r = pkcs5_pbkdf2(hash, "foo", 3, "bar", 3, ~(0U), 1, &buf, 1);

with (for example)

r = pkcs5_pbkdf2(hash, "foo", 3, "bar", 3, 100000, 1, &buf, 1);

the seg fault is avoided.  Lower numbers of iterations continue to avoid the seg fault while higher number eventually hit it.  Why this is avoided when cryptsetup is dynamically linked and not statically is still unknown.  I'm also now sure what the final fix should be because messing with the benchmarking may compromise the strength of the crypto.
Comment 11 Anthony Basile gentoo-dev 2010-08-04 23:12:04 UTC
To make my previous comment clearer I wrote the following POC:

#include <signal.h>
#include <sys/time.h>

static volatile size_t global_count = 0;
static volatile size_t perf_count = 0;

static int looper( unsigned int c )
{
	unsigned int i, rc = 0 ;

	for (i = 1; i <= c; i++) {
		if (perf_count) {
			rc = i ;
			goto out;
		}
		global_count++;
	}

out:
	return rc;
}

static void sigvtalarm(int foo)
{
	perf_count = global_count;
}

int main()
{
	int r;
	struct itimerval it;

	signal(SIGVTALRM,sigvtalarm);
	it.it_interval.tv_usec = 0;
	it.it_interval.tv_sec = 0;
	it.it_value.tv_usec = 0;
	it.it_value.tv_sec =  1;
	if (setitimer (ITIMER_VIRTUAL, &it, 0) < 0)
		return  -1 ;

	r = looper( ~(0U) ) ;

	printf("perf_count = %ld\n", perf_count );
	global_count = 0;
	perf_count = 0;
	return r;
}




If we compile this with gcc-4.3.4 or gcc-4.4.4-r1 dynamic/static, we get a reproduction of the seg fault:

yellowness tmp # gcc -o signaler signaler.c 
signaler.c: In function ‘main’:
signaler.c:43: warning: incompatible implicit declaration of built-in function ‘printf’
yellowness tmp # ./signaler 
perf_count = 444770828
yellowness tmp # gcc -static -o signaler signaler.c 
signaler.c: In function ‘main’:
signaler.c:43: warning: incompatible implicit declaration of built-in function ‘printf’
yellowness tmp # ./signaler 
Segmentation fault


However, if we use vanilla gcc-4.4.3-r2 then there is no problem:

basile@gentoo-dev ~ $ gcc -o signaler signaler.c 
signaler.c: In function 'main':
signaler.c:43: warning: incompatible implicit declaration of built-in function 'printf'
signaler.c:43: warning: format '%ld' expects type 'long int', but argument 2 has type 'size_t'
basile@gentoo-dev ~ $ ./signaler 
perf_count = 436764469
basile@gentoo-dev ~ $ gcc -static -o signaler signaler.c 
signaler.c: In function 'main':
signaler.c:43: warning: incompatible implicit declaration of built-in function 'printf'
signaler.c:43: warning: format '%ld' expects type 'long int', but argument 2 has type 'size_t'
basile@gentoo-dev ~ $ ./signaler 
perf_count = 442126054

Comment 12 Anthony Basile gentoo-dev 2010-08-11 23:15:54 UTC
Actually the problem is even deeper than my previous comments.  The segfault occurs with ANY signal being caught by statically linked code.  Here's the code to demonstrate:

/*
 *	Compile either
 *		1. gcc -static -o poc poc.c
 *		2. gcc -o poc poc.c
 *
 *	When run, do kill -s 1 <pid>.  Static
 *	give seg fault, dynamic is okay.
 *
 *	Works with any signal, except non-blocking
 *	
 */

#include <signal.h>
#include <sys/types.h>
#include <unistd.h>

void sigvtalarm()
{
	printf("s\n") ;
}

int main()
{
	int i ;

	printf("My PID = %d\n", getpid() ) ;
	signal(1,sigvtalarm);
        for (i = 1; ; i++) ;
	return 0 ;
}
Comment 13 SpanKY gentoo-dev 2010-08-14 23:46:32 UTC
Created attachment 242993 [details]
signal.tar.bz2

if we look at the disassembly of __libc_sigaction in glibc and compare libc.so to libc.a, we see that the shared code (correctly) does:
  db:   48 8d 05 2e ff ff ff    lea    -0xd2(%rip),%rax   # 10 <__restore_rt>

while the static code (incorrectly) does:
  db:   48 8b 05 2e ff ff ff    mov    -0xd2(%rip),%rax   # 10 <__restore_rt>

the former will load the address of __restore_rt into %rax while the latter will load the code at the address of __restore_rt into %rax.  this is why when we look at the stack, the return address is something like:
  0x0f0000000fc0c748

this is the first 64bits of the opcodes of __restore_rt:
0000000000000010 <__restore_rt>:
  10:   48 c7 c0 0f 00 00 00    mov    $0xf,%rax
  17:   0f 05                   syscall 

so it would seem gcc is miscompiling the x86_64 sigaction.c code.  specifically, this bit of sysdeps/unix/sysv/linux/x86_64/sigaction.c:
...
extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
...
      kact.sa_restorer = &restore_rt;
...

in the attached tarball, you can find the code to reproduce this behavior.  assumption is that it is in an unpacked & configured glibc-2.11.2, but you should be able to experiment with just the .i files when compiling things by hand and looking at the output.

this happens on my system with a hardened gcc profile, not a vanilla or hardenednopie gcc profile (use gcc-config to change).  so -fpie usage seems to be key to triggering the bug.
Comment 14 Magnus Granberg gentoo-dev 2010-08-16 15:06:33 UTC
From bug PR45286
Re: #c12, the difference is because the source code is different.
In the first preprocessed source, restore_rt isn't hidden, in the latter it is.
So, in the first case (-fPIE) gcc can't assume __restore_rt is defined in the
same shared library or binary, in the latter case it can.
Shorter testcase is:
extern void foo (void) asm ("baz")
#ifdef HIDDEN
__attribute__((visibility ("hidden")))
#endif
;
void *bar (void)
{
  return &foo;
}
asm (".text; .type baz, @function; baz: nop; .previous");

-fpie vs. -fpic -DHIDDEN, the only difference is again:
-       movq    baz@GOTPCREL(%rip), %rax
+       leaq    baz(%rip), %rax

So, if there is any bug, it is either on the assembler/ld side, or on the glibc
side or user side, compiling glibc in a way it was never meant to be compiled.
Comment 15 Magnus Granberg gentoo-dev 2010-08-16 21:09:45 UTC
@vapier have you any idea what to do next?
Compile the libc.a with -fPIC insted or build it with -nopie?
Comment 16 SpanKY gentoo-dev 2010-08-19 20:08:46 UTC
*** Bug 333173 has been marked as a duplicate of this bug. ***
Comment 17 Magnus Granberg gentoo-dev 2010-09-09 14:47:38 UTC
This need to be fixed in as or glibc.
Glibc
1. Do we compile sigaction.o with -nopie
2. Split out lib*.a from the objectfiles and compile it with -nopie

Comment 18 Magnus Granberg gentoo-dev 2010-09-12 22:01:30 UTC
Created attachment 247070 [details, diff]
updated patch with the fix for sigaction

added a fix for sigaction in the hardened-pie patch
don't know if this is okey with toolchain or we need make some else fix.
Comment 19 SpanKY gentoo-dev 2010-11-19 08:33:39 UTC
*** Bug 209979 has been marked as a duplicate of this bug. ***
Comment 20 Jimmy C. Chau 2011-01-16 12:53:53 UTC
*** Bug 351843 has been marked as a duplicate of this bug. ***
Comment 21 vina 2011-01-24 23:56:32 UTC
This issue also occurred some time ago with sigalarm as in

  http://www.linuxquestions.org/questions/slackware-14/slackware-64-static-compilation-broken-803845/

For me, it showed up in July 2010 with fbsplash, being linked statically against
glibc on hardened x86_64.
The problem seems to be that the relocation information is lost when statically
binding glibc against some programs when using position independent code and
using sigalarm, which uses 64-bit instruction pointer relative adressing in a
wrong way, which is only possible for x86_64.

In sigalarm.c, the usage of
  extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
where attribute_hidden is curiously not defined, seems to imply that the symbol
does not appear in the right way on the outer interface of sigaction.o .
The problem is, that the linker does not resolve the relocation information (for
the callback of sigalarm) in the right way and produces a callback address for
the kernel syscall binding, which is no address but the move instruction at that
point (which should move the call back address to register rax).
0xffc0c748 :
  xxxxxx:       48 c7 c0 xx xx xx xx    mov    xx,%rax
  xxxxxx:       0f 05                   syscall
The linker should replace this address xx xx xx xx by the real call back address
to resume the program on return from the system call, but fails to do so.

Two ways have proven to solve the problem of wrong adressing of __restore_rt in
sigaction.c for me with hardened gentoo with pic on x86_64:
First:
    fixed replacement of
        'attribute_hidden'
    by
        '__attribute__((__visibility__("hidden")))'
Second:
    Making the symbol __restore_rt global and shown in the global offset table
    by the following patch.
Comment 22 vina 2011-01-24 23:59:06 UTC
Created attachment 260620 [details, diff]
patch to give linker a hint for correct relocation info of __restore_rt
Comment 23 Anthony Basile gentoo-dev 2011-01-30 19:18:13 UTC
(In reply to comment #22)
> Created an attachment (id=260620) [details]
> patch to give linker a hint for correct relocation info of __restore_rt
> 

Zorry and I both tested this patch and it worked.  We both tested on amd64.
Comment 24 Magnus Granberg gentoo-dev 2011-01-31 21:44:20 UTC
Created attachment 261195 [details, diff]
This patch has the attachment 260620 [details, diff] in it.

Thanks for the help and hint squeezy
Comment 25 Magnus Granberg gentoo-dev 2011-01-31 23:06:05 UTC
Created attachment 261197 [details, diff]
This patch has the attachment 260620 [details, diff] in it.

Fix some typos in the last patch.
Comment 26 Francisco Blas Izquierdo Riera gentoo-dev 2011-01-31 23:57:12 UTC
Created attachment 261199 [details, diff]
Patch with fixed spacing

The previous didn't apply due to bad spacing copypasta. This ought to fix that :D
Comment 27 Francisco Blas Izquierdo Riera gentoo-dev 2011-01-31 23:59:26 UTC
Created attachment 261200 [details, diff]
Doing things well, forgot a few details :P
Comment 28 Magnus Granberg gentoo-dev 2011-03-01 01:21:49 UTC
Created attachment 264219 [details, diff]
fix the attribute_hidden on __restore_rt

We only need one fix __attribute__((__visibility__("hidden")));
see comment 21
Comment 29 SpanKY gentoo-dev 2011-03-11 07:41:34 UTC
patch is in glibc-2.13-r2
Comment 30 darin hensley 2011-07-22 07:52:31 UTC
It is now July 2011 and sys-libs/glibc is still 2.12.2 in portage as the most recent not masked glibc. So, this problem still exist for crypt users with harden. At least for me.
Comment 31 darin hensley 2011-07-22 09:25:05 UTC
The patch that was tested on amd64 no longer works. i've used it before successfully. i don't know why it doesn't work anymore.
Comment 32 darin hensley 2011-07-22 09:26:14 UTC
localhost cryptsetup #  USE="static-libs" emerge cryptsetup

 * IMPORTANT: 2 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.


 * IMPORTANT: config file '/etc/portage/savedconfig/sys-apps/busybox-1.17.4' needs updating.
 * See the CONFIGURATION FILES section of the emerge
 * man page to learn how to update config files.
Calculating dependencies... done!

>>> Verifying ebuild manifests

>>> Emerging (1 of 1) sys-fs/cryptsetup-1.1.3-r3
 * cryptsetup-1.1.3.tar.bz2 RMD160 SHA1 SHA256 size ;-) ...              [ ok ]
 * Package:    sys-fs/cryptsetup-1.1.3-r3
 * Repository: gentoo
 * Maintainer: base-system@gentoo.org
 * USE:        amd64 elibc_glibc kernel_linux multilib nls selinux userland_GNU
 * FEATURES:   sandbox selinux sesandbox
 * Determining the location of the kernel source code
 * Found kernel source directory:
 *     /usr/src/linux
 * Found kernel object directory:
 *     /lib/modules/2.6.37-hardened-r7/build
 * Found sources for kernel version:
 *     2.6.37-hardened-r7
 * Checking for suitable kernel configuration options...                 [ ok ]
>>> Unpacking source...
>>> Unpacking cryptsetup-1.1.3.tar.bz2 to /var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/work
>>> Source unpacked in /var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/work
>>> Preparing source in /var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/work/cryptsetup-1.1.3 ...
 * Running elibtoolize in: cryptsetup-1.1.3/
 *   Applying portage-2.2.patch ...
 *   Applying sed-1.5.6.patch ...
 *   Applying as-needed-2.2.6.patch ...
 * Applying newpatch.patch ...

 * Failed Patch: newpatch.patch !
 *  ( /usr/portage/sys-fs/cryptsetup/files/newpatch.patch )
 * 
 * Include in your bugreport the contents of:
 * 
 *   /var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/temp/newpatch.patch.out

 * ERROR: sys-fs/cryptsetup-1.1.3-r3 failed (prepare phase):
 *   Failed Patch: newpatch.patch!
 * 
 * Call stack:
 *     ebuild.sh, line   56:  Called src_prepare
 *   environment, line 3475:  Called epatch '/usr/portage/sys-fs/cryptsetup/files/newpatch.patch'
 *   environment, line 1840:  Called die
 * The specific snippet of code:
 *               die "Failed Patch: ${patchname}!";
 * 
 * If you need support, post the output of 'emerge --info =sys-fs/cryptsetup-1.1.3-r3',
 * the complete build log and the output of 'emerge -pqv =sys-fs/cryptsetup-1.1.3-r3'.
 * The complete build log is located at '/var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/temp/environment'.
 * S: '/var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/work/cryptsetup-1.1.3'

>>> Failed to emerge sys-fs/cryptsetup-1.1.3-r3, Log file:

>>>  '/var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/temp/build.log'

 * Messages for package sys-fs/cryptsetup-1.1.3-r3:

 * Failed Patch: newpatch.patch !
 *  ( /usr/portage/sys-fs/cryptsetup/files/newpatch.patch )
 * 
 * Include in your bugreport the contents of:
 * 
 *   /var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/temp/newpatch.patch.out
 * ERROR: sys-fs/cryptsetup-1.1.3-r3 failed (prepare phase):
 *   Failed Patch: newpatch.patch!
 * 
 * Call stack:
 *     ebuild.sh, line   56:  Called src_prepare
 *   environment, line 3475:  Called epatch '/usr/portage/sys-fs/cryptsetup/files/newpatch.patch'
 *   environment, line 1840:  Called die
 * The specific snippet of code:
 *               die "Failed Patch: ${patchname}!";
 * 
 * If you need support, post the output of 'emerge --info =sys-fs/cryptsetup-1.1.3-r3',
 * the complete build log and the output of 'emerge -pqv =sys-fs/cryptsetup-1.1.3-r3'.
 * The complete build log is located at '/var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/temp/environment'.
 * S: '/var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/work/cryptsetup-1.1.3'

 * IMPORTANT: 2 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.

localhost cryptsetup #
Comment 33 darin hensley 2011-07-26 06:55:03 UTC
Created attachment 280985 [details]
cat /var/tmp/portage/sys-fs/cryptsetup-1.1.3-r3/temp/newpatch.patch.out
Comment 34 darin hensley 2011-07-26 06:56:51 UTC
Created attachment 280987 [details]
emerge --info =sys-fs/cryptsetup-1.1.3-r3
Comment 35 darin hensley 2011-07-26 07:03:31 UTC
Created attachment 280989 [details]
make.info, uname -a, emerge --info
Comment 36 SpanKY gentoo-dev 2011-08-11 04:26:44 UTC
this bug has nothing to do with cryptsetup.  please stop spamming that stuff.
Comment 37 darin hensley 2011-08-11 04:48:29 UTC
The original author, Nick, who filed this bug stated:
"Trying to run the following command always results in the following:

luffy ~ # /sbin/cryptsetup --cipher=aes-cbc-essiv:sha256 -s 256 luksFormat
/dev/md0

WARNING!
========
This will overwrite data on /dev/md0 irrevocably.

Are you sure? (Type uppercase yes): YES
Segmentation fault (core dumped)"



Did you not see that this was reported by Nick on 2009-09-02 02:18? Did not you see that he when filed this bug because he stated he was trying to encrypt his partition with cryptsetup and it segfaulted? 

Instead of accusing me of spamming, why not maintain this and fix it? If all you can do is accuse me of spamming in which I had the same problem as Nick just a couple of months ago, then it explains why this bug has dated back to 2009 and still has not been fixed.
Comment 38 Anthony Basile gentoo-dev 2011-08-11 09:29:40 UTC
(In reply to comment #37)
> The original author, Nick, who filed this bug stated:
> "Trying to run the following command always results in the following:
> 
> luffy ~ # /sbin/cryptsetup --cipher=aes-cbc-essiv:sha256 -s 256 luksFormat
> /dev/md0
> 
> WARNING!
> ========
> This will overwrite data on /dev/md0 irrevocably.
> 
> Are you sure? (Type uppercase yes): YES
> Segmentation fault (core dumped)"
> 
> 
> 
> Did you not see that this was reported by Nick on 2009-09-02 02:18? Did not you
> see that he when filed this bug because he stated he was trying to encrypt his
> partition with cryptsetup and it segfaulted? 
> 
> Instead of accusing me of spamming, why not maintain this and fix it? If all
> you can do is accuse me of spamming in which I had the same problem as Nick
> just a couple of months ago, then it explains why this bug has dated back to
> 2009 and still has not been fixed.

The reason you are not getting a response from the devs is because you don't understand what's going on and stubbornly refuse to listen to us.  The problem is triggered by cryptsetup, but it is in glibc.  If you look at my POC in comment 11 and comment 12, you will see *other* programs that trigger this same error.

Note that the patch is in glibc-2.13-r2 so it is fixed if you upgrade to.

Finally, stop spamming this bug.  It forces people reading it to have to waste time skipping over the useless information.
Comment 39 Anthony Basile gentoo-dev 2011-09-20 16:31:32 UTC
*** Bug 383599 has been marked as a duplicate of this bug. ***
Comment 40 Manuel Ullmann 2013-07-25 15:21:36 UTC
Current stable glibc is 2.15-r3. I can't see, why this was not closed already, as there is a fix released and all users should have received it. Am I missing something?
Comment 41 SpanKY gentoo-dev 2013-09-05 09:21:42 UTC
(In reply to Manuel Ullmann from comment #40)

the patch in the tree is a hack.  we don't know why it makes things work.  more analysis is necessary so we can find the true source of the bug.
Comment 42 Magnus Granberg gentoo-dev 2015-07-04 15:24:17 UTC
have updated the upstream bug if it works on gcc 6.x and trunk glibc.
Comment 43 Magnus Granberg gentoo-dev 2015-11-22 21:42:08 UTC
Looks like it is fixed in glibc 2.22