Bcc:
Subject: fs/binfmt_elf: Integer Overflow vulnerability report Reply-To:
I'm sharing a report of an integer overflow vulnerability I found (in fs/binfmt_elf.c). I sent and discussed this vulnerability report with members of [email protected]. I'm raising this for public discussion, with approval from Greg ([email protected]).
Quoted 46 lines · Itay Iellin
In
fs/binfmt_elf.c, line 1193,e_entryvalue can be overflowed. This potentially allows to create a fake entry point field for an ELF file.The local variable
e_entryis set toelf_ex->e_entry+load_bias. Given anET_DYNELF file, without aPT_INTERPprogram header, with anelf_ex->e_entryfield in the ELF header, which equals to 0xffffffffffffffff(inx86_64for example), and aload_biaswhich is greater than 0,e_entry(the local variable)overflows. This bypasses the check ofBAD_ADDRmacro in line 1241.It is possible to set a large enough NO-OP(NOP) sled, before the actual code, modify the
elf_ex->e_entryfield so that elf_ex->e_entry+load_bias will be in the range where the NO-OP sled ismapped(because the offset of the PT_LOAD program header of the text segment can be controlled). This is practically a guess, becauseload_biasis randomized, the ELF file can be loaded a large amount of times untilelf_ex->e_entry+load_biasis in the range of the NO-OP sled.
To conclude, this bug potentially allows the creation of a "fake" entry point field in the ELF file header.Suggested git diff:
Add a
BAD_ADDRtest toelf_ex->e_entryto prevent from using an overflowedelf_entryvalue.Signed-off-by Itay Iellin <[email protected]>--- fs/binfmt_elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/binfmt_elf.c +1
-1@@ -1238,7 +1238,7 @@ static int load_elf_binary(struct linux_binprm *bprm)kfree (interp_elf_phdata); }else { elf_entry = e_entry; -if (BAD_ADDR (elf_entry)) { +if (BAD_ADDR (elf_entry) ||BAD_ADDR (elf_ex->e_entry)) { retval = -EINVAL ; goto out_free_dentry; }Signature · 1 line
2.32.0
I am not attaching the replies to my initial report from the discussion with members of [email protected], only when or if I will be given permission from the repliers to do so.
Itay Iellin