Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp243030ybl; Tue, 20 Aug 2019 19:11:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXm9VR3MKwUU4IS9P7wtGB9NBR9leORHgboDrStKVRbYZDofU9f+hm7CubsANaH4BNxUxu X-Received: by 2002:a63:e306:: with SMTP id f6mr26823479pgh.39.1566353485074; Tue, 20 Aug 2019 19:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566353485; cv=none; d=google.com; s=arc-20160816; b=yABmqTV1EgM59yT9ZWecJtjDD2124lMseWwdnab0l1pTaVy9mWMpMUMvok7oocahuk AjBnS4qjIrlLL+bNhfhk3CX7eMCe0Mv61HmtzgVtqtZM8OxzJgZQrE1KMDNPF+/IWZn0 iU8rB/f8ymxHuXusEvQJ/AjXK4TDZaYd0HebpqDwp2a2WQMEV3P+9KQZJ6jUWSBw44bm 0vnQeXQL9+hLocyv7rFZw9ZlxCSS//pmVaBuncyzjKBXzYfO9DXDshvLInD+rFGg64Sb vKW4gACfq7sI1Zv1E6HUoHoCiKeSKxC8iFatf0hHNY9IM3B13+cytAQKq2fuxxW6pFyH uDoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=lcSvMESqbvZIhFUYnwa9vRznzlotJ/0bMoQbwZs2T0o=; b=WoPt/0Yyiw+3CaOmps9e2U7KvuPIWtBzYcYgz06gh86oFSsSCs5pSpeNtrbwoYByl3 EfULaqRn013cTIyrQPMG9FzAYshQyDQ9tnrudh28P/orPwsrdQURuT9fbnkecDsFoBnK Rcthd9xKxz60KZXwUHDrqaKhluVEf2UP7QAdkQhH1Yh7vigtF5HtDujBltfj4z2XgbEV HEHvzKrsM3MlGIuZevjX9bl7ZvifyiEJifpHvXgtduf8Rwe/7ok4qqjEhYiovqdsLV90 vVYMM/B3pJRY/I9uEYmtCvXRIJheKlU7tqjx57aOSltDC3CFA6UPpFmheqqjDsGr8Ltu fWiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ahk39hs1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7si1239417pjn.50.2019.08.20.19.11.10; Tue, 20 Aug 2019 19:11:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ahk39hs1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbfHUCHr (ORCPT + 99 others); Tue, 20 Aug 2019 22:07:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:50214 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726804AbfHUCHq (ORCPT ); Tue, 20 Aug 2019 22:07:46 -0400 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E84E422DA7; Wed, 21 Aug 2019 02:07:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566353265; bh=Zqudwk65vUNNG7cwLAF4ZWtWBzan/Kk8MUshf8f8kpk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ahk39hs1grZsNJL1+z7+Stu7VoJZ6O9TIOL6aijYhsOVJd9K6tq6DKj/KQriJd21r svftHv/8MJx99tArPBUKMT+U7s4YdKHNLSSKQpMISNCjo/gzLMrZLMkqHq+Ug/srgk ncfFglDJPhJxDZGJ/AK4fNUdUy2nxumdQ2pKTRsQ= Date: Wed, 21 Aug 2019 11:07:39 +0900 From: Masami Hiramatsu To: Jisheng Zhang , Steven Rostedt Cc: Catalin Marinas , Jonathan Corbet , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "x86@kernel.org" , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH v2 2/3] kprobes: adjust kprobe addr for KPROBES_ON_FTRACE Message-Id: <20190821110739.fb3ab6b69423dff64a3b4a29@kernel.org> In-Reply-To: <20190820114224.0c8963c4@xhacker.debian> References: <20190820113928.1971900c@xhacker.debian> <20190820114224.0c8963c4@xhacker.debian> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jisheng, On Tue, 20 Aug 2019 03:53:31 +0000 Jisheng Zhang wrote: > For KPROBES_ON_FTRACE case, we need to adjust the kprobe's addr > correspondingly. Either KPROBES_ON_FTRACE=y or not, ftrace_location() check must be done correctly. If it failed, kprobes can modify the instruction which can be modified by ftrace. > > Signed-off-by: Jisheng Zhang > --- > kernel/kprobes.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 9873fc627d61..3fd2f68644da 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -1484,15 +1484,19 @@ static inline int check_kprobe_rereg(struct kprobe *p) > > int __weak arch_check_ftrace_location(struct kprobe *p) > { > - unsigned long ftrace_addr; > + unsigned long ftrace_addr, addr = (unsigned long)p->addr; > > - ftrace_addr = ftrace_location((unsigned long)p->addr); > +#ifdef CONFIG_KPROBES_ON_FTRACE > + addr = ftrace_call_adjust(addr); > +#endif > + ftrace_addr = ftrace_location(addr); No, this is not right way to do. If we always need to adjust address before calling ftrace_location(), something wrong with ftrace_location() interface. ftrace_location(addr) must check the address is within the range which can be changed by ftrace. (dyn->ip <= addr <= dyn->ip+MCOUNT_INSN_SIZE) > if (ftrace_addr) { > #ifdef CONFIG_KPROBES_ON_FTRACE > /* Given address is not on the instruction boundary */ > - if ((unsigned long)p->addr != ftrace_addr) > + if (addr != ftrace_addr) > return -EILSEQ; > p->flags |= KPROBE_FLAG_FTRACE; > + p->addr = (kprobe_opcode_t *)addr; And again, please don't change the p->addr silently. Thank you, > #else /* !CONFIG_KPROBES_ON_FTRACE */ > return -EINVAL; > #endif > -- > 2.23.0.rc1 > -- Masami Hiramatsu