Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3720399pxt; Tue, 10 Aug 2021 09:46:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7C7k3Rhj8BJkJlgw2OIpBT9neky9jupsDVt5wh71jIqZOJik5S3O+qGz2Ic+ms6C1rSm/ X-Received: by 2002:a05:6402:1a4c:: with SMTP id bf12mr5966001edb.137.1628614004578; Tue, 10 Aug 2021 09:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628614004; cv=none; d=google.com; s=arc-20160816; b=BH7DTTp64HEmPIyiCmYzCwAXSPHsMv3uIV+iLAm4FGa1fvKEu91Am0i9CMVwb/5tCk TAwkTqt9rAZmjLUU9yMNGgQGl73YcDUfp3sEU1LJNWStT99IXYpW6vECbOeWrketHYQk zimOgwE69Ag79cZxFEq651IKmMEjvp5tS58oh/5sNwrN9LvbOhr3RJHdIHKwMx0ib375 wQhWKYbrI+oDYu/siJYtiMdxT6dyCxjVtdqvq7ycnP5shicY1YRkzhrSvdvIjxtgdQ6B 2r0IX7RtiAPHcOS/qVx9h8w52VlZg82ciyUL5rLN011lYjT5TlxiNpQO3mANO4CcEYmN DCiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pp5jSCLUfBazud3M8vpAeIWQGfrH+W+suHfD/QD+PE8=; b=qKzm6w3ggFB/4D6aRTPdkDV8Gph95CYqohYaFUcij6D6yddZLFujKmtHgpcxz9fTaU vAlVRAx+LwEx4e3uHIt0A0+IG/YXqi71QPDC8dmKew8rSMLz5mueNYHSBjfJBNqQNDWn fHV0461T78Bdyckjf3Uv3sskJGmYg2+F3mh2UwBKG59L3DihXhtm8fjDt5mIV1jOGNW3 fBn9UQa+roBvEHET6tM1SqJU1Td1HlhJI7Y8T8IGMszAj8XMRvb/1ih09QOKYNOvLeRD /1SfTTD4pOSvLtSw9GL3qKqXMRvOYIrJHTaFFKWRIMVuFugKLf+eb1P9oOS5Vtwka0dM jfjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=RLpZ0hqW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j25si22424425edr.48.2021.08.10.09.46.15; Tue, 10 Aug 2021 09:46:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=RLpZ0hqW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242247AbhHJQBC (ORCPT + 99 others); Tue, 10 Aug 2021 12:01:02 -0400 Received: from mout.gmx.net ([212.227.15.18]:41865 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239131AbhHJQBA (ORCPT ); Tue, 10 Aug 2021 12:01:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1628611197; bh=G3sM2QcP/MH50Zmwdjb3PS8F5QBGj5Y8VFa/7F2tPSc=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=RLpZ0hqW/lrGAmurvpvHUFQYaAYshU/EL8HTj09Xa1VJXzVbI1pET09X0faIk0+qF TZkmhHf9CmViqUxAAUCF+NxxGBpaiXeCn21JdMnfMEJPC5rbvtkbFoNvkRdRzCd495 83pnkOLc/giyhG64K1K/d/2czIyz0vQGQlpCbT94= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from titan ([79.150.72.99]) by mail.gmx.net (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MAOJV-1mOBOw2Arz-00Bp83; Tue, 10 Aug 2021 17:59:57 +0200 Date: Tue, 10 Aug 2021 17:59:53 +0200 From: Len Baker To: Christophe JAILLET , Bernd Petrovitsch Cc: Andy Gross , Bjorn Andersson , Geert Uytterhoeven , Magnus Damm , Santosh Shilimkar , Len Baker , Kees Cook , David Laight , Robin Murphy , linux-hardening@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v4 2/3] drivers/soc/renesas: Prefer memcpy over strcpy Message-ID: <20210810155953.GB2508@titan> References: <20210808125012.4715-1-len.baker@gmx.com> <20210808125012.4715-3-len.baker@gmx.com> <39485c0e-511c-50a0-83be-f9ce6fc47e67@petrovitsch.priv.at> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Provags-ID: V03:K1:FPnUfg9bHq3mnp/YBiXnJfdCYth5+kd8VoT92LWLiyrQC/T7qWV XqEMPQaChEtvXvpYQ0FF7Z/k5XfSetPCvutFfenyLdouGF3+8FbQSDYSzaKDcHfI9Dhk9pT nqMVMtEa8s6Uo4e8R+j6kuHpbSoJjrUwp2ujWigdUNW475H61eXq4DWibqEpwgxIo8irZ9S IzLJgN8K5DUg2AmYmO3Sw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:xVByGEykzDo=:h92VZnFlg+VkvKpiRFRLaQ xPYCBWL7ImYXcrI8PHzLKgnvx0U0nAtR8VXIPzxaGS2RH0f/a614v6z4l9jMI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XBavobn8ilwZL/8/FvePXAg== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Sun, Aug 08, 2021 at 07:06:30PM +0200, Christophe JAILLET wrote: > Hi, > > Le 08/08/2021 =E0 17:35, Bernd Petrovitsch a =E9crit=A0: > > Hi all! > > > > On 08/08/2021 14:50, Len Baker wrote: > > > strcpy() performs no bounds checking on the destination buffer. This > > > could result in linear overflows beyond the end of the buffer, leadi= ng > > > to all kinds of misbehaviors. So, use memcpy() as a safe replacement= . > > > > > > This is a previous step in the path to remove the strcpy() function > > > entirely from the kernel. > > > > > > Signed-off-by: Len Baker > > > --- > > > drivers/soc/renesas/r8a779a0-sysc.c | 6 ++++-- > > > drivers/soc/renesas/rcar-sysc.c | 6 ++++-- > > > 2 files changed, 8 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/soc/renesas/r8a779a0-sysc.c b/drivers/soc/renes= as/r8a779a0-sysc.c > > > index d464ffa1be33..7410b9fa9846 100644 > > > --- a/drivers/soc/renesas/r8a779a0-sysc.c > > > +++ b/drivers/soc/renesas/r8a779a0-sysc.c > > > @@ -404,19 +404,21 @@ static int __init r8a779a0_sysc_pd_init(void) > > > for (i =3D 0; i < info->num_areas; i++) { > > > const struct r8a779a0_sysc_area *area =3D &info->areas[i]; > > > struct r8a779a0_sysc_pd *pd; > > > + size_t n; > > > > > > if (!area->name) { > > > /* Skip NULLified area */ > > > continue; > > > } > > > > > > - pd =3D kzalloc(sizeof(*pd) + strlen(area->name) + 1, GFP_KERNEL); > > > + n =3D strlen(area->name) + 1; > > > + pd =3D kzalloc(sizeof(*pd) + n, GFP_KERNEL); > > Zeroing the allocated bytes is not needed since it's completly > > overwritten with the strcpy()/memcpy(). > > The strcpy()/memcpy() only overwrites the pd->name field, not the whole = pd > structure. You are right. > I think that it is needed to keep the kzalloc. Yes, I think so. The kzalloc is needed to guarantee that the whole struct = is initialize (all the members are initialized with zeros). Regards, Len > > Just my 2c, > CJ > > > > if (!pd) { > > > error =3D -ENOMEM; > > > goto out_put; > > > } > > > > > > - strcpy(pd->name, area->name); > > > + memcpy(pd->name, area->name, n); > > > pd->genpd.name =3D pd->name; > > > pd->pdr =3D area->pdr; > > > pd->flags =3D area->flags; > > > > And similar for the second hunk. > > > > MfG, > > Bernd > > >