Ticket #8434: protectGPT.patch

File protectGPT.patch, 1.9 KB (added by zymoticb, 8 years ago)

Patch that will cause the intel partition parser to exit with B_BAD_DATA if it detects the GPT signature.

  • src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp

    diff --git a/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp b/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp
    index e94b020..509cd91 100644
    a b  
    2222#include "PartitionMapParser.h"
    2323
    2424
    25 //#define TRACE_ENABLED
     25#define TRACE_ENABLED
    2626#ifdef TRACE_ENABLED
    2727#   ifdef _USER_MODE
    2828#       define TRACE(x) printf x
    PartitionMapParser::_ReadPartitionTable(off_t offset, partition_table* table)  
    309309        TRACE(("intel: _ReadPartitionTable(): reading the partition table "
    310310            "failed: %lx\n", error));
    311311    }
     312        //check for GPT signature "EFI PART"
     313        //located in the 8bytes following the mbr
     314        char gptSignature[8] = {0};
     315        if (read_pos(fDeviceFD, fSessionOffset + sizeof(partition_table), &gptSignature, kGPTSignatureSize) != kGPTSignatureSize) {
     316 #ifndef _BOOT_MODE
     317        error = errno;
     318        if (error == B_OK)
     319            error = B_IO_ERROR;
     320#else
     321        error = B_IO_ERROR;
     322#endif
     323                TRACE(("intel: _ReadPartitionTable(): checking for GPT signature "
     324                        "failed: %lx\n", error));
     325        }
     326        if( strcmp(gptSignature, "EFI PART") == 0)
     327        {
     328            TRACE(("intel: _ReadPartitionTable(): Disk is formatted as GPT. "
     329                        "GPT disks are currently unsupported\n"));
     330            error = B_BAD_DATA;
     331        }
     332
    312333    return error;
    313334}
    314335
  • src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h

    diff --git a/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h b/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h
    index 7034bac..8ca10ee 100644
    a b private:  
    5454            PartitionMap*       fMap;
    5555};
    5656
     57static const int32 kGPTSignatureSize = 8;
     58
    5759#endif  // PARTITION_MAP_PARSER_H