Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 122893 - /etc/init.d/halt.sh patch for overwriting swap partition with zeros on halt - [security-enhancement]
Summary: /etc/init.d/halt.sh patch for overwriting swap partition with zeros on halt -...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-15 02:20 UTC by Stefan Behte (RETIRED)
Modified: 2006-02-26 10:48 UTC (History)
1 user (show)

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


Attachments
/etc/init.d/halt.sh patch for zeroing the swap on halt. configurable via /etc/conf.d/rc (RC_ZERO_SWAP) (halt-zero-swap.patch,737 bytes, patch)
2006-02-15 02:21 UTC, Stefan Behte (RETIRED)
Details | Diff
/etc/conf.d/rc patch for zeroing the swap on halt (RC_ZERO_SWAP) (rc-zero-swap.patch,144 bytes, patch)
2006-02-15 02:22 UTC, Stefan Behte (RETIRED)
Details | Diff
/etc/init.d/halt.sh patch for zeroing the swap on halt. configurable via /etc/conf.d/rc (RC_ZERO_SWAP) (zero_swap.patch,997 bytes, patch)
2006-02-15 11:46 UTC, Stefan Behte (RETIRED)
Details | Diff
/etc/conf.d/rc patch for zeroing the swap on halt (RC_ZERO_SWAP) (rc-zero_swap.patch,301 bytes, patch)
2006-02-15 11:50 UTC, Stefan Behte (RETIRED)
Details | Diff
baselayout-erase-swap.patch (baselayout-erase-swap.patch,831 bytes, patch)
2006-02-15 18:19 UTC, SpanKY
Details | Diff
RC_ERASE_SWAP patch for /etc/init.d/halt.sh (baselayout-erase-swap.patch,815 bytes, patch)
2006-02-16 07:14 UTC, Stefan Behte (RETIRED)
Details | Diff
baselayout-erase-swap (baselayout-erase-swap.patch,858 bytes, patch)
2006-02-16 11:41 UTC, Stefan Behte (RETIRED)
Details | Diff
baselayout-erase-swap patch (I hope the last one :/ ) (baselayout-erase-swap.patch,859 bytes, patch)
2006-02-17 04:48 UTC, Stefan Behte (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Behte (RETIRED) gentoo-dev Security 2006-02-15 02:20:42 UTC
Hello!
The following patch overwrites your swap with zeros (with dd) on halt and then does an mkswap on it so that it's usable when turning on the pc again.

It modifies /etc/init.d/halt.sh and adds a configuration line to /etc/conf.d/rc (RC_ZERO_SWAP=) so that you can turn swap-zeroing on and off easily.

It's a rather simple patch and I'm running it for two weeks now without any problems.

This patch is useful when you can't/don't want/think it's too complicated to use crypto for your swap (in case you're working with an old machine that would run even slower when crypting it).
It's mainly useful for laptops and systems other people (you don't trust) also have physical access to.

Well I'd really like to see it in the baselayout so that I don't have to patch all my machines manually :)

If you don't like the patch at all or the way it works, please tell me - so that I can do thinks properly next time.

-Craig-
Comment 1 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-15 02:21:20 UTC
Created attachment 79837 [details, diff]
/etc/init.d/halt.sh patch for zeroing the swap on halt. configurable via /etc/conf.d/rc (RC_ZERO_SWAP)
Comment 2 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-15 02:22:38 UTC
Created attachment 79838 [details, diff]
/etc/conf.d/rc patch for zeroing the swap on halt (RC_ZERO_SWAP)
Comment 3 Radek Podgorny 2006-02-15 08:40:09 UTC
Cool idea, just be sure to keep it un-selectable... :-) I would be using it on my laptop but not on my main PC...
Comment 4 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-15 09:00:12 UTC
>Cool idea,
Thanks :)

>just be sure to keep it un-selectable... :-)
Sorry, I don't get what you mean (english is not my native language...).

>I would be using it on my laptop but not on my main PC...
I'd use it everywhere. It will be very easy to enable it, and it will bring you (at least some) additional security :)

We'll see if others like it and if gentoo devs are going to integrate it :)
Comment 5 Radek Podgorny 2006-02-15 10:06:33 UTC
Well, neither is mine so it may be my fault. It was just a note for gentoo devs not to hardcode it, but keep it selectable via conf.d...
Comment 6 SpanKY gentoo-dev 2006-02-15 11:19:48 UTC
Comment on attachment 79837 [details, diff]
/etc/init.d/halt.sh patch for zeroing the swap on halt. configurable via /etc/conf.d/rc (RC_ZERO_SWAP)

