lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 4 Jan 2023 16:35:15 +0800
From:   "liaochang (A)" <liaochang1@...wei.com>
To:     Björn Töpel <bjorn@...nel.org>,
        Chen Guokai <chenguokai17@...ls.ucas.ac.cn>,
        <paul.walmsley@...ive.com>, <palmer@...belt.com>,
        <aou@...s.berkeley.edu>, <rostedt@...dmis.org>, <mingo@...hat.com>,
        <sfr@...b.auug.org.au>
CC:     <linux-riscv@...ts.infradead.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v5 6/9] riscv/kprobe: Add code to check if kprobe can be
 optimized



在 2023/1/3 2:04, Björn Töpel 写道:
> Chen Guokai <chenguokai17@...ls.ucas.ac.cn> writes:
> 
>> From: Liao Chang <liaochang1@...wei.com>
> 
>> diff --git a/arch/riscv/kernel/probes/opt.c b/arch/riscv/kernel/probes/opt.c
>> index a0d2ab39e3fa..258a283c906d 100644
>> --- a/arch/riscv/kernel/probes/opt.c
>> +++ b/arch/riscv/kernel/probes/opt.c
>> @@ -271,15 +271,103 @@ static void find_free_registers(struct kprobe *kp, struct optimized_kprobe *op,
>>  	*ra = (kw == 1UL) ? 0 : __builtin_ctzl(kw & ~1UL);
>>  }
>>  
>> +static bool insn_jump_into_range(unsigned long addr, unsigned long start,
>> +				 unsigned long end)
>> +{
>> +	kprobe_opcode_t insn = *(kprobe_opcode_t *)addr;
>> +	unsigned long target, offset = GET_INSN_LENGTH(insn);
>> +
>> +#ifdef CONFIG_RISCV_ISA_C
>> +	if (offset == RVC_INSN_LEN) {
>> +		if (riscv_insn_is_c_beqz(insn) || riscv_insn_is_c_bnez(insn))
>> +			target = addr + rvc_branch_imme(insn);
>> +		else if (riscv_insn_is_c_jal(insn) || riscv_insn_is_c_j(insn))
>> +			target = addr + rvc_jal_imme(insn);
>> +		else
>> +			target = 0;
>> +		return (target >= start) && (target < end);
>> +	}
>> +#endif
>> +
>> +	if (riscv_insn_is_branch(insn))
>> +		target = addr + rvi_branch_imme(insn);
>> +	else if (riscv_insn_is_jal(insn))
>> +		target = addr + rvi_jal_imme(insn);
>> +	else
>> +		target = 0;
>> +	return (target >= start) && (target < end);
>> +}
>> +
>> +static int search_copied_insn(unsigned long paddr, struct optimized_kprobe *op)
>> +{
>> +	int i =  1;
>> +	unsigned long offset = GET_INSN_LENGTH(*(kprobe_opcode_t *)paddr);
>> +
>> +	while ((i++ < MAX_COPIED_INSN) && (offset < 2 * RVI_INSN_LEN)) {
>> +		if (riscv_probe_decode_insn((probe_opcode_t *)paddr + offset,
>> +					    NULL) != INSN_GOOD)
> 
> If the second argument is NULL, and the insn is auipc, we'll splat with
> NULL-ptr exception.

Good catch, it is my fault to ignore the access to second argument in macro RISCV_INSN_SET_SIMULATE.

> 
> Hmm, probe_opcode_t is u32, right? And GET_INSN_LENGTH() returns 4 or 2
> ...then the pointer arithmetic will be a mess?

Hmm, This pointer arithemtic does make no sense here, i had debugged this function on QEMU step by step,
and it work well. Anyway, i will go through this function again, thanks.

> 
> 
> Björn

-- 
BR,
Liao, Chang

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