Page MenuHome GnuPG

Debian ppc64el failure of 'make check with_valgrind=1'
Open, LowPublic

Description

I encountered a failure (actually, a kind of false positive) of valgrind.

It is a false positive from view point of GnuPG.
But, from viewpoint of valgrind, it correctly detects memory access beyond allocated area.

It's strncmp in libgcrypt/cipher/cipher.c:search_oid, which causes the failure.
GCC for ppc64el optimizes strncmp into comparison of word-sized memory, because of the constant "oid." of 4-byte. It's aggressive with only for possible page boundary check.

Similarly, I found the implementation of strncmp in GNU C library is also aggressive.

I'm a bit anxious about POWER situation for this.

I came here to investigate the FTBFS for gnupg 2.3.1, but I think that there is no problem in GnuPG itself, but it's a problem of how it is built on buildd (no /run/user, no HOME).

Event Timeline

gniibe created this task.
gniibe updated the task description. (Show Details)

This is the minimized test case.

$ gcc -O3 -o a -g t.c -Wall && valgrind --exit-on-first-error=yes ./a
==17094== Bad option: --exit-on-first-error=yes
==17094== You must define a non nul exit error code, with --error-exitcode=...
==17094== Use --help for more information or consult the user manual.
==17094== Memcheck, a memory error detector
==17094== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==17094== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==17094== Command: ./a
==17094==
796
1694
2718
==17094== Invalid read of size 4
==17094==    at 0x180878: check (t.c:28)
==17094==    by 0x180878: main (t.c:43)
==17094==  Address 0x4b467fe is 30 bytes inside a block of size 33 alloc'd
==17094==    at 0x4894260: malloc (in /usr/lib/powerpc64le-linux-gnu/valgrind/vgpreload_memcheck-ppc64le-linux.so)
==17094==    by 0x18082F: check (t.c:18)
==17094==    by 0x18082F: main (t.c:43)
==17094==
==17094==
==17094== Exit program on first error (--exit-on-first-error=yes)

This is another test case for GNU C library's strncmp:

I use --partial-loads-ok=no in this case.

$ gcc -O3 -o a -g t.c -Wall && valgrind --partial-loads-ok=no --exit-on-first-error=yes \
./a
==21411== Bad option: --exit-on-first-error=yes
==21411== You must define a non nul exit error code, with --error-exitcode=...
==21411== Use --help for more information or consult the user manual.
==21411== Memcheck, a memory error detector
==21411== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==21411== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==21411== Command: ./a
==21411==
1487
==21411== Invalid read of size 8
==21411==    at 0x1808AC: check (t.c:31)
==21411==    by 0x1808AC: main (t.c:48)
==21411==  Address 0x4b277ff is 15 bytes inside a block of size 21 alloc'd
==21411==    at 0x4894260: malloc (in /usr/lib/powerpc64le-linux-gnu/valgrind/vgpreload_memcheck-ppc64le-linux.so)
==21411==    by 0x18085F: check (t.c:20)
==21411==    by 0x18085F: main (t.c:48)
==21411==
==21411==
==21411== Exit program on first error (--exit-on-first-error=yes)

I test on ppc64 machine (POWER9, big endian).

Only when I specify -mcpu={power6,power7,power8,power9} for gcc, I can see the failure of valgrind.