Bug 1370931 - glfs_realpath() should not return malloc()'d allocated memory
Summary: glfs_realpath() should not return malloc()'d allocated memory
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: GlusterFS
Classification: Community
Component: libgfapi
Version: mainline
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: ---
Assignee: Niels de Vos
QA Contact: Sudhir D
URL:
Whiteboard:
Depends On: 1344714 1364529 1383591
Blocks: 1383592 1383593
TreeView+ depends on / blocked
 
Reported: 2016-08-28 14:30 UTC by Niels de Vos
Modified: 2017-03-06 17:23 UTC (History)
2 users (show)

Fixed In Version: glusterfs-3.10.0
Clone Of:
: 1383591 1383592 1383593 (view as bug list)
Environment:
Last Closed: 2017-03-06 17:23:44 UTC
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Embargoed:


Attachments (Terms of Use)

Description Niels de Vos 2016-08-28 14:30:25 UTC
Description of problem:
Very similar to how upcall events are allocated by gfapi and returned to the applications, glfs_realpath() uses malloc(). 

Version-Release number of selected component (if applicable):
all

How reproducible:
Compile an application that calls glfs_realpath() and have the function allocate the memory on behalf of the application. If the application uses a different memory allocated (i.e. jemalloc), free() will not work correctly and can cause segfaults.

Additional info:
See http://review.gluster.org/14701 for a more complete description.

Comment 1 Worker Ant 2016-08-28 14:36:33 UTC
REVIEW: http://review.gluster.org/15332 (gfapi: warn when glfs_realpath() returned malloc'd memory) posted (#1) for review on master by Niels de Vos (ndevos)

Comment 2 Worker Ant 2016-08-29 11:52:54 UTC
REVIEW: http://review.gluster.org/15332 (gfapi: warn when glfs_realpath() returned malloc'd memory) posted (#2) for review on master by Niels de Vos (ndevos)

Comment 3 Worker Ant 2016-08-29 20:05:12 UTC
REVIEW: http://review.gluster.org/15332 (gfapi: warn when glfs_realpath() returned malloc'd memory) posted (#3) for review on master by Niels de Vos (ndevos)

Comment 4 Worker Ant 2016-09-13 11:40:25 UTC
REVIEW: http://review.gluster.org/15332 (gfapi: warn when glfs_realpath() returned malloc'd memory) posted (#4) for review on master by Niels de Vos (ndevos)

Comment 5 Worker Ant 2016-09-30 11:10:24 UTC
REVIEW: http://review.gluster.org/15332 (gfapi: warn when glfs_realpath() returned malloc'd memory) posted (#5) for review on master by Niels de Vos (ndevos)

Comment 6 Worker Ant 2016-09-30 13:49:11 UTC
REVIEW: http://review.gluster.org/15332 (gfapi: warn when glfs_realpath() returned malloc'd memory) posted (#6) for review on master by Niels de Vos (ndevos)

Comment 7 Worker Ant 2016-10-10 13:33:38 UTC
REVIEW: http://review.gluster.org/15332 (gfapi: warn when glfs_realpath() returned malloc'd memory) posted (#7) for review on master by Niels de Vos (ndevos)

Comment 8 Worker Ant 2016-10-11 07:14:04 UTC
COMMIT: http://review.gluster.org/15332 committed in master by Niels de Vos (ndevos) 
------
commit 85e959052148ec481823d55c8b91cdee36da2b43
Author: Niels de Vos <ndevos>
Date:   Tue Sep 13 09:03:56 2016 +0200

    gfapi: warn when glfs_realpath() returned malloc'd memory
    
    glfs_realpath() may return memory allocated with malloc(). Depending on
    the memory allocator that the application uses, calling free() on the
    returned string can cause segmentation faults or other problems.
    
    Functions that allocate memory, need to match the free'ing of the same
    memory allocator and memory accounting. glibc/malloc and jemalloc/free
    do not match together (other allocators could probably trigger these
    problems as well).
    
    Applications need to provide a pre-allocated buffer, or in case
    glfs_realpath() allocates the memory, glfs_free() should be used to free
    it.
    
    Change-Id: I5d721a7425674aa700db8a7a436cbedb95a5927f
    BUG: 1370931
    Signed-off-by: Niels de Vos <ndevos>
    Reviewed-on: http://review.gluster.org/15332
    CentOS-regression: Gluster Build System <jenkins.org>
    Smoke: Gluster Build System <jenkins.org>
    NetBSD-regression: NetBSD Build System <jenkins.org>
    Reviewed-by: Kaleb KEITHLEY <kkeithle>

Comment 9 Niels de Vos 2016-10-13 07:57:16 UTC
from #gluster-dev on freenode:

09:03 < anoopcs> ndevos, Regarding http://review.gluster.org/#/c/15332/8/api/src/gfapi.map. I could not see GFAPI_3.7.16 changed to GFAPI_3.7.17 for the last glfs_ipc block. Was that intentionally done?

https://botbot.me/freenode/gluster-dev/2016-10-13/?msg=74721134&page=1

Comment 10 Worker Ant 2016-10-13 08:03:04 UTC
REVIEW: http://review.gluster.org/15633 (gfapi: correct the gfapi.map for glfs_ipc@GFAPI_4_0_0) posted (#1) for review on master by Niels de Vos (ndevos)

Comment 11 Worker Ant 2016-10-13 12:22:21 UTC
COMMIT: http://review.gluster.org/15633 committed in master by Kaleb KEITHLEY (kkeithle) 
------
commit fc3ff95041581fb0791bd083baa0dd98717e188b
Author: Niels de Vos <ndevos>
Date:   Thu Oct 13 09:58:21 2016 +0200

    gfapi: correct the gfapi.map for glfs_ipc@GFAPI_4_0_0
    
    Commit 85e959052148ec481823d55c8b91cdee36da2b43 introduced an
    inconsistency in gfapi.map. We need to figure out how to handle the
    glfs_ipc() function at one point...
    
    Change-Id: If53ad904318d5a60c14bd8b80685f7a852bf25e5
    BUG: 1370931
    Reported-by: Anoop C S <anoopcs>
    Signed-off-by: Niels de Vos <ndevos>
    Reviewed-on: http://review.gluster.org/15633
    Reviewed-by: Anoop C S <anoopcs>
    NetBSD-regression: NetBSD Build System <jenkins.org>
    CentOS-regression: Gluster Build System <jenkins.org>
    Reviewed-by: Kaleb KEITHLEY <kkeithle>
    Smoke: Gluster Build System <jenkins.org>

Comment 12 Shyamsundar 2017-03-06 17:23:44 UTC
This bug is getting closed because a release has been made available that should address the reported issue. In case the problem is still not fixed with glusterfs-3.10.0, please open a new bug report.

glusterfs-3.10.0 has been announced on the Gluster mailinglists [1], packages for several distributions should become available in the near future. Keep an eye on the Gluster Users mailinglist [2] and the update infrastructure for your distribution.

[1] http://lists.gluster.org/pipermail/gluster-users/2017-February/030119.html
[2] https://www.gluster.org/pipermail/gluster-users/


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