Bug 1451308

Summary: glibc: Fix valgrind reporting with check_pf when there is no ipv6 interface
Product: Red Hat Enterprise Linux 7 Reporter: Deepu K S <dkochuka>
Component: glibcAssignee: Arjun Shankar <ashankar>
Status: CLOSED ERRATA QA Contact: qe-baseos-tools-bugs
Severity: medium Docs Contact:
Priority: medium    
Version: 7.3CC: ashankar, bfinger, bgollahe, codonell, cww, dkochuka, fweimer, glibc-bugzilla, jwright, mnewsome, pfrankli, skolosov
Target Milestone: rcKeywords: Patch
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: glibc-2.17-296.el7 Doc Type: Bug Fix
Doc Text:
Cause: When running on a system with IPv6 disabled, a pointer used internally by the getaddrinfo function was deallocated and assigned the address of a statically allocated structure instead. Consequence: The runtime incorrectly attempted to deallocate this statically allocated memory at program exit. This led to a crash at program exit and/or an "invalid free" error when run under `valgrind'. Fix: getaddrinfo was fixed so that at program exit, it now only deallocates this memory if it is dynamically allocated. Result: Programs using getaddrinfo running on systems with IPv6 disabled no longer crash and/or show "invalid free" errors when run under `valgrind'.
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-31 19:08:29 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1594286, 1710258    

Description Deepu K S 2017-05-16 11:26:58 UTC
Description of problem:
posix/bug-ga2 fails when there is no ipv6 interface.

The test posix/bug-ga2 fails with the following error:

*** Error in `/root/src/upstream/glibc/build/posix/bug-ga2': free(): invalid pointer: 0x00007fe7ab1bc370 **
*

There is a known issue in libc 2.17 (https://sourceware.org/ml/libc-alpha/2014-07/msg00200.html) when the system doesn’t have ipv6 configured, libc points the noai6ai_cached to a static variable which later results in freeing an invalid pointer at exit.

Due to this, VALGRIND reports "Invalid free() / delete / delete[] / realloc()" error in c++ application.

log snippet from valgrind:
==33350== 1 errors in context 1 of 1:
==33350== Invalid free() / delete / delete[] / realloc()
==33350==    at 0x4C28CDD: free (vg_replace_malloc.c:530)
==33350==    by 0x57B80EB: __libc_freeres (in /usr/lib64/libc-2.17.so)
==33350==    by 0x4A22749: _vgnU_freeres (vg_preloaded.c:77)
==33350==    by 0x568BA0A: __run_exit_handlers (exit.c:92)


Version-Release number of selected component (if applicable):
Red Hat Enterprise Linux 7.3
glibc-2.17-157.el7_3.1.x86_64

How reproducible:
Always

Steps to Reproduce:
1.
2.
3.

Actual results:

*** Error in `/root/src/upstream/glibc/build/posix/bug-ga2': free(): invalid pointer: 0x00007fe7ab1bc370 ***


Expected results:
No fail.

Additional info:

Comment 5 Florian Weimer 2017-10-02 15:53:29 UTC
I looked at the upstream fix and it seems wrong.  After the fix, we need leak the memory instead if the cache pointer was allocated on the heap.

We should remove the statically allocate structure and always allocate it on the heap.  Things have changed since the code was written.  Today, (unused) IPv6 interfaces are the default, and the static allocation just wastes RSS.

Comment 16 Sergey Kolosov 2019-10-18 15:05:31 UTC
Verified, the bug reproduced in glibc-2.17-295.el7 and didn't in glibc-2.17-296.el7.

Comment 18 errata-xmlrpc 2020-03-31 19:08:29 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:0989