From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751895AbdJ1IsD (ORCPT ); Sat, 28 Oct 2017 04:48:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:58246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751663AbdJ1IsC (ORCPT ); Sat, 28 Oct 2017 04:48:02 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E38D218A5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mhiramat@kernel.org Date: Sat, 28 Oct 2017 17:47:59 +0900 From: Masami Hiramatsu To: Zhou Chengming Cc: , , , Subject: Re: [PATCH v3 2/2] kprobes: initialize probed_mod to NULL Message-Id: <20171028174759.f0e161980b69f35d4fe1c74f@kernel.org> In-Reply-To: <1509096195-21734-2-git-send-email-zhouchengming1@huawei.com> References: <1509096195-21734-1-git-send-email-zhouchengming1@huawei.com> <1509096195-21734-2-git-send-email-zhouchengming1@huawei.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 27 Oct 2017 17:23:15 +0800 Zhou Chengming wrote: > When check_kprobe_address_safe() return fail, the probed_mod > should be set to NULL, because no module refcount held. And we > initialize probed_mod to NULL in register_kprobe() for the same reason. > Ok, it's a kind of hardening code but looks good to me. Acked-by: Masami Hiramatsu Thank you! > Signed-off-by: Zhou Chengming > --- > kernel/kprobes.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 1eeedac..a04588c 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -1488,6 +1488,7 @@ static int check_kprobe_address_safe(struct kprobe *p, > * its code to prohibit unexpected unloading. > */ > if (unlikely(!try_module_get(*probed_mod))) { > + *probed_mod = NULL; > ret = -ENOENT; > goto out; > } > @@ -1514,7 +1515,7 @@ int register_kprobe(struct kprobe *p) > { > int ret; > struct kprobe *old_p; > - struct module *probed_mod; > + struct module *probed_mod = NULL; > kprobe_opcode_t *addr; > > /* Adjust probe address from symbol */ > -- > 1.8.3.1 > -- Masami Hiramatsu