From: Oleh Nykyforchyn Subject: [PATCH v2 1/2] server: Return STATUS_IMAGE_INVALID_NOT_MZ on create_mapping for a fake 16 bit dll. Message-Id: <20211014230202.14270-1-olen.nyk@gmail.com> Date: Fri, 15 Oct 2021 02:02:01 +0300 If request ( create_mapping ) returns STATUS_IMAGE_INVALID_WIN_16 for a file, then the search fails, but STATUS_IMAGE_INVALID_NOT_MZ triggers attempt to load *.so file instead in ntdll. It allows to run 16 bin applications again. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51564 Signed-off-by: Oleh Nykyforchyn --- server/mapping.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/server/mapping.c b/server/mapping.c index 93dae94b7c4..af9e92fcf25 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -697,6 +697,13 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s mz_size = size; pos = mz.dos.e_lfanew; + mapping->image.image_flags = 0; + mapping->image.loader_flags = 0; + if (mz_size == sizeof(mz) && !memcmp( mz.buffer, builtin_signature, sizeof(builtin_signature) )) + mapping->image.image_flags |= IMAGE_FLAGS_WineBuiltin; + else if (mz_size == sizeof(mz) && !memcmp( mz.buffer, fakedll_signature, sizeof(fakedll_signature) )) + mapping->image.image_flags |= IMAGE_FLAGS_WineFakeDll; + size = pread( unix_fd, &nt, sizeof(nt), pos ); if (size < sizeof(nt.Signature) + sizeof(nt.FileHeader)) return STATUS_INVALID_IMAGE_PROTECT; /* zero out Optional header in the case it's not present or partial */ @@ -707,7 +714,13 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s { IMAGE_OS2_HEADER *os2 = (IMAGE_OS2_HEADER *)&nt; if (os2->ne_magic != IMAGE_OS2_SIGNATURE) return STATUS_INVALID_IMAGE_PROTECT; - if (os2->ne_exetyp == 2) return STATUS_INVALID_IMAGE_WIN_16; + if (os2->ne_exetyp == 2) + { + if (mapping->image.image_flags & IMAGE_FLAGS_WineFakeDll) + return STATUS_INVALID_IMAGE_NOT_MZ; + else + return STATUS_INVALID_IMAGE_WIN_16; + } if (os2->ne_exetyp == 5) return STATUS_INVALID_IMAGE_PROTECT; return STATUS_INVALID_IMAGE_NE_FORMAT; } @@ -737,7 +750,6 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s nt.opt.hdr32.SectionAlignment & page_mask); mapping->image.header_size = nt.opt.hdr32.SizeOfHeaders; mapping->image.checksum = nt.opt.hdr32.CheckSum; - mapping->image.image_flags = 0; if (nt.opt.hdr32.SectionAlignment & page_mask) mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat; if ((nt.opt.hdr32.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) && @@ -769,7 +781,6 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s nt.opt.hdr64.SectionAlignment & page_mask); mapping->image.header_size = nt.opt.hdr64.SizeOfHeaders; mapping->image.checksum = nt.opt.hdr64.CheckSum; - mapping->image.image_flags = 0; if (nt.opt.hdr64.SectionAlignment & page_mask) mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat; if ((nt.opt.hdr64.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) && @@ -788,10 +799,6 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s mapping->image.zerobits = 0; /* FIXME */ mapping->image.file_size = file_size; mapping->image.loader_flags = clr_va && clr_size; - if (mz_size == sizeof(mz) && !memcmp( mz.buffer, builtin_signature, sizeof(builtin_signature) )) - mapping->image.image_flags |= IMAGE_FLAGS_WineBuiltin; - else if (mz_size == sizeof(mz) && !memcmp( mz.buffer, fakedll_signature, sizeof(fakedll_signature) )) - mapping->image.image_flags |= IMAGE_FLAGS_WineFakeDll; /* load the section headers */ -- 2.33.0