From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162924AbdDWRMp convert rfc822-to-8bit (ORCPT ); Sun, 23 Apr 2017 13:12:45 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54288 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162920AbdDWRKe (ORCPT ); Sun, 23 Apr 2017 13:10:34 -0400 Date: Sun, 23 Apr 2017 17:09:34 +0000 From: "Naveen N. Rao" Subject: Re: [PATCH v4 4/7] powerpc/kprobes: Use safer string functions in kprobe_lookup_name() To: Masami Hiramatsu , Michael Ellerman , pc@us.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Ingo Molnar References: <6e14d22994530fb5200c74d1593e73541d3b8028.1492604782.git.naveen.n.rao@linux.vnet.ibm.com> <20170421123320.7344-1-naveen.n.rao@linux.vnet.ibm.com> <5393535f-4469-d6b7-f7ce-256a5612999f@us.ibm.com> In-Reply-To: User-Agent: astroid/0.8 (https://github.com/astroidmail/astroid) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT X-TM-AS-MML: disable x-cbid: 17042317-1617-0000-0000-000001C3E26C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042317-1618-0000-0000-00004803F6B3 Message-Id: <1492967265.w6y5305xmj.astroid@naverao1-tp.none> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-04-23_16:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704230313 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Excerpts from Paul Clarke's message of April 21, 2017 19:22: > Sent too soon. The suggestions don't guarantee null termination. Refined, below. (Sorry for the noise.) Yeah, the string operations here are a bit of a minefield... > > On 04/21/2017 08:33 AM, Paul Clarke wrote: >> On 04/21/2017 07:33 AM, Naveen N. Rao wrote: >>> Convert usage of strchr()/strncpy()/strncat() to >>> strnchr()/memcpy()/strlcat() for simpler and safer string manipulation. > >>> diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c >>> index 97b5eed1f76d..c73fb6e3b43f 100644 >>> --- a/arch/powerpc/kernel/kprobes.c >>> +++ b/arch/powerpc/kernel/kprobes.c >>> @@ -65,28 +65,27 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset) >>> char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN]; >>> const char *modsym; >>> bool dot_appended = false; >>> - if ((modsym = strchr(name, ':')) != NULL) { >>> + if ((modsym = strnchr(name, ':', MODULE_NAME_LEN)) != NULL) { ... as I just realized this is an epic FAIL! ;/ I will take my time to redo this. - Naveen From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3w9wwJ5nCZzDq8M for ; Mon, 24 Apr 2017 03:10:40 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3NH8uWS003644 for ; Sun, 23 Apr 2017 13:10:33 -0400 Received: from e23smtp05.au.ibm.com (e23smtp05.au.ibm.com [202.81.31.147]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a0mqfb1pa-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 23 Apr 2017 13:10:33 -0400 Received: from localhost by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Apr 2017 03:10:30 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3NHAKZ447513672 for ; Mon, 24 Apr 2017 03:10:28 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3NH9teN018304 for ; Mon, 24 Apr 2017 03:09:56 +1000 Date: Sun, 23 Apr 2017 17:09:34 +0000 From: "Naveen N. Rao" Subject: Re: [PATCH v4 4/7] powerpc/kprobes: Use safer string functions in kprobe_lookup_name() To: Masami Hiramatsu , Michael Ellerman , pc@us.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Ingo Molnar References: <6e14d22994530fb5200c74d1593e73541d3b8028.1492604782.git.naveen.n.rao@linux.vnet.ibm.com> <20170421123320.7344-1-naveen.n.rao@linux.vnet.ibm.com> <5393535f-4469-d6b7-f7ce-256a5612999f@us.ibm.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Message-Id: <1492967265.w6y5305xmj.astroid@naverao1-tp.none> List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Excerpts from Paul Clarke's message of April 21, 2017 19:22: > Sent too soon. The suggestions don't guarantee null termination. Refine= d, below. (Sorry for the noise.) Yeah, the string operations here are a bit of a minefield... >=20 > On 04/21/2017 08:33 AM, Paul Clarke wrote: >> On 04/21/2017 07:33 AM, Naveen N. Rao wrote: >>> Convert usage of strchr()/strncpy()/strncat() to >>> strnchr()/memcpy()/strlcat() for simpler and safer string manipulation. >=20 >>> diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobe= s.c >>> index 97b5eed1f76d..c73fb6e3b43f 100644 >>> --- a/arch/powerpc/kernel/kprobes.c >>> +++ b/arch/powerpc/kernel/kprobes.c >>> @@ -65,28 +65,27 @@ kprobe_opcode_t *kprobe_lookup_name(const char *nam= e, unsigned int offset) >>> char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN]; >>> const char *modsym; >>> bool dot_appended =3D false; >>> - if ((modsym =3D strchr(name, ':')) !=3D NULL) { >>> + if ((modsym =3D strnchr(name, ':', MODULE_NAME_LEN)) !=3D NULL) { ... as I just realized this is an epic FAIL! ;/ I will take my time to redo this. - Naveen =