Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2956385pxb; Tue, 24 Aug 2021 11:26:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzz1zDSdG1h+Deq7Z1HytS8xhUltmndNbyW8RPcJ48ABZrZhr8LDsqfQFn3DVIutHrs/9F5 X-Received: by 2002:a6b:be02:: with SMTP id o2mr10109345iof.103.1629829598562; Tue, 24 Aug 2021 11:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629829598; cv=none; d=google.com; s=arc-20160816; b=0Lm4ny+a8vpKukY3jbHT+6MqQ3lU5fGtkpBOO0PyN6tHQ0Wxrv1szwXYsZZHm2CxWJ vHg+zup8Un/YUstgkQNzgvMQpagkPNwccJQPyvb+qwXYRC3PxBZ5g8YC7f/bLZfVQekA OXAtsP90Y81sUsJnl+6hLaIJArBE19fZ30ZC7Hb07MEBgj3erfEhBpTh87xhHJ7dxO02 GTUexl7VZAybD7g3Rsz1admVibUslFC1zm4VwJYyyF1wKaIX1SBEgqUsuG0CeBuhfmgF nUIXXAOn9/sE7Ewg8jG5z9yqbXicC3i96GpxEE0m54nTX4Zy81ShFvF/fZH3Yye1j32f K+qw== 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=zZGkwWSiDZd/SYcLT5qkYvAPUqD+oDPAAEUs5B3f5eo=; b=B73wkXoDgmFRwzo9YtRx+EKviPWCLzq42zyXn/nZAEwIA7+OB98qFcdg782RIiU12O ++MuQfkQkmNy7XPM9MkEySElxmmTWT8JzKpPCY58RIgWP2l8CdjaQA3fC8y/usOXFr3h Hd0zgKLlOgr92Bz31DpnHR3yVS3u8yZCkJGe4YqxkTFt/J7gLjM1kHAY7h9VOoP25Nax 9NXT0qmWzC7dQOWXXbk4TIRoq1QZ+3FMN9UG45xDS+nHzFXtNZPRGhj+XE7wkYZQvrcL NDX24nkSFzatelCnOkDWMmY4W3A29CDB3NaC5forLGKQOVBWP9FMJl7Mupa4dYAkvvR+ kUEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="pbTnW4F/"; 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 t4si1122438iof.69.2021.08.24.11.26.24; Tue, 24 Aug 2021 11:26:38 -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="pbTnW4F/"; 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 S232809AbhHXS0Z (ORCPT + 99 others); Tue, 24 Aug 2021 14:26:25 -0400 Received: from mail.skyhub.de ([5.9.137.197]:34718 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231494AbhHXS0X (ORCPT ); Tue, 24 Aug 2021 14:26:23 -0400 Received: from zn.tnic (p200300ec2f114400ce3b938495d443bc.dip0.t-ipconnect.de [IPv6:2003:ec:2f11:4400:ce3b:9384:95d4:43bc]) (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 6C4981EC01FC; Tue, 24 Aug 2021 20:25:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1629829533; 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=zZGkwWSiDZd/SYcLT5qkYvAPUqD+oDPAAEUs5B3f5eo=; b=pbTnW4F/JQeXpkgNJypk6W3fcyJRq66+e87oCG9qDGS0mzB8LkGjt6fK0Fonzv12eLyJiE jR7+b6gKUtixMAMoyFEtTRt8783+maqHC/tqknnYhkZpQrRGfpBNMR454EiBJhe+lwMIsL eshGboOwyzHABQIQiNN5gslplo14aIE= Date: Tue, 24 Aug 2021 20:26:10 +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> <20210824090338.GB7999@titan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210824090338.GB7999@titan> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 24, 2021 at 12:28:07PM +0200, Len Baker wrote: > This is a task of the KSPP [1] and the main reason is to clean up the > proliferation of str*cpy functions in the kernel. That I understood - you prominently explain where the patches stem from. What I can't parse is that formulation "previous step". What previous step do you mean? > Yes, you are right. The same discussion happened in the v3 review [2] and > I agree with the reasons that Robert Richter exposed. Using the strlen() > implementation it is not necessary to check the return code of strcpy and > we can assume a silent truncation. > > [2] https://lore.kernel.org/linux-hardening/YRN+8u59lJ6MWsOL@rric.localdomain/ Ok, looking at the asm, gcc is actually smart enough not to call strlen() twice on the same buffer. But then there's this in the strscpy() kernel-doc comment: "The destination buffer is always NUL terminated, unless it's zero-sized." so looking at the code, we're merrily decrementing len but nothing's checking whether len can become 0. Because if it does, strscpy() will do: if (count == 0 || WARN_ON_ONCE(count > INT_MAX)) return -E2BIG; so if p ends up pointing to something which is *not* '\0', strlen() will go off into the weeds. So I don't care if it doesn't look just as nice - it better be correct in all cases first. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette