Received: by 2002:a05:6520:45c5:b0:135:a20d:b557 with SMTP id t5csp2136217lkv; Mon, 23 Aug 2021 10:31:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6wYhkUedPuT+vdz/6Yx8MKBSV0GPvRPaSnkKYpqf+iUeEbYXDbDWyKHgLaQWODMY2iWKy X-Received: by 2002:a17:907:a043:: with SMTP id gz3mr14168748ejc.366.1629739907144; Mon, 23 Aug 2021 10:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629739907; cv=none; d=google.com; s=arc-20160816; b=ARurgH7iIW/SSqnKomorQhlrQIKezUolDHF2THHPIlgGqEpBuAjO/pdMkRmyMpk6Pl 80TQwf1RP61Tty9QLC6RzOw07seerhU+oQEmn/KeDWuRI/VAilDd0sC0aQHkQ5yqqdBO TED/8G7GexKfnLmjLmp2dGb9pwJngmbkfrimZMQ/Obupxilo+++sPDByzgS4bjtjsfWe iSlxMz45AugYRIpdSS+sS6WjvVBEBjm92s1E5Dhtqj3P517HMvm+F9G2BgQoclz3qB9J kz8XVq29O2FoPJPSsp74B261H9rYoCDrE73yzKQktqRZLDbkgC4OU+bICOfEwb3Fj2hp KJlA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=k7kW0H/f78ipggRR3pMr7cXUnVjI28dbJ/hrQ806WjA=; b=hlBz57Kp9+wEVsepg7TRYxG84nfaMBCh/aSOZ4IjIw1/ug1FcGnvtXcqDgFFJmgjSG yOd9LCAtbdM2tUPxB7IqC17Sywk3Aia8CUaLCvCpBSoCQXxH351FXArEhLmqp9bxjoZG Mrad2GRxuj+rNK15DJaOr5qPg37yWPryiEIYCiYD/51wHS3LIfe/qUqTPktquictPejb hA+kdKNM1haTjHzhgaK11+jqtLgazqXYrK3NaUMlZgNvQAV36NCTTEGu14PHPCNMyyn0 iFWZNHZroDyzNkQCuzaGqjOaT0vajQe2j7OqlReb8op+JcWgvc8gVJNJrjl3wb5VZSWJ yG9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=hDhXULFW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z10si4093016edd.2.2021.08.23.10.31.22; Mon, 23 Aug 2021 10:31:47 -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=@alien8.de header.s=dkim header.b=hDhXULFW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229694AbhHWRaq (ORCPT + 99 others); Mon, 23 Aug 2021 13:30:46 -0400 Received: from mail.skyhub.de ([5.9.137.197]:42596 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbhHWRap (ORCPT ); Mon, 23 Aug 2021 13:30:45 -0400 Received: from zn.tnic (p200300ec2f07d9009c2198849783fa17.dip0.t-ipconnect.de [IPv6:2003:ec:2f07:d900:9c21:9884:9783:fa17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 63E151EC0354; Mon, 23 Aug 2021 19:29:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1629739797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=k7kW0H/f78ipggRR3pMr7cXUnVjI28dbJ/hrQ806WjA=; b=hDhXULFWcHFsoJBIsrfHxmwpgT3Wnl9sEleCLnWDCuz5POadrad9gy5ajW3R69VqkH+gH5 9K0Vr0mUo/r33+mjTLFeLTpCv/rZPsIGkCo79PEIkh4IMsknG5IJuzQARW/Ns9Myjbjs+G dE1D547ttNlcLZzDNJGnSf6K/ahRXc0= Date: Mon, 23 Aug 2021 19:30:34 +0200 From: Borislav Petkov To: Len Baker Cc: Mauro Carvalho Chehab , Tony Luck , James Morse , Robert Richter , Joe Perches , David Laight , Kees Cook , linux-hardening@vger.kernel.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] EDAC/mc: Prefer strscpy over strcpy Message-ID: References: <20210814075527.5999-1-len.baker@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210814075527.5999-1-len.baker@gmx.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 14, 2021 at 09:55:27AM +0200, Len Baker wrote: > strcpy() performs no bounds checking on the destination buffer. This > could result in linear overflows beyond the end of the buffer, leading > to all kinds of misbehaviors. The safe replacement is strscpy(). > > This is a previous step in the path to remove the strcpy() function "previous step"? > entirely from the kernel. > > Signed-off-by: Len Baker ... > diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c > index f6d462d0be2d..7aea6c502316 100644 > --- a/drivers/edac/edac_mc.c > +++ b/drivers/edac/edac_mc.c > @@ -1032,6 +1032,7 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type, > int i, n_labels = 0; > struct edac_raw_error_desc *e = &mci->error_desc; > bool any_memory = true; > + size_t len; > > edac_dbg(3, "MC%d\n", mci->mc_idx); > > @@ -1086,6 +1087,7 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type, > */ > p = e->label; > *p = '\0'; > + len = sizeof(e->label); > > mci_for_each_dimm(mci, dimm) { > if (top_layer >= 0 && top_layer != dimm->location[0]) > @@ -1114,10 +1116,12 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type, > *p = '\0'; > } else { > if (p != e->label) { > - strcpy(p, OTHER_LABEL); > - p += strlen(OTHER_LABEL); > + strscpy(p, OTHER_LABEL, len); Hm, maybe I'm missing something but looking at that strscpy() definition, why aren't you doing: num = strscpy(p, OTHER_LABEL, len); if (num < 0) /* just in case */ break; len -= num; p += num; since that function supposedly returns the number of chars copied. > + len -= strlen(p); > + p += strlen(p); > } > - strcpy(p, dimm->label); > + strscpy(p, dimm->label, len); > + len -= strlen(p); > p += strlen(p); Ditto. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette