public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Steinmetz <ast@domdv.de>
To: pavel@suse.cz, Linux Kernel Mailinglist <linux-kernel@vger.kernel.org>
Subject: [PATCH] zero disk pages used by swsusp on resume
Date: Sun, 10 Apr 2005 15:13:59 +0200	[thread overview]
Message-ID: <42592697.8060909@domdv.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 963 bytes --]

It may not be desireable to leave swsusp saved pages on disk after
resume as they may contain sensitive data that was never intended to be
stored on disk in an way (e.g. in-kernel dm-crypt keys, mlocked pages).

The attached simple patch against 2.6.11.2 should fix this by zeroing
the swap pages after reading them.

The patch is by no means perfect. Especially it isn't invoked on error
conditions. However it seems to work during regular operation.

Note that it is not possible to do this from userspace in a performant
way, one has to zero the whole swap partition used for swsusp to achive
a similar effect which quite often means clearing 2GB instead of about a
few 100MB. The difference in speed and power consumption is important
especially for laptops when resuming on battery. The userspace method
also allows for a window in which at least some of the data may still be
read.
-- 
Andreas Steinmetz                       SPAMmers use robotrap@domdv.de

[-- Attachment #2: swsusp.diff --]
[-- Type: text/plain, Size: 1300 bytes --]

--- linux-2.6.11.2/kernel/power/swsusp.c.ast	2005-04-10 14:08:55.000000000 +0200
+++ linux-2.6.11.2/kernel/power/swsusp.c	2005-04-10 14:24:10.000000000 +0200
@@ -112,6 +112,10 @@
 
 static struct swsusp_info swsusp_info;
 
+static struct swsusp_clear {
+	char zero[PAGE_SIZE];
+} __attribute__((packed, aligned(PAGE_SIZE))) swsusp_clear __initdata;
+
 /*
  * XXX: We try to keep some more pages free so that I/O operations succeed
  * without paging. Might this be more?
@@ -1169,6 +1173,29 @@
 
 }
 
+static int __init data_clear(void)
+{
+	struct pbe * p;
+	int error = 0;
+	int i;
+	int mod = nr_copy_pages / 100;
+
+	if (!mod)
+		mod = 1;
+
+	memset(&swsusp_clear, 0, sizeof(swsusp_clear));
+
+	printk( "Clearing disk data (%d pages):     ", nr_copy_pages );
+	for(i = 0, p = pagedir_nosave; i < nr_copy_pages && !error; i++, p++) {
+		if (!(i%mod))
+			printk( "\b\b\b\b%3d%%", i / mod );
+		error = bio_write_page(swp_offset(p->swap_address),
+				  (void *)&swsusp_clear);
+	}
+	printk(" %d done.\n",i);
+	return error;
+}
+
 extern dev_t __init name_to_dev_t(const char *line);
 
 static int __init read_pagedir(void)
@@ -1208,6 +1235,8 @@
 		return error;
 	if ((error = data_read()))
 		free_pages((unsigned long)pagedir_nosave, pagedir_order);
+	else
+		data_clear();
 	return error;
 }
 

             reply	other threads:[~2005-04-10 13:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-10 13:13 Andreas Steinmetz [this message]
2005-04-10 18:40 ` [PATCH] zero disk pages used by swsusp on resume Oliver Neukum
2005-04-10 19:29   ` Andreas Steinmetz
2005-04-10 20:03     ` Oliver Neukum
2005-04-10 20:14       ` Pavel Machek
2005-04-11  3:23         ` Elladan
2005-04-11 10:14           ` Pavel Machek
2005-04-11  7:13         ` Stefan Seyfried
2005-04-11 10:37         ` Oliver Neukum
2005-04-11 16:39           ` Rafael J. Wysocki
2005-04-11 17:02             ` Andreas Steinmetz
2005-04-11 21:27               ` Rafael J. Wysocki
2005-04-12 10:08                 ` Andreas Steinmetz
2005-04-11 14:18         ` Jan Niehusmann
  -- strict thread matches above, loose matches on Subject: below --
2005-04-10 15:03 Pavel Machek
2005-04-10 15:15 ` [PATCH] " Andreas Steinmetz
2005-04-10 18:18   ` Pavel Machek
2005-04-10 18:45     ` Oliver Neukum
2005-04-10 18:56       ` Pavel Machek
2005-04-10 19:33     ` Andreas Steinmetz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42592697.8060909@domdv.de \
    --to=ast@domdv.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox