Bug 903203 - libselinux memory leak causes libvirtd to grow unbounded (with fix)
libselinux memory leak causes libvirtd to grow unbounded (with fix)
Product: Fedora
Classification: Fedora
Component: libselinux (Show other bugs)
Unspecified Unspecified
unspecified Severity high
: ---
: ---
Assigned To: Daniel Walsh
Fedora Extras Quality Assurance
Depends On: 903280
Blocks: 890039 891324
  Show dependency treegraph
Reported: 2013-01-23 08:37 EST by Richard W.M. Jones
Modified: 2013-03-02 15:10 EST (History)
13 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 891324
Last Closed: 2013-03-02 15:10:02 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Richard W.M. Jones 2013-01-23 08:37:17 EST
+++ This bug was initially created as a clone of Bug #891324 +++

+++ This bug was initially created as a clone of Bug #890039 +++

Description of problem:

  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND           
25390 rjones    20   0 10.9g  10g 8.4g S   0.0 66.8  16:34.08 libvirtd          

At least a component of this is caused by a memory leak
in libselinux.  The memory leak isn't in libselinux upstream,
but in a Fedora-specific patch that we apply to libselinux

This patch causes selabel_open to indirectly call a function
called 'load_mmap'.  This function strdups a string:

 spec->lr.ctx_raw = strdup((char *)addr);

but because of later faulty logic, spec->lr.ctx_raw is never
freed up.

The following patch fixes this:

--- libselinux-2.1.12/src/label_file.c.orig	2013-01-23 13:16:49.290131262 +0000
+++ libselinux-2.1.12/src/label_file.c	2013-01-23 13:17:13.202021998 +0000
@@ -535,11 +535,11 @@
 	for (i = 0; i < data->nspec; i++) {
 		spec = &data->spec_arr[i];
+		free(spec->lr.ctx_raw);
 		if (spec->from_mmap)
-		free(spec->lr.ctx_raw);
 		if (spec->regcomp) {

I have tested this patch and it works and reduces the memory
leakage of libvirtd in Fedora 18 (it doesn't eliminate it,
but I believe that we have another patch to libvirt which
fixes it completely).

Please apply the above patch to libselinux.
Comment 1 Richard W.M. Jones 2013-01-23 08:38:55 EST
Additionally, this is the valgrind log showing the memory leak:

Comment 2 Daniel Walsh 2013-01-28 11:16:50 EST
We actually have more of a fix in rawhide.

	for (i = 0; i < data->nspec; i++) {
		spec = &data->spec_arr[i];
		if (spec->from_mmap)
		if (spec->regcomp) {
Comment 3 Daniel Walsh 2013-01-28 11:35:44 EST
Fixed in libselinux-2.1.12-7.1.fc18
Comment 4 Fedora Update System 2013-01-28 11:54:10 EST
libselinux-2.1.12-7.1.fc18 has been submitted as an update for Fedora 18.
Comment 5 Fedora Update System 2013-01-29 19:55:40 EST
Package libselinux-2.1.12-7.1.fc18:
* should fix your issue,
* was pushed to the Fedora 18 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing libselinux-2.1.12-7.1.fc18'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).
Comment 6 Fedora Update System 2013-03-02 15:10:08 EST
libselinux-2.1.12-7.1.fc18 has been pushed to the Fedora 18 stable repository.  If problems still persist, please make note of it in this bug report.

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