diff --git a/python-libmount.changes b/python-libmount.changes index 302d6f4..e0a1faf 100644 --- a/python-libmount.changes +++ b/python-libmount.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu May 19 14:29:27 CEST 2016 - sbrabec@suse.com + +- blkid: Wipe corect area for probes with offset (bsc#976141, + util-linux-libblkid-wipe-offset.patch). + ------------------------------------------------------------------- Tue Apr 26 18:24:40 CEST 2016 - sbrabec@suse.com diff --git a/python-libmount.spec b/python-libmount.spec index 88695ca..c48bcda 100644 --- a/python-libmount.spec +++ b/python-libmount.spec @@ -155,6 +155,8 @@ Source51: blkid.conf ## ## util-linux patches ## +# PATCH-FIX-UPSTREAM util-linux-libblkid-wipe-offset.patch bsc976141 sbrabec@suse.com -- blkid: Wipe corect area for probes with offset +Patch: util-linux-libblkid-wipe-offset.patch # PATCH-EXTEND-UPSTREAM: Let `su' handle /sbin and /usr/sbin in path Patch4: make-sure-sbin-resp-usr-sbin-are-in-PATH.diff BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -392,6 +394,7 @@ library. xzcat %{S:0} | %gpg_verify -p %{_name} %{S:12} - %endif %setup -q -n %{_name}-%{version} -b 40 +%patch -p1 %patch4 -p1 # # setctsid diff --git a/util-linux-libblkid-wipe-offset.patch b/util-linux-libblkid-wipe-offset.patch new file mode 100644 index 0000000..e2b82d7 --- /dev/null +++ b/util-linux-libblkid-wipe-offset.patch @@ -0,0 +1,100 @@ +From 445e6b1ec82642a298419bdd18a81110593bfbaa Mon Sep 17 00:00:00 2001 +From: Petr Uzel +Date: Mon, 18 Apr 2016 16:22:05 +0200 +Subject: [PATCH] libblkid: make blkid_do_wipe() work with probes with offset + +When a probe is created with an offset, e.g. via +blkid_probe_set_device(), this offset is correctly used when looking for +the signatures, but is not respected by blkid_do_wipe() function. +Therefore the signature is removed from an invalid location. + +Usecase: Wiping signatures from an area on the block device where +partition is to be created (but as it does not exist yet, there's no +device node for it and probe on the whole block device has to be used +with correct offset and length). + +Reproducer: +======================== wiper.c =========================== + +const char *dev; +unsigned long offset; +unsigned long size; + +int main(int argc, char** argv) { + + if (argc != 4) { + printf("usage: wiper dev offset size\n"); + exit(1); + } + + dev = argv[1]; + offset = strtoull(argv[2], NULL, 10); + size = strtoull(argv[3], NULL, 10); + + printf("dev=%s, off=%llu, size=%llu\n", dev, offset, size); + + int fd = open (dev, O_RDWR); + if (fd == -1) { + perror("open"); + exit(1); + } + + blkid_loff_t wipe_offset = offset * SECTOR_SIZE; + blkid_loff_t wipe_size = size * SECTOR_SIZE; + + int ret; + + blkid_probe pr; + pr = blkid_new_probe(); + if (!pr) + return 0; + ret = blkid_probe_set_device(pr, fd, wipe_offset, wipe_size); + ret = blkid_probe_enable_superblocks(pr, 1); + ret = blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC); + + while (blkid_do_probe(pr) == 0) { + ret = blkid_do_wipe(pr, 0); + } + + blkid_free_probe(pr); + close(fd); +} +======================== wiper.c =========================== + +Steps to reproduce: +modprobe scsi_debug +parted -s /dev/sdX mklabel gpt +parted -s /dev/sdX mkpart first 2048s 4095s +mkfs.ext2 /dev/sdX1 + +wipefs -np /dev/sdX1 + +./wiper /dev/sdX1 2048 2048 + +Actual result: wiper gets into endless loop, because +blkid_do_wipe() wipes at wrong location (1080), leaving the signature +on /dev/sdc1. So it is again found by blkid_do_probe(), and so on. + +Expected result: wiper clears the ext2 signature at offset 1049656(=1080+2048*512). + +Signed-off-by: Petr Uzel +--- + libblkid/src/probe.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c +index 34d97b8..0c8625c 100644 +--- a/libblkid/src/probe.c ++++ b/libblkid/src/probe.c +@@ -1121,7 +1121,7 @@ int blkid_do_wipe(blkid_probe pr, int dryrun) + if (rc || len == 0 || off == NULL) + return 0; + +- offset = strtoumax(off, NULL, 10); ++ offset = strtoumax(off, NULL, 10) + pr->off; + fd = blkid_probe_get_fd(pr); + if (fd < 0) + return -1; +-- +2.8.1 + diff --git a/util-linux-systemd.changes b/util-linux-systemd.changes index 302d6f4..e0a1faf 100644 --- a/util-linux-systemd.changes +++ b/util-linux-systemd.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu May 19 14:29:27 CEST 2016 - sbrabec@suse.com + +- blkid: Wipe corect area for probes with offset (bsc#976141, + util-linux-libblkid-wipe-offset.patch). + ------------------------------------------------------------------- Tue Apr 26 18:24:40 CEST 2016 - sbrabec@suse.com diff --git a/util-linux-systemd.spec b/util-linux-systemd.spec index 7a96495..1564473 100644 --- a/util-linux-systemd.spec +++ b/util-linux-systemd.spec @@ -155,6 +155,8 @@ Source51: blkid.conf ## ## util-linux patches ## +# PATCH-FIX-UPSTREAM util-linux-libblkid-wipe-offset.patch bsc976141 sbrabec@suse.com -- blkid: Wipe corect area for probes with offset +Patch: util-linux-libblkid-wipe-offset.patch # PATCH-EXTEND-UPSTREAM: Let `su' handle /sbin and /usr/sbin in path Patch4: make-sure-sbin-resp-usr-sbin-are-in-PATH.diff BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -392,6 +394,7 @@ library. xzcat %{S:0} | %gpg_verify -p %{_name} %{S:12} - %endif %setup -q -n %{_name}-%{version} -b 40 +%patch -p1 %patch4 -p1 # # setctsid diff --git a/util-linux.changes b/util-linux.changes index 302d6f4..e0a1faf 100644 --- a/util-linux.changes +++ b/util-linux.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu May 19 14:29:27 CEST 2016 - sbrabec@suse.com + +- blkid: Wipe corect area for probes with offset (bsc#976141, + util-linux-libblkid-wipe-offset.patch). + ------------------------------------------------------------------- Tue Apr 26 18:24:40 CEST 2016 - sbrabec@suse.com diff --git a/util-linux.spec b/util-linux.spec index 608f8cd..6ca47c7 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -155,6 +155,8 @@ Source51: blkid.conf ## ## util-linux patches ## +# PATCH-FIX-UPSTREAM util-linux-libblkid-wipe-offset.patch bsc976141 sbrabec@suse.com -- blkid: Wipe corect area for probes with offset +Patch: util-linux-libblkid-wipe-offset.patch # PATCH-EXTEND-UPSTREAM: Let `su' handle /sbin and /usr/sbin in path Patch4: make-sure-sbin-resp-usr-sbin-are-in-PATH.diff BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -392,6 +394,7 @@ library. xzcat %{S:0} | %gpg_verify -p %{_name} %{S:12} - %endif %setup -q -n %{_name}-%{version} -b 40 +%patch -p1 %patch4 -p1 # # setctsid