LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-05-2023, 02:06 PM   #1
henly
LQ Newbie
 
Registered: May 2023
Posts: 3

Rep: Reputation: 0
Wipe previously used memory from a shutdown VM without shutting down the host


I have a server that hosts a number of kvm/qemu VMs. I'd like to assure that after a VM is shutdown, sensitive information from the memory used by the VM is overwritten under the assumption that a memory dump or something could extract the information even after the VM is destroyed. This is sort of like defending against cold boot attacks but I don't want to shut down the whole server to assure things are cleared so the traditional defenses don't really apply.

I haven't been able to figure out how reuse of memory space when stopping and restarting a virtual machine would play out so to be safe I would have to assume that no memory would be reused so that potentially any available memory on the host could still contain the previous VMs state. Cold boot defenses like rebooting to memtest or running shmem or other wipers on shutdown of the VM couldn't really be relied upon based on the same assumption. Or maybe that isn't true? So overwriting all available memory after the VM is shutdown seems the only logical path.

In researching I've seen users suggest filling up 95% of memory and having the OMM kill the task to prevent the system from crashing. My system by default has no swap at all. I thought of enhancing this idea somewhat by temporarily enabling a swap file to prevent the crash and so that all available memory can be hit.

I guess I'm just looking for any blindspots in my thinking or better ideas
 
Old 05-05-2023, 03:01 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Others here may disagree with me, @henly, but I am quite confident that your concerns are unfounded.

When a virtual machine ceases to exist, all of its resources are released. Sensitive data might be here-or-there in physical memory "for the time being," but none of it is accessible. I do not consider the scenario that you are worrying about to be a credible threat.
 
2 members found this post helpful.
Old 05-05-2023, 03:44 PM   #3
henly
LQ Newbie
 
Registered: May 2023
Posts: 3

Original Poster
Rep: Reputation: 0
I'll be happy to be wrong on this topic! But by what measure is none of the previously used memory accessible? I'm aware of AMD supporting a method of memory encryption for virtual machines but my processor does not support it.
 
Old 05-05-2023, 06:26 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Get real. If you're hosting material that's actually sensitive (illegal?) enough that you're thinking about this, then you would smash that power button so fast that no-one would even see you move.

Last edited by dugan; 05-05-2023 at 07:57 PM.
 
Old 05-05-2023, 06:43 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Some search hits I got that might interest you:

https://security.stackexchange.com/q...ory-space-afte

https://superuser.com/questions/8944...y-applications

The first link has a link to what you're asking for. Direct link:

https://en.wikibooks.org/wiki/Grsecu...l_freed_memory

Last edited by dugan; 05-08-2023 at 09:29 PM.
 
1 members found this post helpful.
Old 05-05-2023, 09:43 PM   #6
henly
LQ Newbie
 
Registered: May 2023
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for the links @dugan The idea seems similar to a bash script I saw here:

https://stackoverflow.com/questions/...-snapshot-size

Quote:
#!/bin/bash

echo 3 > /proc/sys/vm/drop_caches
memfree=$(free -m | awk '/^Mem/ {print $4-32}')
if [ $memfree -gt 0 ]; then
dd if=/dev/zero of=/dev/null bs=${memfree}M count=1
fi
I guess my real question is now, how does swap behave in an OOM situation like this? Does linux start swapping out previously used blocks in an effort to maintain some available real memory (for performance) or does it exhaust the real and only then start using swap?

-----------------

This is adjacent to my question somewhat but this was an interesting discussion to me:
https://security.stackexchange.com/q...boot-clear-ram

This suggested that if a PC was running or simply suspended to ram that getting a dump of (almost) everything in ram was pretty trivial as you could just reboot into a custom OS that was designed for that purpose. I'd never thought about that before, my PC suspends to ram when not in use or I leave it on. I hardly ever reboot so all my bank passwords are probably just sitting there!
 
Old 05-06-2023, 02:44 PM   #7
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Quote:
This suggested that if a PC was running or simply suspended to ram that getting a dump of (almost) everything in ram was pretty trivial as you could just reboot into a custom OS that was designed for that purpose.
Code:
sudo head /dev/mem | hexdump -C
sudo cat /dev/mem | hexdump -C | less
dd if=/dev/mem of=ramfile
Edit:
Quote:
Does linux start swapping out previously used blocks in an effort to maintain some available real memory
Depends on where you have swappiness set to.

Last edited by teckk; 05-06-2023 at 02:45 PM.
 
Old 05-08-2023, 12:55 PM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Quote:
... by what measure is none of the previously used memory accessible?
Here's a thirty-second primer on virtual memory. Every process runs in an environment where it appears to have "memory" exclusive to itself. But the reality is that hardware features are used to translate the addresses issued by the program to the (unknowable ...) actual location in physical-RAM where the information resides. If the information is not now present in physical RAM, an interrupt is generated which causes Linux to retrieve ("swap in") the requested information and make it available ... suspending the process until this has been done, at which time the process resumes execution, "none the wiser."

The information in question may have been "swapped out" to disk since it was "not recently used." In which case the data will be read ("swapped") back in. Or it may be that the location had never been referenced before, in which case Linux will allocate a physical memory page, set it entirely to zero, and then make it available.

Either way, the "memory" that is available to any process is always its purely-virtual picture. Data "left over" from any other process is never available. As far as any process is concerned, "it is the only game in town."

When actual "pressure" exists for the physical-RAM resource, Linux is constantly scanning for "not recently used" memory-pages that can be "swapped out" to disk to make room. In a crisis situation that should never happen, the "OOM killer = Out-of-Memory killer" can start killing-off processes to free up room.

A virtual-machine (VM) monitor uses the same mechanisms to manage the VMs.

Last edited by sundialsvcs; 05-08-2023 at 12:58 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shutting down of daemons during Ubuntu shutdown Richard Rahl Ubuntu 2 03-02-2011 08:19 PM
Shutting down and non shutting down x windows golden_boy615 Linux - General 1 03-01-2010 06:28 AM
Database doesn't shutdown during shutting down the server shipon_97 Linux - Enterprise 0 08-11-2007 11:12 AM
Shutdown not shutting down completely jrdioko Linux - Newbie 19 10-12-2003 11:47 AM
Connection not shutting down on shutdown or restart tyrann Linux - Networking 2 07-12-2003 11:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration