diff mbox

[v3,1/7] kpartx: don't keep creating recursive partitions

Message ID 1487125017-22049-2-git-send-email-bmarzins@redhat.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show

Commit Message

Benjamin Marzinski Feb. 15, 2017, 2:16 a.m. UTC
If the dos partition table is corrupted, kpartx can just keep creating
the same partitions until it runs out of partition numbers. This check
catches the recursion.

Signed-off-by: Cedric Buissart <cbuissar@redhat.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 kpartx/dos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christophe Varoqui Feb. 27, 2017, 6:03 a.m. UTC | #1
Applied.

On Wed, Feb 15, 2017 at 3:16 AM, Benjamin Marzinski <bmarzins@redhat.com>
wrote:

> If the dos partition table is corrupted, kpartx can just keep creating
> the same partitions until it runs out of partition numbers. This check
> catches the recursion.
>
> Signed-off-by: Cedric Buissart <cbuissar@redhat.com>
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
> ---
>  kpartx/dos.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kpartx/dos.c b/kpartx/dos.c
> index 64b27b6..4985152 100644
> --- a/kpartx/dos.c
> +++ b/kpartx/dos.c
> @@ -46,7 +46,7 @@ read_extended_partition(int fd, struct partition *ep,
> int en,
>                 for (i=0; i<2; i++) {
>                         memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof
> (p));
>                         if (is_extended(p.sys_type)) {
> -                               if (p.nr_sects && !moretodo) {
> +                               if (p.start_sect && p.nr_sects &&
> !moretodo) {
>                                         next = start + sector_size_mul *
> le32_to_cpu(p.start_sect);
>                                         moretodo = 1;
>                                 }
> --
> 1.8.3.1
>
>
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

diff --git a/kpartx/dos.c b/kpartx/dos.c
index 64b27b6..4985152 100644
--- a/kpartx/dos.c
+++ b/kpartx/dos.c
@@ -46,7 +46,7 @@  read_extended_partition(int fd, struct partition *ep, int en,
 		for (i=0; i<2; i++) {
 			memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
 			if (is_extended(p.sys_type)) {
-				if (p.nr_sects && !moretodo) {
+				if (p.start_sect && p.nr_sects && !moretodo) {
 					next = start + sector_size_mul * le32_to_cpu(p.start_sect);
 					moretodo = 1;
 				}