Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 364667 - sys-power/nvclock - -O(N>0) in src/backend/ generates faulty code
Summary: sys-power/nvclock - -O(N>0) in src/backend/ generates faulty code
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High normal
Assignee: No maintainer - Look at https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers if you want to take care of it
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-24 14:41 UTC by Diego Elio Pettenò (RETIRED)
Modified: 2013-10-12 21:10 UTC (History)
1 user (show)

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


Attachments
Build log (nvclock-0.8_p20110102-r1:20110424-083751.log,18.61 KB, text/plain)
2011-04-24 14:41 UTC, Diego Elio Pettenò (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Diego Elio Pettenò (RETIRED) gentoo-dev 2011-04-24 14:41:35 UTC
Created attachment 271005 [details]
Build log

I don't know the build system for this program (and this is a generic bug template so I cannot tell you which program exactly is), but my tests shows that it's not respecting CFLAGS (or CXXFLAGS) properly.

Please look into it, since it's important to respect user CFLAGS and CXXFLAGS.

Warning: this bug might look like a false positive because you actually have your CFLAGS being used; this happens if the CFLAGS are "set in stone" in the build system during src_unpack/src_prepare. While QA has not as of this moment expressed to me a preference, I'd sincerely suggest to avoid the set-in-stone approach, so that ebuild commands could work to reproduce the actual results.

To avoid the set in stone approach:

- consider just changing CFLAGS= to CFLAGS+= if the build system enables warnings;
- if the buildsystem does not use CFLAGS variable at all, in the sed use '$(CFLAGS)', single quoted, so that the CFLAGS variable is picked up;
- use '$(OPTCFLAGS)' in the sed and then use make OPTCFLAGS=$CFLAGS.

Thanks,
Diego
Comment 1 Jeroen Roovers (RETIRED) gentoo-dev 2011-04-25 03:04:57 UTC
This is about the backend subdir. When I allow that to build with -ON>0 :

jeroen@astrid ~ $ /var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk 
*** buffer overflow detected ***: /var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x50)[0xb71885f0]
/lib/libc.so.6(+0xe25ba)[0xb71865ba]
/lib/libc.so.6(+0xe1c88)[0xb7185c88]
/lib/libc.so.6(__overflow+0x4a)[0xb710eb1a]
/lib/libc.so.6(_IO_vfprintf+0x4eff)[0xb70e5e5f]
/lib/libc.so.6(__vsprintf_chk+0xa7)[0xb7185d37]
/lib/libc.so.6(__sprintf_chk+0x2d)[0xb7185c7d]
/var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk[0x80609b1]
/var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk[0x8057c77]
/var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk[0x8057f48]
/var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk[0x805fd3d]
/var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk[0x8056421]
/lib/libc.so.6(__libc_start_main+0xe6)[0xb70babb6]
/var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk[0x804b071]
======= Memory map: ========
08048000-080a4000 r-xp 00000000 08:03 1053305    /var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk
080a4000-080a5000 r--p 0005c000 08:03 1053305    /var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk
080a5000-080b3000 rw-p 0005d000 08:03 1053305    /var/tmp/portage/sys-power/nvclock-0.8_p20110102-r1/image/usr/bin/nvclock_gtk
0956f000-095b2000 rw-p 00000000 00:00 0          [heap]
b5d60000-b5d7c000 r-xp 00000000 08:03 953664     /usr/lib/gcc/i686-pc-linux-gnu/4.4.5/libgcc_s.so.1
b5d7c000-b5d7d000 r--p 0001b000 08:03 953664     /usr/lib/gcc/i686-pc-linux-gnu/4.4.5/libgcc_s.so.1
b5d7d000-b5d7e000 rw-p 0001c000 08:03 953664     /usr/lib/gcc/i686-pc-linux-gnu/4.4.5/libgcc_s.so.1
b5d98000-b5da8000 rw-s d6300000 00:0e 3685       /dev/nvidia0
b5da8000-b5ea8000 rw-s d6700000 00:0e 3685       /dev/nvidia0
b5ea8000-b5eaa000 rw-s d6680000 00:0e 3685       /dev/nvidia0
b5eaa000-b5eba000 rw-s d6610000 00:0e 3685       /dev/nvidia0
b5eba000-b5ebc000 rw-s d6601000 00:0e 3685       /dev/nvidia0
b5ebc000-b5eec000 rw-s d6000000 00:0e 3685       /dev/nvidia0
b5eec000-b5eed000 rw-s d6100000 00:0e 3685       /dev/nvidia0
b5eed000-b5eee000 rw-s d6101000 00:0e 3685       /dev/nvidia0
b5eee000-b5f14000 r--p 00000000 08:03 1428757    /usr/share/locale/en_GB/LC_MESSAGES/gtk20-properties.mo
b5f14000-b5f1e000 r-xp 00000000 08:03 1039510    /lib/libnss_files-2.11.3.so
b5f1e000-b5f1f000 r--p 00009000 08:03 1039510    /lib/libnss_files-2.11.3.so
b5f1f000-b5f20000 rw-p 0000a000 08:03 1039510    /lib/libnss_files-2.11.3.so
b5f20000-b5f29000 r-xp 00000000 08:03 1039652    /lib/libnss_nis-2.11.3.so
b5f29000-b5f2a000 r--p 00008000 08:03 1039652    /lib/libnss_nis-2.11.3.so
b5f2a000-b5f2b000 rw-p 00009000 08:03 1039652    /lib/libnss_nis-2.11.3.so
b5f2b000-b5f3e000 r-xp 00000000 08:03 1039656    /lib/libnsl-2.11.3.so
b5f3e000-b5f3f000 r--p 00012000 08:03 1039656    /lib/libnsl-2.11.3.so
b5f3f000-b5f40000 rw-p 00013000 08:03 1039656    /lib/libnsl-2.11.3.so
b5f40000-b5f42000 rw-p 00000000 00:00 0 
b5f42000-b5f48000 r-xp 00000000 08:03 1039655    /lib/libnss_compat-2.11.3.so
b5f48000-b5f49000 r--p 00006000 08:03 1039655    /lib/libnss_compat-2.11.3.so
b5f49000-b5f4a000 rw-p 00007000 08:03 1039655    /lib/libnss_compat-2.11.3.so
b5f64000-b6153000 r--p 00000000 08:03 3276969    /usr/lib/locale/locale-archive
b6153000-b61b9000 rw-p 00000000 00:00 0 
b61b9000-b61ba000 r-xp 00000000 08:03 1084592    /usr/lib/opengl/nvidia/lib/libnvidia-tls.so.96.43.19
b61ba000-b61bb000 rw-p 00000000 08:03 1084592    /usr/lib/opengl/nvidia/lib/libnvidia-tls.so.96.43.19
b61bb000-b6a08000 r-xp 00000000 08:03 1084587    /usr/lib/opengl/nvidia/lib/libGLcore.so.96.43.19
b6a08000-b6a3d000 rwxp 0084d000 08:03 1084587    /usr/lib/opengl/nvidia/lib/libGLcore.so.96.43.19
b6a3d000-b6a41000 rwxp 00000000 00:00 0 
b6a41000-b6a42000 rw-p 00000000 00:00 0 
b6a42000-b6a53000 r-xp 00000000 08:03 1039633    /lib/libresolv-2.11.3.so
b6a53000-b6a54000 r--p 00010000 08:03 1039633    /lib/libresolv-2.11.3.so
b6a54000-b6a55000 rw-p 00011000 08:03 1039633    /lib/libresolv-2.11.3.so
b6a55000-b6a57000 rw-p 00000000 00:00 0 
b6a57000-b6a7b000 r-xp 00000000 08:03 1688575    /usr/lib/libexpat.so.1.5.2
b6a7b000-b6a7d000 r--p 00023000 08:03 1688575    /usr/lib/libexpat.so.1.5.2
b6a7d000-b6a7e000 rw-p 00025000 08:03 1688575    /usr/lib/libexpat.so.1.5.2
b6a7e000-b6a91000 r-xp 00000000 08:03 1004540    /lib/libz.so.1.2.5
b6a91000-b6a92000 r--p 00012000 08:03 1004540    /lib/libz.so.1.2.5
b6a92000-b6a93000 rw-p 00013000 08:03 1004540    /lib/libz.so.1.2.5
b6a93000-b6b14000 r-xp 00000000 08:03 1233260    /usr/lib/libfreetype.so.6.6.2
b6b14000-b6b18000 r--p 00080000 08:03 1233260    /usr/lib/libfreetype.so.6.6.2
b6b18000-b6b19000 rw-p 00084000 08:03 1233260    /usr/lib/libfreetype.so.6.6.2
b6b19000-b6b89000 r-xp 00000000 08:03 1084567    /usr/lib/opengl/nvidia/lib/libGL.so.96.43.19
b6b89000-b6ba3000 rwxp 0006f000 08:03 1084567    /usr/lib/opengl/nvidia/lib/libGL.so.96.43.19
b6ba3000-b6ba4000 rwxp 00000000 00:00 0 
b6ba4000-b6ba5000 rw-p 00000000 00:00 0 
b6ba5000-b6ba9000 r-xp 00000000 08:03 1001960    /usr/lib/libXdmcp.so.6.0.0
b6ba9000-b6baa000 r--p 00003000 08:03 1001960    /usr/lib/libXdmcp.so.6.0.0
b6baa000-b6bab000 rw-p 00004000 08:03 1001960    /usr/lib/libXdmcp.so.6.0.0
b6bab000-b6bad000 r-xp 00000000 08:03 999758     /usr/lib/libXau.so.6.0.0
b6bad000-b6bae000 r--p 00001000 08:03 999758     /usr/lib/libXau.so.6.0.0
b6bae000-b6baf000 rw-p 00002000 08:03 999758     /usr/lib/libXau.so.6.0.0
b6baf000-b6bb5000 r-xp 00000000 08:03 1017226    /usr/lib/libxcb-render.so.0.0.0
b6bb5000-b6bb6000 r--p 00005000 08:03 1017226    /usr/lib/libxcb-render.so.0.0.0
b6bb6000-b6bb7000 rw-p 00006000 08:03 1017226    /usr/lib/libxcb-render.so.0.0.0
b6bb7000-b6bb9000 r-xp 00000000 08:03 1017246    /usr/lib/libxcb-shm.so.0.0.0
b6bb9000-b6bba000 r--p 00001000 08:03 1017246    /usr/lib/libxcb-shm.so.0.0.0
b6bba000-b6bbb000 rw-p 00002000 08:03 1017246    /usr/lib/libxcb-shm.so.0.0.0
b6bbb000-b6bde000 r-xp 00000000 08:03 1039052    /usr/lib/libpng14.so.14.5.0
b6bde000-b6bdf000 r--p 00022000 08:03 1039052    /usr/lib/libpng14.so.14.5.0
b6bdf000-b6be0000 rw-p 00023000 08:03 1039052    /usr/lib/libpng14.so.14.5.0
b6be0000-b6bee000 r-xp 00000000 08:03 1262495    /usr/lib/libEGL.so.1.0
b6bee000-b6bef000 r--p 0000d000 08:03 1262495    /usr/lib/libEGL.so.1.0
b6bef000-b6bf0000 rw-p 0000e000 08:03 1262495    /usr/lib/libEGL.so.1.0
b6bf0000-b6bf1000 rw-p 00000000 00:00 0 
b6bf1000-b6c4d000 r-xp 00000000 08:03 1102468    /usr/lib/libpixman-1.so.0.20.2
b6c4d000-b6c50000 r--p 0005b000 08:03 1102468    /usr/lib/libpixman-1.so.0.20.2
b6c50000-b6c51000 rw-p 0005e000 08:03 1102468    /usr/lib/libpixman-1.so.0.20.2
b6c51000-b6c69000 r-xp 00000000 08:03 1017186    /usr/lib/libxcb.so.1.1.0
b6c69000-b6c6a000 r--p 00017000 08:03 1017186    /usr/lib/libxcb.so.1.1.0Aborted

