Bug 1383591 - glfs_realpath() should not return malloc()'d allocated memory
Summary: glfs_realpath() should not return malloc()'d allocated memory
Keywords:
Status: CLOSED DUPLICATE of bug 1364529
Alias: None
Product: GlusterFS
Classification: Community
Component: libgfapi
Version: 3.9
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: ---
Assignee: Niels de Vos
QA Contact: Sudhir D
URL:
Whiteboard:
Depends On:
Blocks: 1370931
TreeView+ depends on / blocked
 
Reported: 2016-10-11 07:31 UTC by Niels de Vos
Modified: 2018-02-13 18:27 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1370931
Environment:
Last Closed: 2016-10-14 07:50:39 UTC
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Embargoed:


Attachments (Terms of Use)

Description Niels de Vos 2016-10-11 07:31:06 UTC
+++ This bug was initially created as a clone of Bug #1370931 +++

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.

--- Additional comment from Worker Ant on 2016-08-28 16:36:33 CEST ---

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)

--- Additional comment from Worker Ant on 2016-08-29 13:52:54 CEST ---

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)

--- Additional comment from Worker Ant on 2016-08-29 22:05:12 CEST ---

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)

--- Additional comment from Worker Ant on 2016-09-13 13:40:25 CEST ---

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)

--- Additional comment from Worker Ant on 2016-09-30 13:10:24 CEST ---

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)

--- Additional comment from Worker Ant on 2016-09-30 15:49:11 CEST ---

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)

--- Additional comment from Worker Ant on 2016-10-10 15:33:38 CEST ---

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)

--- Additional comment from Worker Ant on 2016-10-11 09:14:04 CEST ---

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 1 Worker Ant 2016-10-11 09:41:48 UTC
REVIEW: http://review.gluster.org/15621 (gfapi: warn when glfs_realpath() returned malloc'd memory) posted (#1) for review on release-3.9 by Niels de Vos (ndevos)

Comment 2 Worker Ant 2016-10-11 18:54:24 UTC
COMMIT: http://review.gluster.org/15621 committed in release-3.9 by Kaleb KEITHLEY (kkeithle) 
------
commit b07c5324161f2fda22d5903db61b9711cf949229
Author: Niels de Vos <ndevos>
Date:   Tue Oct 11 11:40:13 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.
    
    Cherry picked from commit 85e959052148ec481823d55c8b91cdee36da2b43:
    > 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>
    
    Change-Id: I5d721a7425674aa700db8a7a436cbedb95a5927f
    BUG: 1383591
    Signed-off-by: Niels de Vos <ndevos>
    Reviewed-on: http://review.gluster.org/15621
    NetBSD-regression: NetBSD Build System <jenkins.org>
    CentOS-regression: Gluster Build System <jenkins.org>
    Smoke: Gluster Build System <jenkins.org>
    Reviewed-by: Kaleb KEITHLEY <kkeithle>

Comment 3 Worker Ant 2016-10-14 05:49:24 UTC
REVIEW: http://review.gluster.org/15638 (gfapi: correct the gfapi.map for glfs_ipc@GFAPI_4_0_0) posted (#1) for review on release-3.9 by Anoop C S (anoopcs)

Comment 4 Niels de Vos 2016-10-14 07:50:39 UTC

*** This bug has been marked as a duplicate of bug 1364529 ***


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