Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 324243 - hardened-sources 2.6.32-r9 and higher memory leak under KVM hypervisor
Summary: hardened-sources 2.6.32-r9 and higher memory leak under KVM hypervisor
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Hardened (show other bugs)
Hardware: AMD64 Linux
: High normal (vote)
Assignee: The Gentoo Linux Hardened Kernel Team (OBSOLETE)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-16 10:09 UTC by Bert Smith
Modified: 2010-12-20 23:49 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Configuration file for 2.6.32-hardened-r7 (config-2632hr7,35.30 KB, text/plain)
2010-06-16 10:11 UTC, Bert Smith
Details
emerge --info for hardened VM (mid,3.30 KB, text/plain)
2010-08-17 18:56 UTC, Aleister
Details
hardened kvm guest kernel config (hardened-config,42.18 KB, text/plain)
2010-08-28 21:15 UTC, Aleister
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bert Smith 2010-06-16 10:09:51 UTC
When running kernel 2.6.32-r7 (amd64) under KVM 0.12.4 (installed as part of proxmox virtual environment - http://pve.proxmox.com) there appears to be a severe memory leak condition in kernel mode... 
After running for a short time, especially if the system is under load (such as compilation)

This was reproduced on a HP DL140 G3 running proxmox pve 1.5 with the latest updates.

I am unsure how to debug kernel memory allocation, if anyone can provide details how to debug this i will post appropriate output.

Reproducible: Always

Steps to Reproduce:
1. Install a gentoo amd64 image under kvm or proxmox using virtio disk/net, 512mb ram, using the attached kernel config
2. attempt to emerge mysql under the booted kernel



Actual Results:  
System will consume an increasing amount of memory, aparrently in kernel mode... After the OOM killer has killed all the userland processes, the memory usage will still be high.

Expected Results:  
Mysql should compile successfully, and the memory used by the compile should be freed again after completion.
Comment 1 Bert Smith 2010-06-16 10:11:03 UTC
Created attachment 235557 [details]
Configuration file for 2.6.32-hardened-r7

Example configuration file that causes memory leak issue
Comment 2 Bert Smith 2010-06-16 10:12:43 UTC
Kernel 2.6.32-hardened-r6 (from hardened-development overlay) does work correctly with the same configuration.
Comment 3 Bert Smith 2010-06-16 10:22:43 UTC
Output from a test system..
"free" showing memory usage, ps aux showing that not a huge amount is running (certainly not enough to justify the level of memory usage)

dbmail ~ # free
             total       used       free     shared    buffers     cached
Mem:        506740     501844       4896          0         80       1676
-/+ buffers/cache:     500088       6652
Swap:      1048568       1928    1046640

dbmail ~ # w
 11:21:21 up 35 min,  1 user,  load average: 0.32, 1.31, 1.18
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
root     ttyS0     11:21    0.00s  0.20s  0.02s w


dbmail ~ # ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   3984     8 ?        Ss   10:45   0:00 init [3]      
root         2  0.0  0.0      0     0 ?        S    10:45   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    10:45   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    10:45   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    10:45   0:00 [events/0]
root         6  0.0  0.0      0     0 ?        S    10:45   0:00 [khelper]
root        16  0.0  0.0      0     0 ?        S    10:45   0:00 [async/mgr]
root        59  0.0  0.0      0     0 ?        S    10:45   0:00 [sync_supers]
root        61  0.0  0.0      0     0 ?        S    10:45   0:00 [bdi-default]
root        63  0.0  0.0      0     0 ?        S    10:45   0:00 [kblockd/0]
root        64  0.0  0.0      0     0 ?        S    10:45   0:00 [kacpid]
root        65  0.0  0.0      0     0 ?        S    10:45   0:00 [kacpi_notify]
root        66  0.0  0.0      0     0 ?        S    10:45   0:00 [kacpi_hotplug]
root       136  0.0  0.0      0     0 ?        S    10:45   0:00 [kseriod]
root       178  0.0  0.0      0     0 ?        D    10:45   0:01 [kswapd0]
root       179  0.0  0.0      0     0 ?        S    10:45   0:00 [aio/0]
root       180  0.0  0.0      0     0 ?        S    10:45   0:00 [crypto/0]
root       814  0.0  0.0      0     0 ?        S    10:45   0:00 [jbd2/vda1-8]
root       815  0.0  0.0      0     0 ?        S    10:45   0:00 [ext4-dio-unwr]
root       904  0.0  0.0  12600     0 ?        S<s  10:45   0:00 /sbin/udevd --d
root      3866  0.0  0.0  12596     0 ?        S<   10:46   0:00 /sbin/udevd --d
root      3921  0.0  0.0   6076     4 tty1     Ss+  10:46   0:00 /sbin/agetty 38
root      3922  0.0  0.0   6064     4 tty2     Ss+  10:46   0:00 /sbin/agetty 38
root      3923  0.0  0.0   6116     4 tty3     Ss+  10:46   0:00 /sbin/agetty 38
root      3924  0.0  0.0   6096     4 tty4     Ss+  10:46   0:00 /sbin/agetty 38
root      3925  0.0  0.0   6104     4 tty5     Ss+  10:46   0:00 /sbin/agetty 38
root      3926  0.0  0.0   6120     4 tty6     Ss+  10:46   0:00 /sbin/agetty 38
root     28395  0.0  0.0  56192     4 ttyS0    Ss   11:15   0:00 /bin/login -- 
root     28440  0.0  0.0      0     0 ?        S    11:21   0:00 [flush-254:0]
root     28441  0.8  0.0  17920   216 ttyS0    S    11:21   0:00 -bash
root     28448  0.0  0.2  14908  1052 ttyS0    R+   11:21   0:00 ps aux
dbmail ~ # free
             total       used       free     shared    buffers     cached
Mem:        506740     501844       4896          0         76       1716
-/+ buffers/cache:     500052       6688
Swap:      1048568       1960    1046608
dbmail ~ # uname -a
Linux dbmail 2.6.32-hardened-r9-katyusha #3 SMP Tue Jun 15 16:36:13 BST 2010 x86_64 QEMU Virtual CPU version 0.12.4 GenuineIntel GNU/Linux
Comment 4 Anthony Basile gentoo-dev 2010-07-07 19:29:49 UTC
Can the reporter please test the in tree hardened-sources-2.6.32-r9 and see if this is still a problem?
Comment 5 Bert Smith 2010-07-07 20:21:46 UTC
(In reply to comment #4)
> Can the reporter please test the in tree hardened-sources-2.6.32-r9 and see if
> this is still a problem?

Still occurs on hardened-sources-2.6.32-r9 with the same configuration.

Comment 6 Aleister 2010-08-17 18:26:40 UTC
same issue here running kvm on ~amd64 other VMs is working fine besides the gentoo hardened vm (amd64-nomultilib) with virtio disk/net (maybe that could be the problem? since i vaguely remember it not happening when i used emulated pata and the e1000 driver (will test that when i have the time).
host kernel: 2.6.35-gentoo-r1 VM kernel 2.6.32-hardened-r9
Comment 7 Aleister 2010-08-17 18:50:58 UTC
ok tested it it happens even when i used emulated hardware instead of virtio disk/net
Comment 8 Aleister 2010-08-17 18:56:36 UTC
Created attachment 243361 [details]
emerge --info for hardened VM
Comment 9 Anthony Basile gentoo-dev 2010-08-25 19:12:23 UTC
I think that bug #332355 is a special instance of this one, but I'm not 100% sure.  There the memory leak was triggered when using

1. kvm
2. hardened-sources-2.6.32-r9
3. virtio for hardware devices rather than emulating

The workaround is either emulate the hardware (eg use -nic,model=e1000 and compile in e1000 support in the guest kernel) or use kernels later than hs-2.6.32-r9.  -r9 was the last in the grsec-2.1.4 series which was also used in -r7.  Beginning from -r10 on, grsec-2.2.0 was used.

It seems to be working for me.  Can users try -r14 and let me know.


Comment 10 Aleister 2010-08-28 17:46:57 UTC
(In reply to comment #9)
> I think that bug #332355 is a special instance of this one, but I'm not 100%
> sure.  There the memory leak was triggered when using
> 
> 1. kvm
> 2. hardened-sources-2.6.32-r9
> 3. virtio for hardware devices rather than emulating
> 
> The workaround is either emulate the hardware (eg use -nic,model=e1000 and
> compile in e1000 support in the guest kernel) or use kernels later than
> hs-2.6.32-r9.  -r9 was the last in the grsec-2.1.4 series which was also used
> in -r7.  Beginning from -r10 on, grsec-2.2.0 was used.
> 
> It seems to be working for me.  Can users try -r14 and let me know.
> 

again i have just disproved "3" so only 1 and 2 could be the cause ill get back when i have tested -r14
Comment 11 Bert Smith 2010-08-28 17:56:54 UTC
I have tested 2.6.34-hardened-r2 and 2.6.32-hardened-r14 with the same configuration under KVM and both seem to work fine so far, tested with a loop of emerge mysql commands with no problems (previously this same vm would crash during a single emerge mysql process).

However, enabling the new "Prevent invalid userland pointer dereference" option present in these kernels causes a crash on bootup.
Comment 12 Aleister 2010-08-28 21:15:04 UTC
Created attachment 245177 [details]
hardened kvm guest kernel config

attached the kernel config for the guest that is hitting this bug (2.6.32-r9).
Comment 13 Aleister 2010-08-28 22:07:28 UTC
disabling CONFIG_PAX_KERNEXEC (by bluness`s advice) fixed it so it seems like that is the problem with this specific pax/kernel version.
Comment 14 PaX Team 2010-10-02 10:26:47 UTC
can you guys try the latest .32 and .35 PaX test patches (http://www.grsecurity.net/~paxguy1/) and let me know if you still see the memory leak? if you do, can you post /proc/slabinfo in the hope that the leaking structure will show up there?
Comment 15 Anthony Basile gentoo-dev 2010-10-05 18:08:49 UTC
(In reply to comment #14)
> can you guys try the latest .32 and .35 PaX test patches
> (http://www.grsecurity.net/~paxguy1/) and let me know if you still see the
> memory leak? if you do, can you post /proc/slabinfo in the hope that the
> leaking structure will show up there?
> 

Tested and neither show the leak.  slabtop shows very little change as the vm boots.

Again, I'll close this as soon as we have stabilization of kernels which do not exhibit the leak.

Thanks pipacs :)
Comment 16 Anthony Basile gentoo-dev 2010-12-20 23:49:56 UTC
Just stabilized hardened-sources-2.6.32-r31.ebuild and hardened-sources-2.6.36-r6.ebuild which include the fix.  Closing.