From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941288AbdDTGI4 (ORCPT ); Thu, 20 Apr 2017 02:08:56 -0400 Received: from ozlabs.org ([103.22.144.67]:59019 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938142AbdDTGIy (ORCPT ); Thu, 20 Apr 2017 02:08:54 -0400 From: Michael Ellerman To: "Naveen N. Rao" , Ingo Molnar Cc: Ananth N Mavinakayanahalli , Masami Hiramatsu , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/7] kprobes: validate the symbol name length In-Reply-To: <6e14d22994530fb5200c74d1593e73541d3b8028.1492604782.git.naveen.n.rao@linux.vnet.ibm.com> References: <6e14d22994530fb5200c74d1593e73541d3b8028.1492604782.git.naveen.n.rao@linux.vnet.ibm.com> User-Agent: Notmuch/0.21 (https://notmuchmail.org) Date: Thu, 20 Apr 2017 16:08:52 +1000 Message-ID: <87o9vr4nm3.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Naveen N. Rao" writes: > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 6a128f3a7ed1..bb86681c8a10 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -1382,6 +1382,28 @@ bool within_kprobe_blacklist(unsigned long addr) > return false; > } > > +bool is_valid_kprobe_symbol_name(const char *name) > +{ > + size_t sym_len; > + char *s; > + > + s = strchr(name, ':'); > + if (s) { > + sym_len = strnlen(s+1, KSYM_NAME_LEN); > + if (sym_len <= 0 || sym_len >= KSYM_NAME_LEN) > + return false; > + sym_len = (size_t)(s - name); > + if (sym_len <= 0 || sym_len >= MODULE_NAME_LEN) > + return false; > + } else { > + sym_len = strnlen(name, MODULE_NAME_LEN); > + if (sym_len <= 0 || sym_len >= MODULE_NAME_LEN) > + return false; > + } I think this is probably more elaborate than it needs to be. Why not just check the string is <= (MODULE_NAME_LEN + KSYM_NAME_LEN) ? cheers