From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932498AbdJ0BZn (ORCPT ); Thu, 26 Oct 2017 21:25:43 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:9434 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932431AbdJ0BZR (ORCPT ); Thu, 26 Oct 2017 21:25:17 -0400 Message-ID: <59F28AB7.4000300@huawei.com> Date: Fri, 27 Oct 2017 09:24:07 +0800 From: zhouchengming User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Masami Hiramatsu CC: , , , Subject: Re: [PATCH] kprobes: avoid the kprobe being re-registered References: <1509019885-58481-1-git-send-email-zhouchengming1@huawei.com> <20171026233944.d56f558c01275e70744c2add@kernel.org> In-Reply-To: <20171026233944.d56f558c01275e70744c2add@kernel.org> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.236.183] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A010202.59F28AF6.001B,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 6d4459248c4d3af60ff3e0704f75612d Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017/10/26 22:39, Masami Hiramatsu wrote: > On Thu, 26 Oct 2017 20:11:25 +0800 > Zhou Chengming wrote: > >> Old code use check_kprobe_rereg() to check if the kprobe has been >> registered already, but check_kprobe_rereg() will release the >> kprobe_mutex then, so maybe two paths will pass the check and >> register the same kprobe. This patch put the check inside the mutex. > Still no good, see below comment. > >> Signed-off-by: Zhou Chengming >> --- >> kernel/kprobes.c | 23 ++++++----------------- >> 1 file changed, 6 insertions(+), 17 deletions(-) >> >> diff --git a/kernel/kprobes.c b/kernel/kprobes.c >> index a1606a4..2a4873a 100644 >> --- a/kernel/kprobes.c >> +++ b/kernel/kprobes.c >> @@ -1443,19 +1443,6 @@ static struct kprobe *__get_valid_kprobe(struct kprobe *p) >> return ap; >> } >> >> -/* Return error if the kprobe is being re-registered */ >> -static inline int check_kprobe_rereg(struct kprobe *p) >> -{ >> - int ret = 0; >> - >> - mutex_lock(&kprobe_mutex); >> - if (__get_valid_kprobe(p)) >> - ret = -EINVAL; >> - mutex_unlock(&kprobe_mutex); >> - >> - return ret; >> -} >> - >> int __weak arch_check_ftrace_location(struct kprobe *p) >> { >> unsigned long ftrace_addr; >> @@ -1536,10 +1523,6 @@ int register_kprobe(struct kprobe *p) >> return PTR_ERR(addr); >> p->addr = addr; >> >> - ret = check_kprobe_rereg(p); >> - if (ret) >> - return ret; >> - >> /* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */ >> p->flags&= KPROBE_FLAG_DISABLED; >> p->nmissed = 0; > here, we already modifies the kprobe. We need to check and reject before modifying it. > > Thank you, Ah, right. We should put the modifies after the re-reg check. I will send a patch-v2. Thank you. >> @@ -1551,6 +1534,12 @@ int register_kprobe(struct kprobe *p) >> >> mutex_lock(&kprobe_mutex); >> >> + /* Return error if the kprobe is being re-registered */ >> + if (__get_valid_kprobe(p)) { >> + ret = -EINVAL; >> + goto out; >> + } >> + >> old_p = get_kprobe(p->addr); >> if (old_p) { >> /* Since this may unoptimize old_p, locking text_mutex. */ >> -- >> 1.8.3.1 >> >