Re: [PATCH 1/2] x86/kprobes: Fix kprobes instruction boudary check with CONFIG_RETHUNK

From: Peter Zijlstra
Date: Wed Sep 07 2022 - 03:06:58 EST


On Wed, Sep 07, 2022 at 09:55:21AM +0900, Masami Hiramatsu (Google) wrote:

> +/* Return the jump target address or 0 */
> +static inline unsigned long insn_get_branch_addr(struct insn *insn)
> +{
> + switch (insn->opcode.bytes[0]) {
> + case 0xe0: /* loopne */
> + case 0xe1: /* loope */
> + case 0xe2: /* loop */

Oh cute, objtool doesn't know about those, let me go add them.

> + case 0xe3: /* jcxz */
> + case 0xe9: /* near relative jump */

/* JMP.d32 */

> + case 0xeb: /* short relative jump */

/* JMP.d8 */

> + break;
> + case 0x0f:
> + if ((insn->opcode.bytes[1] & 0xf0) == 0x80) /* jcc near */

/* Jcc.d32 */

Are the GNU AS names for these things.

> + break;
> + return 0;

> + default:
> + if ((insn->opcode.bytes[0] & 0xf0) == 0x70) /* jcc short */
> + break;
> + return 0;

You could write that as:

case 0x70 ... 0x7f: /* Jcc.d8 */
break;

default:
return 0;

> + }
> + return (unsigned long)insn->next_byte + insn->immediate.value;
> +}