midenok / stuff-linux

Linux-related setup and utilities stuff: scripts, instructions, etc.
3 stars 1 forks source link

udisks-helper-modify-partition infinite loop on changing partition type #2

Open midenok opened 10 years ago

midenok commented 10 years ago

https://bugs.launchpad.net/ubuntu/+source/udisks/+bug/694060

midenok commented 10 years ago

https://bugs.launchpad.net/udisks/+bug/689593

midenok commented 10 years ago
Affected drive:
(parted) p
Model: Generic USB SD Reader (scsi)
Disk /dev/sdb: 1948254208B
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start        End          Size         Type     File system  Flags
 1      32256B       1948197887B  1948165632B  primary  fat32        boot, lba
 2      1948197888B  1948230143B  32256B       primary               hidden, lba
Affected command:
udisks-helper-modify-partition /dev/sdb 32256 1948165632 0x0c boot

Command was to not modify size -- size is the same!

midenok commented 10 years ago

partutil.c:

1807          if (*out_size < new_size)
1808            {
1809              DEBUG ("new_size=%lld but resulting size, %lld, smaller than requested", new_size, *out_size);
1810              new_end_sector++;
1811              goto try_change_again;
1812            }

new_end_sector is increasing beyond drive size:

(parted) p
Model: Generic USB SD Reader (scsi)
Disk /dev/sdb: 3805184s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start     End       Size      Type     File system  Flags
 1      63s       3805073s  3805011s  primary  fat32        boot, lba
 2      3805074s  3805136s  63s       primary               hidden, lba
(gdb) b 1811
Breakpoint 2 at 0x404b0a: file partutil.c, line 1811.
(gdb) commands 2
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>silent
>p new_end_sector
>end
(gdb) c
Continuing.
$1 = 5831611
(gdb) c
Continuing.
$2 = 5831612
(gdb) c
Continuing.
$3 = 5831613
(gdb) c
Continuing.
$4 = 5831614
midenok commented 10 years ago

There should be at least check against device->length:

(gdb) p *device
$9 = {
  next = 0x0,
  model = 0xc154e0 "Generic USB SD Reader",
  path = 0xc143a0 "/dev/sdb",
  type = PED_DEVICE_SCSI,
  sector_size = 512,
  phys_sector_size = 512,
  length = 3805184,
...

But more correct will be check against current partition size + free space after it.

midenok commented 10 years ago
To sum up, there are two problems with the code in part_add_change_partition():
  1. no limit for new_end_sector;
  2. it tries to change partition size while the requested size is exact match of existing size.