ca9d7ec3ba
- Fix blkid swap recognition on big-endian boxes (#445786)
60 lines
2.1 KiB
Diff
60 lines
2.1 KiB
Diff
[PATCH] blkid: more sanity checks for swap v1
|
|
|
|
mkswap followed by pvcreate on a block device
|
|
will still turn up as "swap" in blkid, because
|
|
pvcreate isn't particularly careful about zeroing
|
|
old signatures. (neither is mkswap, for that matter).
|
|
|
|
Testing for appropriate version and page counts
|
|
gives us a bit more confidence that we have a
|
|
real swap (v1) partition.
|
|
|
|
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
|
|
---
|
|
lib/blkid/probe.c | 7 ++++++-
|
|
1 files changed, 6 insertions(+), 1 deletions(-)
|
|
|
|
diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c
|
|
index 45885c3..a070201 100644
|
|
--- a/lib/blkid/probe.c
|
|
+++ b/lib/blkid/probe.c
|
|
@@ -827,7 +827,7 @@ static int probe_swap0(struct blkid_probe *probe,
|
|
}
|
|
|
|
static int probe_swap1(struct blkid_probe *probe,
|
|
- struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
+ struct blkid_magic *id,
|
|
unsigned char *buf __BLKID_ATTR((unused)))
|
|
{
|
|
struct swap_id_block *sws;
|
|
@@ -843,6 +843,11 @@ static int probe_swap1(struct blkid_probe *probe,
|
|
if (!sws)
|
|
return 1;
|
|
|
|
+ /* check for wrong version or zeroed pagecount, for sanity */
|
|
+ if (!memcmp(id->bim_magic, "SWAPSPACE2", id->bim_len) &&
|
|
+ (sws->sws_version != 1 || sws->sws_lastpage == 0))
|
|
+ return 1;
|
|
+
|
|
/* arbitrary sanity check.. is there any garbage down there? */
|
|
if (sws->sws_pad[32] == 0 && sws->sws_pad[33] == 0) {
|
|
if (sws->sws_volume[0])
|
|
--- a/lib/blkid/test_probe.in 2008-05-12 11:50:41.580983841 -0500
|
|
+++ b/lib/blkid/test_probe.in 2008-05-12 11:51:21.323436536 -0500
|
|
@@ -20,6 +20,15 @@ do
|
|
continue
|
|
fi
|
|
bunzip2 < $SRCDIR/tests/$i.img.bz2 > /tmp/test.img.$$
|
|
+ # swap is native-endian, so regenerate before testing
|
|
+ if [ "$i" == "swap0" ]; then
|
|
+ dd if=/dev/zero of=/tmp/test.img.$$ bs=1024 count=1 seek=1024
|
|
+ mkswap -v0 /tmp/test.img.$$ > /dev/null
|
|
+ elif [ "$i" == "swap1" ]; then
|
|
+ dd if=/dev/zero of=/tmp/test.img.$$ bs=1024 count=1 seek=1024
|
|
+ mkswap -v1 -L SWAP-TEST -U 8ff8e77f-8553-485e-8656-58be67a81666 /tmp/test.img.$$ >/dev/null
|
|
+ fi
|
|
+
|
|
./tst_probe /tmp/test.img.$$ > tests/$i.out
|
|
/bin/rm -f /tmp/test.img.$$ tests/$i.ok tests/$i.failed
|
|
cmp -s tests/$i.out $SRCDIR/tests/$i.results
|