post a patch by using `diff -u`
Comment 7 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-15 11:46:29 UTC
Created attachment 79860 [details, diff]
/etc/init.d/halt.sh patch for zeroing the swap on halt. configurable via /etc/conf.d/rc (RC_ZERO_SWAP)
Comment 8 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-15 11:50:49 UTC
Created attachment 79861 [details, diff]
/etc/conf.d/rc patch for zeroing the swap on halt (RC_ZERO_SWAP)
Comment 9 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-15 11:53:54 UTC
I'm sorry!
I hope it's correct now (*shiver*)...
Comment 10 SpanKY gentoo-dev 2006-02-15 18:19:46 UTC
Created attachment 79889 [details, diff]
baselayout-erase-swap.patch

try this instead
Comment 11 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-16 06:40:43 UTC
http://bugs.gentoo.org/attachment.cgi?id=79861
It has to be + not - there I think, you swapped the filenames with diff.

Well RC_ZERO_SWAP is better, but contains an error:
if you want to overwrite the partition and do not specify the count= parameter for dd, it gets an error:

dd if=/dev/zero of=/dev/hda3
dd: writing to `/dev/hda3': No space left on device
996031+0 records in
996030+0 records out

when halting the system this results in:
Erasing swap space /dev/hda3 ...       [!!]

-> which means: "failed"

I'm attaching a new patch to solve that.
Comment 12 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-16 07:13:01 UTC
The rc patch: it has to be + not - there I think, you swapped the filenames with diff.

Well RC_ZERO_SWAP is better, but contains an error:
if you want to overwrite the partition and do not specify the count= parameter for dd, it gets an error:

dd if=/dev/zero of=/dev/hda3
dd: writing to `/dev/hda3': No space left on device
996031+0 records in
996030+0 records out

when halting the system this results in:
Erasing swap space /dev/hda3 ...       [!!]

-> which means: "failed"

I'm attaching a new patch to solve that with fdisk -s.
Comment 13 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-16 07:14:05 UTC
Created attachment 79936 [details, diff]
RC_ERASE_SWAP patch for /etc/init.d/halt.sh
Comment 14 SpanKY gentoo-dev 2006-02-16 10:04:27 UTC
Comment on attachment 79936 [details, diff]
RC_ERASE_SWAP patch for /etc/init.d/halt.sh

fdisk isnt portable ... you need to figure out a different way of getting the size
Comment 15 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-16 11:37:22 UTC
Not portable? You mean not running on bsd or so?

Well, dd does it's job fine, but does not returns 0.
Suggestion: using /proc/partions...see the patch.

other mad ideas you probably won't like:

[1]:
dd if=/dev/zero of=${s} bs=4096 &> /dev/null
eend 0

[2]:
echo `dd if=/dev/zero of=${s} bs=4096` &> /dev/null
Then $? will be 0
Comment 16 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-16 11:41:23 UTC
Created attachment 79955 [details, diff]
baselayout-erase-swap
Comment 17 SpanKY gentoo-dev 2006-02-17 04:24:10 UTC
not portable as in not all Linux hosts support it
Comment 18 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-17 04:48:38 UTC
Created attachment 80005 [details, diff]
baselayout-erase-swap patch (I hope the last one :/ )
Comment 19 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-17 04:50:44 UTC
Ah ok.
I'm sorry, but there was a last error in the patch. The bs= had to be 1024!
I've tested the patch several times now and it works fine (finally).
I attached the (hopefully) final version - I'm sorry that it was such a pain.
Comment 20 SpanKY gentoo-dev 2006-02-17 06:19:49 UTC
this:
ssize=$(grep $(basename ${s}) /proc/partitions | awk '{print $3}')

can be written simply as:
ssize=$(awk '$4 == "'${s##*/}'" {print $3}' /proc/partitions 2> /dev/null)
Comment 21 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-17 06:31:55 UTC
Ok, if you prefer it like that.
Shall I create a new patch or are you going to integrate it with you changes?
Comment 22 SpanKY gentoo-dev 2006-02-17 21:59:27 UTC
it isnt a matter of style, the version i posted uses only one fork

added to svn, thanks for the patch
Comment 23 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-19 16:47:02 UTC
Ah, ok.
Thanks for your patience :)
Comment 24 Stefan Behte (RETIRED) gentoo-dev Security 2006-02-26 09:44:04 UTC
Just because I'm not familar with the process of adding patches:
- Who decides if a patch is added to "unstable" and later to the "stable" tree?
- When (if ever) will this one be added?

Thanks.
Comment 25 SpanKY gentoo-dev 2006-02-26 10:48:30 UTC
> Just because I'm not familar with the process of adding patches:
> - Who decides if a patch is added to "unstable" and later to the "stable" tree?

the baselayout maintainers