Bug 1699304 - Multiple invalid writes of size 4 found by valgrind on arm
Summary: Multiple invalid writes of size 4 found by valgrind on arm
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: cmocka
Version: 29
Hardware: armv7l
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Andreas Schneider
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-04-12 11:20 UTC by Tomas Korbar
Modified: 2019-09-30 09:37 UTC (History)
3 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2019-09-30 09:37:17 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Reproducer (131 bytes, text/x-csrc)
2019-04-12 11:20 UTC, Tomas Korbar
no flags Details
Valgrind's logs (3.54 KB, text/plain)
2019-04-12 11:23 UTC, Tomas Korbar
no flags Details

Description Tomas Korbar 2019-04-12 11:20:13 UTC
Created attachment 1554772 [details]
Reproducer

Description of problem:
Valgrind finds multiple invalid writes in programs which use libcmocka and are compiled on arm architecture. See log and reproducer in attachments.

Version-Release number of selected component (if applicable):
libcmocka-1.1.5-1.fc29.armv7hl
valgrind-1:3.14.0-10.fc29.armv7hl
gcc-8.3.1-2.fc29.armv7hl

How reproducible:
Compile reproducer from attachments on arm and run valgrind on it.

Steps to Reproduce:
1. $ gcc cmocka_reproducer.c -o cmocka_reproducer -lcmocka
2. $ valgrind ./cmocka_reproducer

Actual results:
Multiple messages with invalid writes.

Expected results:
No messages.

Additional info:

Comment 1 Tomas Korbar 2019-04-12 11:23:09 UTC
Created attachment 1554773 [details]
Valgrind's logs

Comment 2 Andreas Schneider 2019-04-12 13:06:48 UTC
==10538== Invalid write of size 4
==10538==    at 0x4867360: _assert_string_equal (cmocka.c:1815)
==10538==    by 0x104A3: main (in /home/tkorbar/cmocka_reproducer)
==10538==  Address 0xbde1eab0 is on thread 1's stack
==10538==  24 bytes below stack pointer

Looking at the code, I'm not sure were a invalid write of 4 should be here:

1814 void _assert_string_equal(const char * const a, const char * const b,
1815                           const char * const file, const int line) {

==10538== Invalid write of size 4
==10538==    at 0x48649F0: cm_print_error (cmocka.c:2251)
==10538==    by 0x4867393: string_equal_display_error (cmocka.c:1299)
==10538==    by 0x4867393: _assert_string_equal (cmocka.c:1816)
==10538==    by 0x104A3: main (in /home/tkorbar/cmocka_reproducer)
==10538==  Address 0xbde1eaa0 is on thread 1's stack
==10538==  16 bytes below stack pointer

2250 void cm_print_error(const char * const format, ...)                                                                                                                                     
2251 {

This also points to a bogus line.


This is either a bug in valgrind or a bug in gcc on ARM.

Comment 3 Pascal Terjan 2019-09-30 08:41:53 UTC
I noticed the same problem om Mageia. All the invalid writes are on the { line of the function so my guess would be some code added by gcc (I believe -fstack-protector would add some code when the function is entered)

Comment 4 Pascal Terjan 2019-09-30 08:56:58 UTC
I noticed cmocka gets built with -fstack-clash-protection so this is probably https://bugzilla.redhat.com/show_bug.cgi?id=1522678

Comment 5 Pascal Terjan 2019-09-30 09:04:04 UTC
I have confirmed the problem goes away with this (ugly, just for testing :) ) patch:

--- cmocka-1.1.5/CompilerChecks.cmake.sav       2019-09-30 08:58:18.445946241 +0000
+++ cmocka-1.1.5/CompilerChecks.cmake   2019-09-30 08:58:45.066525089 +0000
@@ -84,11 +84,6 @@
         endif()
     endif (WITH_STACK_PROTECTOR_STRONG)
 
-    check_c_compiler_flag_ssp("-fstack-clash-protection" WITH_STACK_CLASH_PROTECTION)
-    if (WITH_STACK_CLASH_PROTECTION)
-        list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-clash-protection")
-    endif()
-
     if (PICKY_DEVELOPER)
         add_c_compiler_flag("-Wno-error=deprecated-declarations" SUPPORTED_COMPILER_FLAGS)
         add_c_compiler_flag("-Wno-error=tautological-compare" SUPPORTED_COMPILER_FLAGS)

Comment 6 Andreas Schneider 2019-09-30 09:37:17 UTC
So this is either compiler issue (-fstack-clash-protection not implemented correctly on ARM) or a valgrind issue seeing things which don't exist.

Closing as comment #5 confirms it is not a cmocka bug.


Note You need to log in before you can comment on or make changes to this bug.