which is why I left it at that previously. I have investigated some more and it seems it should be enough to simply disable compiler optimisation, i.e. have 
-O0 but respect other CFLAGS.
Comment 2 Diego Elio Pettenò (RETIRED) gentoo-dev 2011-04-25 10:04:36 UTC
Um that doesn't look right: if you get a fortify_fail it means there is a buffer overflow in the code. Building at -O0 simply hides it because the compiler does not emit safety guards on the function (inlining is disabled so _FORTIFY_SOURCE is disabled as well).

You should fix the overflow, not simply hide it.
Comment 3 Jeroen Roovers (RETIRED) gentoo-dev 2011-04-25 20:05:35 UTC
(In reply to comment #2)
> Um that doesn't look right: if you get a fortify_fail it means there is a
> buffer overflow in the code. Building at -O0 simply hides it because the
> compiler does not emit safety guards on the function (inlining is disabled so
> _FORTIFY_SOURCE is disabled as well).
> 
> You should fix the overflow, not simply hide it.

That's rather worrying, but couldn't it be that optimising that horrible code creates this new issue? There's an ominous quotation about optimisation: 
src/backend/config.c:                       bios = read_bios(filename); /* GCC 4.0.1 (what about others?) doesn't like it when we directly do nc
lock.card[i].bios = readbios(filename); works fine without optimizations */

Anyway, this looks like a new issue that should be fixed UPSTREAM, and it looks like that might never happen right now.

I'll just cut through the red tape and change this bug's Summary as this is basically still the same problem.
Comment 4 Diego Elio Pettenò (RETIRED) gentoo-dev 2011-04-26 12:52:13 UTC
I don't think it's a miscompilation problem. The partial trace you shown means that the fortified source is being called because the code is calling sprintf() on a statically-sized buffer, which results (at runtime) being smaller than the string it should be printed on.

Now, I don't know your setup, but I picked one possible cause:

char buf[80];
sprintf(buf, "Can't create '%s'. Do you have sufficient permissions?\n", nvclock.path);

That nvclock.path expands to "${HOME}/.nvclock". The 80 characters (which are actually 79, since one you have to reserve for NULL) are likely enough for _most_ users, but that might not be:

"Can't create '/home/jeroen/.nvclock'. Do you have sufficient permissions?\n"

is 76 characters, which would fit, but if you had your home directories is something else like /mnt/encrypted/jeroen ... then it would overflow all the time.

To me, -O0 is just hiding the problems under a rug. And this is not just a matter for upstream, this is the kind of things we should care about in Gentoo as they might even be security-related.
Comment 6 Pacho Ramos gentoo-dev 2013-10-12 21:10:01 UTC
(In reply to SpanKY from comment #5)
> Commit message: Fix gtk linkage against X libs.  Respect $AR settings.  Fix
> .desktop warnings.  Fix buffers overflows in random messages.
> http://sources.gentoo.org/sys-power/nvclock/files/nvclock-0.8_p20110102-
> buffers.patch?rev=1.1
> http://sources.gentoo.org/sys-power/nvclock/files/nvclock-0.8_p20110102-
> desktop.patch?rev=1.1
> http://sources.gentoo.org/sys-power/nvclock/files/nvclock-0.8_p20110102-r1-
> make.patch?rev=1.1
> http://sources.gentoo.org/sys-power/nvclock/files/nvclock-0.8_p20110102-
> usleep.patch?r1=1.1&r2=1.2
> http://sources.gentoo.org/sys-power/nvclock/nvclock-0.8_p20110102-r2.
> ebuild?rev=1.1