Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 268947 - dev-libs/cryptlib[python], dev-python/cryptlib_py breaks when compiled with optimizations
Summary: dev-libs/cryptlib[python], dev-python/cryptlib_py breaks when compiled with o...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High major (vote)
Assignee: Crypto team [DISABLED]
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-07 16:03 UTC by Davide Pesavento
Modified: 2009-10-25 15:20 UTC (History)
0 users

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


Attachments
build.log (build.log,5.64 KB, text/plain)
2009-05-08 18:09 UTC, Davide Pesavento (RETIRED)
Details
example of failing script (test.py,272 bytes, text/plain)
2009-05-17 14:04 UTC, Davide Pesavento (RETIRED)
Details
segfaulting script (testCA.py,596 bytes, text/plain)
2009-05-17 16:14 UTC, Davide Pesavento (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Davide Pesavento (RETIRED) gentoo-dev 2009-05-07 16:03:44 UTC
cryptlib_py compiles an interface module in plain C. When compiled with -O2 in CFLAGS, at runtime it breaks in very strange and hard-to-debug ways (i.e. it's completely unusable). It seems to work with -O0 and -O1.

As a workaround, I propose to replace -O{2,3} with -O1 in the ebuild.
Comment 1 Rafał Mużyło 2009-05-08 02:54:01 UTC
Could you attach the build.log ?
By chance, any strict aliasing warnings ?
Comment 2 Davide Pesavento (RETIRED) gentoo-dev 2009-05-08 17:52:26 UTC
Sorry, I was going to attach more info but I got distracted by another issue and forgot this bug completely :P

emerge --info:
Portage 2.2_rc33 (default/linux/amd64/2008.0/desktop, gcc-4.3.3, glibc-2.9_p20081201-r2, 2.6.30-rc4-g953cdaa-dirty x86_64)
=================================================================
System uname: Linux-2.6.30-rc4-g953cdaa-dirty-x86_64-Intel-R-_Core-TM-2_CPU_T7600_@_2.33GHz-with-gentoo-2.0.0
Timestamp of tree: Fri, 08 May 2009 17:15:01 +0000
ccache version 2.4 [disabled]
app-shells/bash:     4.0_p17-r1
dev-java/java-config: 2.1.7
dev-lang/python:     2.6.2
dev-util/ccache:     2.4-r8
dev-util/cmake:      2.6.4
sys-apps/baselayout: 2.0.0
sys-apps/openrc:     0.4.3-r2
sys-apps/sandbox:    1.9
sys-devel/autoconf:  2.13, 2.63-r1
sys-devel/automake:  1.5, 1.7.9-r1, 1.9.6-r2, 1.10.2
sys-devel/binutils:  2.19.1-r1
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   2.2.6a
virtual/os-headers:  2.6.28-r1
ACCEPT_KEYWORDS="amd64 ~amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=core2 -ggdb -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d 
/etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-O2 -march=core2 -ggdb -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="distlocks fixpackages parallel-fetch preserve-libs protect-owned sandbox sfperms splitdebug strict unmerge-orphans userfetch userpriv usersandbox"
GENTOO_MIRRORS="http://mirror.switch.ch/ftp/mirror/gentoo/                 ftp://ftp.unina.it/pub/linux/distributions/gentoo/"
LANG="it_IT.UTF-8"
LC_ALL="it_IT.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu"
LINGUAS="it"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_EXTRA_OPTS="--human-readable --prune-empty-dirs"
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/pesa"
SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"
USE="X a52 aac acl acpi alsa amd64 audiofile avahi bash-completion berkdb bluetooth branding bzip2 cairo caps cddb cdr cli cracklib crypt curl curlwrappers dbus dj
vu dri dts dv dvd dvdr dvdread emacs emboss encode evo exif expat fam ffmpeg fftw flac fontconfig ftp gd gdbm gif glut gmp gnutls gpm graphviz hal iconv icu idn im
agemagick imlib ipod ipv6 isdnlog jabber java5 java6 javascript jpeg jpeg2k kde lame latex lcms ldap libsamplerate lm_sensors lua lzo mad matroska midi mikmod mmap
 mmx mng mozilla mp3 mpeg mplayer mudflap multilib musepack musicbrainz ncurses networkmanager nls nptl nptlonly nsplugin offensive ogg opengl openmp pam pch pcre 
pdf plasma png policykit ppds pppd pulseaudio qt3support qt4 quicktime readline reflection rss samba sasl sdl session slang sndfile socks5 speex spell spl sqlite s
qlite3 sse sse2 ssl startup-notification svg sysfs syslog taglib tcpd theora threads tiff truetype unicode usb v4l2 vcd vorbis wmf x264 xcb xcomposite xine xineram
a xml xorg xpm xulrunner xv xvid zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel i
ntel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec95
8 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_c
ache 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="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb 
ncurses text" LINGUAS="it" USERLAND="GNU" VIDEO_CARDS="radeonhd vesa"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS
Comment 3 Davide Pesavento (RETIRED) gentoo-dev 2009-05-08 18:09:58 UTC
Created attachment 190697 [details]
build.log

Lots of "warning: passing argument X of ‘...foo...’ from incompatible pointer type".

The bindings are using an 'int *' instead of a 'Py_ssize_t *'. Python's documentation says:
"Changed in version 2.5: This function used an int * type for buffer_len. This might require changes in your code for properly supporting 64-bit systems."

[ see http://docs.python.org/c-api/objbuffer.html ]
Comment 4 Sebastian Luther (few) 2009-05-10 08:08:49 UTC
@maintainer: metadata.xml lists the herd email address under <maintainer> which
is not correct according to
http://www.gentoo.org/proj/en/devrel/handbook/handbook.xml?part=2&chap=4 .
Comment 5 Davide Pesavento (RETIRED) gentoo-dev 2009-05-10 12:04:56 UTC
A couple of examples of the brokenness...

try:
        certStore = cryptKeysetOpen(CRYPT_UNUSED, CRYPT_KEYSET_ODBC_STORE, "CACertStore", CRYPT_KEYOPT_CREATE)
except CryptException, e:
        certStore = cryptKeysetOpen(CRYPT_UNUSED, CRYPT_KEYSET_ODBC_STORE, "CACertStore", CRYPT_KEYOPT_NONE)
PKIUser = cryptCreateCert(CRYPT_UNUSED, CRYPT_CERTTYPE_PKIUSER)
cryptCAAddItem(certStore, PKIUser)
userID = PKIUser.CERTINFO_PKIUSER_ID

the last line segfaults (!)

======

privKeyContext = cryptCreateContext(CRYPT_UNUSED, CRYPT_ALGO_RSA)
privKeyContext.CTXINFO_LABEL = "foo"

Traceback (most recent call last):
 File "./test.py", line 8, in <module>
   privKeyContext.CTXINFO_LABEL = "foo"
 File "<string>", line 32, in __setattr__
cryptlib_py.CryptException: (-2, 'Bad argument, parameter 2')

======

In both cases the C equivalent works.
Comment 6 Davide Pesavento (RETIRED) gentoo-dev 2009-05-10 13:40:25 UTC
Actually, it breaks even with -O1, so optimizations must be completely disabled (-O0). Btw, this might be a gcc bug.
Comment 7 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2009-05-17 06:49:43 UTC
(In reply to comment #5)

Please attach a whole Python script.
Comment 8 Davide Pesavento (RETIRED) gentoo-dev 2009-05-17 14:04:48 UTC
Created attachment 191554 [details]
example of failing script
Comment 9 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2009-05-17 15:54:42 UTC
(In reply to comment #8)

I get:

$ ./test.py
Traceback (most recent call last):
  File "./test.py", line 9, in <module>
    privKeyContext.CTXINFO_LABEL = "foo"
  File "<string>", line 32, in __setattr__
cryptlib_py.CryptException: (-2, 'Bad argument, parameter 2')
$ 

I use dev-python/cryptlib_py-3.3.2 and dev-lang/python-2.6.2.
Comment 10 Davide Pesavento (RETIRED) gentoo-dev 2009-05-17 16:00:22 UTC
(In reply to comment #9)

Yes, I'm getting exactly the same traceback. That error doesn't make any sense, that's why I said the package is completely broken (or gcc miscompiles it). Furthermore, try to compile cryptlib_py with -O0 and see the error disappear.
Comment 11 Davide Pesavento (RETIRED) gentoo-dev 2009-05-17 16:14:08 UTC
Created attachment 191565 [details]
segfaulting script

Another example of a failing script: this one makes the whole python interpreter segfault! To reproduce you need to setup an ODBC data source named "CACertStore", I'm using the myodbc driver (dev-db/myodbc:5.1), and of course cryptlib needs to be compiled with USE="odbc".
Comment 12 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2009-10-25 15:20:50 UTC
In case of dev-libs/cryptlib-3.3.3[python], I don't get exception with script from comment #8 when -O1 was used, so I added filtering of -O2 and higher flags for Python bindings.