Re: partx goes into infinite loop deleting partitions when you do not specify a range

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 24, 2010 at 04:39:35PM -0400, Phillip Susi wrote:
> I noticed that running partx -d /dev/sda hangs so I looked into it and
> it seems that it keeps trying to delete partitions forever.  Looking at
> the source the loop condition is:
> 
> while (upper == 0 || lower <= upper)

 Oh, stupid bug.

> And since I did not specify a range, upper is 0 so the loop continues
> forever.  Well, at least until lower wraps back around to 0 which will
> be quite a while since it is an int.
> 
> How should this be fixed?  It seems that removing the first condition
> and defaulting upper to some sane value, like say 256 should do it, but
> it seems there should be a better way.  For that matter, it seems that

 Yes, kernel partition tables parser has the limit 256 partitions
 (and partx has the same limit). See the patch below. Anyway, it's
 temporary solution.

 IMHO the best way is to read /sys/block/<disk> or /etc/partitions
 and call the ioctl for existing partitions only.
 
 The other (simple) way is to read /sys/block/<disk>/range where
 kernel exports the maximal number of partitions for the disk.

> the kernel should start returning an error other than EBUSY or ENXIO
> once you start asking it to delete partition numbers higher than the
> maximum allowed, which would end the loop, but this doesn't seem to happen.

 My plan is to rewrite partx (use libblkid for PT parsing) in the near
 future. We have to move this tool to 21st century :-)

    Karel


>From c86dda7b36e3a6cfc63b9c03f7d275d715d35fd0 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@xxxxxxxxxx>
Date: Wed, 31 Mar 2010 16:38:51 +0200
Subject: [PATCH] partx: fix infinite loop

On Wed, Mar 24, 2010 at 04:39:35PM -0400, Phillip Susi wrote:
> I noticed that running partx -d /dev/sda hangs so I looked into it
> and it seems that it keeps trying to delete partitions forever.

Reported-By: Phillip Susi <psusi@xxxxxxxxxx>
Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
 partx/partx.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/partx/partx.c b/partx/partx.c
index 3d60bf6..14d2609 100644
--- a/partx/partx.c
+++ b/partx/partx.c
@@ -178,6 +178,8 @@ main(int argc, char **argv){
 		while (upper == 0 || lower <= upper) {
 			int err;
 
+			if (lower > MAXSLICES)
+				break;
 			pt.pno = lower;
 			pt.start = 0;
 			pt.length = 0;
-- 
1.6.6
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux