Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1250426pxb; Sat, 4 Sep 2021 04:43:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNrj2OyKWMp1UiuXJsnSmlrgec9RfNblsNawaeFV8BthPqBGIjsTB7uhXTHNuT9TuSPNnN X-Received: by 2002:a17:906:29d3:: with SMTP id y19mr3779198eje.361.1630755806421; Sat, 04 Sep 2021 04:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630755806; cv=none; d=google.com; s=arc-20160816; b=V4xWCYx9+lNOhNdk8ghgwJZNemVadeLg9Yaw2uRV9i/hsleBlz2mC9+DJP0cc9MEdJ AQfoE+SUw4xetjPyv/VYbgTizQbwcWtHzL08LllmVINN3DWnUgTYIbsQ5azdd1ltFyzc 1v9DwH2j0aSmY22dlQYiwMJxyF+jt6x3ZyVVUzSQNYky73WLC36pXACIbu97WgSI+RUC sDA2JioYEYqTMFXKuLbLLQOXMaSCFK+RIJ/H0KeA+z7Mr9RER+uePoyZtI5exb0utSQH zMsJhdWgfIcBq5i+odxKZAfViWDzarbHRJL7G5t5OCFLZaVRkHj+kj6gxmlWhzO2cB1W /aNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FFQFmz4LQBStJcbIqRzZxa/cVfQkAhrEZqVs/debk/o=; b=p2HNnakXEyBUv5lE4LO0EAIHyyIEUFJ8XE6iKszhPTpastfy4EnMR73PqucO/SJ4wM P7E3Mc3Hsk+lhHENAfC6qvGEPFSsv0OvlEwKv7Q2lbWE5LK7/NEzuSjUeNzMZ/56+i9B f7HqzeexCDwFeXRsXKCqU843uLcLxO23Ag1YKVobk9aqce2R08kngYWCqTMPdZunHD1h Bf3JvYtoeyWtcEG7OjcxKjdjDn6iG+XmrZm5NepCVd9WJJO/awKSN9Dij42W8Y+QQHuT q9v61PaqwyGA9PeaSz9vyoJ+wkXZf/K3ojgiO5rZmXgQl4aaCLTohceJLAKbOWmi8D2N c07w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=Dq4T0yII; 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 mp6si2187941ejc.384.2021.09.04.04.42.34; Sat, 04 Sep 2021 04:43:26 -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=Dq4T0yII; 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 S1351109AbhIDLYf (ORCPT + 99 others); Sat, 4 Sep 2021 07:24:35 -0400 Received: from mout.gmx.net ([212.227.15.19]:33071 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234482AbhIDLYf (ORCPT ); Sat, 4 Sep 2021 07:24:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1630754598; bh=oNeNfx2Pff1MWMSsLtAuLuPTtNZrnmhUxJ32Wbzy0PQ=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=Dq4T0yIIxdhcaG7ubWZf6umefhUbVnJM96o4nRUvZeFWuKlp6+2tV6tTi9eh9dhYi n4Zm24xU9PW5q/JZkCB5PAx4Px5jd7tz3NDYZ6DVlN0SvonHW9+PJWz79bzDwt0jfB 9n69iEydC1gJzeA9iRqfcn49u+yYcfc7a4SWdJMw= 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 1M6Db0-1mKGqc2Geu-006fjl; Sat, 04 Sep 2021 13:23:18 +0200 Date: Sat, 4 Sep 2021 13:23:03 +0200 From: Len Baker To: Joe Perches Cc: Len Baker , Borislav Petkov , Mauro Carvalho Chehab , Tony Luck , James Morse , Robert Richter , David Laight , Kees Cook , linux-hardening@vger.kernel.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6] EDAC/mc: Prefer strscpy or scnprintf over strcpy Message-ID: <20210904094451.GA2998@titan> References: <20210903150539.7282-1-len.baker@gmx.com> <3a035a3ec4571a622ce640e042f9a119@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3a035a3ec4571a622ce640e042f9a119@perches.com> X-Provags-ID: V03:K1:NdVm4hX0KwBB2OaFVM6rjj/Cadbwqs5ugUJfNJk7Ty+WXs1tLIe cd8ytx9mGoQ1OW+qjqlWJO1rXOQxyIt1P4fm8Mn29xxlljrZ+lXG3q04Wmo9dXo8cERCtn0 cOX3p0pDk30ysHvv+juk+ncPbBJebBwLsIKbswEJLA1kui0gQKWJsJpQa/k+zUui6IjEHTH lUWFNgv8gI3TmFG+W8sww== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:+kOwGOz9i50=:n3oD+TWpsWVH3tZ47rLE33 xNKfDTS10b1eWX3wB4Yarw9c59AWrxRQd6QXhd2CnnzYVKy6ujAdQApf1GG6qu9JdGXM2zJFV 7jli3iY6Rc7WMXezeImPqXDSByr3NLpgvxdaiazkhhYZ31QiTl0Af91ajdRXpU3JyhvfTA8+n dNUxTsheNJP4CgI19FDD3OlZdK4SannMVX7f1MkB1btpM4pgQ7OH90Hrq87SBer+R92FsnOi+ cM9qwFZYeH9zqrisJ01wXulEv6EUpzQdqBKbiBBdq7uxnwcnwC23mb4mhTxJW+/5QtNJMNNW+ C5FBFVm7iBBwiVt9aNvkfbr+tZjL3jqMsGgbYOqqbbt6MyM0PCcQVwPAr57L2Q8J2tAFJYeP/ MEIQHb8493jqt5e1qNoXOiW8TUVAqq17k+DZLcVkRc8BNPQqv9iRRUiVH3t3H1lgV0maRO7g4 It50hJ3iZvKiHjeWBFgtPX+WwmjXFkFmgzeLY6okJd37m5jgSOYE9h6ZFLpWN1dcAsX3Q6S8Y GeOZ4NAUPhVlzgokTnSWz3FH+T7UWreq1eB8nT6kLM+VRjuZXzExAf1bx4CQzg6AN60lunxcU KP8B1R/ILroWP0CYimeXtIqp02A1GWF0935yhVPLSWlUns9CQZHmV9GnP/sa35w7ruS9GeDQK dTuHO1k3Tt6XvEmtS62A4FU+zgBv6HURI/8ARpJ7cPrYY/I1L68EVwOE+2FfusVkEqJKtkJI1 WP2VkWvRJGiseEXbRP4qUyMsdGBD64FxTlE8uUaKIR2Mpy5Api2/6VTYDN0nMbD/gdFZSvf9Z 7su3MpJSFU98JXalmmGNW0P+q8u8euThJO7NECBGuCga9f3/KusE9/ueeBRQRo6s7MYzOfWPD faVmwKWHErErrqDrEQ0VZRunCRL4wGq0w9cFFob+4yUb+LY/VcwD5n+GaTQAFNzy64bhfe2JO 70f4AkNUE7Cc6NUEJGDfhSoj769f3sjid1Gbf2sU2Ir6TGp7SPlRyjjTutWT7y6bJIPFlf93a fZV4C8L5tcDGUaqTIkBMTWx4S0CkwE0kA/z+2A61vIZJ4Iov90OrKgzrWu4Kl2r5pE3RmS1wV /gjmct5YEhWaS+F/+EFuprjyliYuSIDBBsyVtamhQIz5YFmBi0xksQVvQ== Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Sep 03, 2021 at 10:03:18AM -0700, Joe Perches wrote: > On 2021-09-03 08:05, Len Baker wrote: > > strcpy() performs no bounds checking on the destination buffer. > > len.baker@gmx.com/ > > [] > > > @@ -1113,12 +1115,9 @@ void edac_mc_handle_error(const enum > > hw_event_mc_err_type type, > > p =3D e->label; > > *p =3D '\0'; > > } else { > > - if (p !=3D e->label) { > > - strcpy(p, OTHER_LABEL); > > - p +=3D strlen(OTHER_LABEL); > > - } > > - strcpy(p, dimm->label); > > - p +=3D strlen(p); > > + n +=3D scnprintf(e->label + n, sizeof(e->label) - n, > > + "%s%s", prefix, dimm->label); > > + prefix =3D OTHER_LABEL; > > OTHER_LABEL is a define specific to this module > > IMO: Used once text macros are just obfuscating and should be removed. This macro is used in "/include/linux/edac.h" as follows: struct edac_raw_error_desc { [...] char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * EDAC_MAX_LABEL= S]; [...] }; If we remove this define the size of label would be: char label[(EDAC_MC_LABEL_LEN + 6) * EDAC_MAX_LABELS]; So, I think now is more complicated to understand because the size is what it is. If you prefer this option, I can remove the macro and add a comment with some explanation. Regards, Len