Check for LD_DW at the end of a program (#6821)

This commit is contained in:
Jack May 2019-11-08 13:30:44 -08:00 committed by GitHub
parent 8babecd890
commit 346213da4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 10 deletions

View File

@ -25,14 +25,6 @@ fn check_prog_len(prog: &[u8]) -> Result<(), Error> {
reject("No program set, call prog_set() to load one".to_string())?;
}
// TODO BPF program may deterministically exit even if the last
// instruction in the block is not an exit (might be earlier and jumped to)
// TODO need to validate more intelligently
// let last_insn = ebpf::get_insn(prog, (prog.len() / ebpf::INSN_SIZE) - 1);
// if last_insn.opc != ebpf::EXIT {
// reject("program does not end with “EXIT” instruction".to_string())?;
// }
Ok(())
}
@ -55,8 +47,10 @@ fn check_imm_endian(insn: &ebpf::Insn, insn_ptr: usize) -> Result<(), Error> {
}
fn check_load_dw(prog: &[u8], insn_ptr: usize) -> Result<(), Error> {
// We know we can reach next insn since we enforce an EXIT insn at the end of program, while
// this function should be called only for LD_DW insn, that cannot be last in program.
if insn_ptr >= (prog.len() / ebpf::INSN_SIZE) {
// Last instruction cannot be LD_DW because there would be no 2nd DW
reject("LD_DW instruction cannot be last in program".to_string())?;
}
let next_insn = ebpf::get_insn(prog, insn_ptr + 1);
if next_insn.opc != 0 {
reject(format!(