Bug 1472485 - libselinux realpath_not_final calls free() on invalid pointer
libselinux realpath_not_final calls free() on invalid pointer
Status: CLOSED DUPLICATE of bug 1404644
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libselinux (Show other bugs)
x86_64 Linux
unspecified Severity medium
: rc
: ---
Assigned To: Petr Lautrbach
Milos Malik
Depends On:
  Show dependency treegraph
Reported: 2017-07-18 17:38 EDT by Ivan Agarkov
Modified: 2017-07-19 04:30 EDT (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2017-07-19 04:30:19 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
CentOS 13567 None None None 2017-07-18 17:38 EDT

  None (edit)
Description Ivan Agarkov 2017-07-18 17:38:09 EDT
Description of problem:
libselinux matchpathcon() calls realpath_not_final() function if the path is a symlink.
realpath_not_final doesn't track double slash properly that caused to free() on invalid pointer.

How reproducible:

Steps to Reproduce:
1. matchpathcon /bin ( it works )
2. matchpathcon //bin ( it crashes )
3. or compile and run the following code:
#include <selinux/selinux.h>
#include <sys/stat.h>
#include <stdlib.h>

int main() {
    char **conptr = malloc(sizeof(char *));
    struct stat st;
    lstat("//bin", &st);
    matchpathcon("//bin", st.st_mode, conptr);
    return 0;

Actual results:
*** Error in `./test': free(): invalid pointer: 0x0000000000b12f41 ***
======= Backtrace: =========

Expected results:
//bin system_u:object_r:bin_t

Additional info:

I've tested latest master branch of libselinux and looks like the bug was fixed there.
Comment 2 Milos Malik 2017-07-19 04:18:14 EDT
This bug is reproducible on RHEL-7.3, but it is not reproducible on RHEL-7.4.

I believe this bug is a duplicate of BZ#1404644.
Comment 3 Vit Mojzis 2017-07-19 04:30:19 EDT

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

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