Adding early checks for ELF file

Change-Id: I1dc833fc2b017edae5c5456b14c376e88ca2bef7
Bu işleme şunda yer alıyor:
Giovanni LB
2024-08-26 17:41:20 -03:00
ebeveyn 41fd850601
işleme 698b6eb641
2 değiştirilmiş dosya ile 18 ekleme ve 0 silme
+9
Dosyayı Görüntüle
@@ -77,6 +77,15 @@ CodeObjDecoderComponent::CodeObjDecoderComponent(
uint64_t codeobj_size, uint64_t codeobj_size,
uint64_t gpu_id uint64_t gpu_id
) { ) {
if (
codeobj_size <= 4 ||
codeobj_data[0] != ELFMAG0 ||
codeobj_data[1] != ELFMAG1 ||
codeobj_data[2] != ELFMAG2 ||
codeobj_data[3] != ELFMAG3
)
throw std::invalid_argument("Invalid ELF file");
m_fd = -1; m_fd = -1;
#if defined(_GNU_SOURCE) && defined(MFD_ALLOW_SEALING) && defined(MFD_CLOEXEC) #if defined(_GNU_SOURCE) && defined(MFD_ALLOW_SEALING) && defined(MFD_CLOEXEC)
m_fd = ::memfd_create(m_uri.c_str(), MFD_ALLOW_SEALING | MFD_CLOEXEC); m_fd = ::memfd_create(m_uri.c_str(), MFD_ALLOW_SEALING | MFD_CLOEXEC);
+9
Dosyayı Görüntüle
@@ -162,6 +162,15 @@ DisassemblyInstance::DisassemblyInstance(
uint64_t gpu_id uint64_t gpu_id
) )
{ {
if (
codeobj_size <= 4 ||
codeobj_data[0] != ELFMAG0 ||
codeobj_data[1] != ELFMAG1 ||
codeobj_data[2] != ELFMAG2 ||
codeobj_data[3] != ELFMAG3
)
throw std::invalid_argument("Invalid ELF file");
buffer = std::vector<char>(codeobj_size, 0); buffer = std::vector<char>(codeobj_size, 0);
std::memcpy(buffer.data(), codeobj_data, codeobj_size); std::memcpy(buffer.data(), codeobj_data, codeobj_size);