Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp570796lqh; Thu, 28 Mar 2024 09:45:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWVt7mimTxsNZ/PbI/x9agJMuCjAVJ24onFZvojMxMsOMi+8hCLRQzk/FwxvcovPV6qezFBfScSOjMvUZiJ6VNn34gv+XU5FD3rV8WCrQ== X-Google-Smtp-Source: AGHT+IGMPcyQXRZaPYCuGvhxYe00Pi/M2nAB45EXpHNWVjrsVGPA9mpiO/GfJ1Soe5/tcZ+s5vGG X-Received: by 2002:a17:902:e549:b0:1e0:e305:19a with SMTP id n9-20020a170902e54900b001e0e305019amr4170556plf.30.1711644310398; Thu, 28 Mar 2024 09:45:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711644310; cv=pass; d=google.com; s=arc-20160816; b=iAnBJsD7nH32+nCZ4TKXYNCA13O0VgotM/ZMygTi2BOK51S2euJLlhtBACYj7oSsAd 7Qqe/2F7m1FQndpPWeIvFi3RWbos1joGMNFTW7j61PBjB2ofNfXplrT+UXKcZI7fOVK7 VNWOTa9rQBj82NOYzyv3oOd4vCMH/Nsg8kJFMhjA3i5ViMRj/CqAcM3+6WFQdDoNIE30 Es0n5gQNZrqYS+EWCssglwVbA/QupfVI+d7Ga6Atptgwm1vmi7w9ik/nVRDl9M4VyQFF YgydhS5ks3BHTtTBSmNdXz+uTmvXeaqIDQMPt07mLOZP9HAkBsSc0KQXZXwCgkQuHW7h T0Yg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=RCUTxfQ4sQDe7I2H/wHmYFn/xpUZAljeyI/mp/W6HYg=; fh=ZaKJYxlTU6/FX17ZameIIEiCCb0pghw6Y3qqpduIf9k=; b=BkI2EForNo2FTaoq7aI0mc6QxubqVNsgmIPUFiCjdFVC3b6NGTRD04m3Gn3f+TX4a9 aNqzoFazQHFmo5I1XJnHO9CaRB+zG0wzBqfoOKcs5szCatNuVkUHZLgYwZ9kUNrWnkPo 6fUcCdJqEF5NvXP0ZRPARLpfWrEiElbep0hqmgJ1Lod5tSe6YbgM/ehrpHtwL+s3P7Vc FlWCLsYI1yZmcwRhyRIRzCcAUjXskG2T+Xsv5H1+/QrTR8RTVLSm/NwAgaEGBXcnonXt DjRQc35nZAVwTzWaM/oK1UZaAwvHCiBQx48TlR02Ob37aKlpkIr+wRNqnMaK7Kc9kTR5 plFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AUa6c9Ye; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-123261-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u17-20020a170902e81100b001e096ce909esi1831635plg.252.2024.03.28.09.45.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:45:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123261-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AUa6c9Ye; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-123261-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C95D9B25A7D for ; Thu, 28 Mar 2024 16:36:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA2AF41757; Thu, 28 Mar 2024 16:35:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AUa6c9Ye" Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C12047F487 for ; Thu, 28 Mar 2024 16:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711643735; cv=none; b=ljlLcx1044AXSJCgJqDpQl+4aEVmP5pxL6RDcIvd/NW5Tm87fTAvPlh1qep1dnZhnwXSE2BcwpHKstegt7wU8KQYbyphJhPLswa00MEn5FurF1usmZQoSV5ympT+FcflwHN+WGazNRUuu1tJGZyEI9xZzrXM2XzFYO1meagxGjw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711643735; c=relaxed/simple; bh=JWJtXJcUZY3AnWXjwt7iRcnwQ6zGkVqoL86keyxldpk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tc+eNOGXzVlN7d7E1UQhdgswxvwWP7K7mAmmym24ZvSVy9hbWGVrZGYZu26HDm1j4VapOi5LIPCJvzyZgEJReUSoq4LdpfAn3OwnFmfPs4hgbFwxHGyfVXJ4YoFni25RS8bZHSLRHhue0cGRXSQMiFwJVcFhaDabKAG/YqXMH1g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=AUa6c9Ye; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a47385a4379so407981866b.0 for ; Thu, 28 Mar 2024 09:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711643732; x=1712248532; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=RCUTxfQ4sQDe7I2H/wHmYFn/xpUZAljeyI/mp/W6HYg=; b=AUa6c9YekRcEfZcIg/J5sRVL0dpS4z2T8h9ICdWQjn9RBzvfW0B0sJG9ps/JOQ6R0C 8KYKkX1ojKRV4ZaTUP6xDVrLb6AbzJIdkrhIDibz1lUbdAUI2tv54xCbw+L9oz+2GX9a R4CeC34mwXDTqZ+/hk/oFSXrwLl07j2qypSgdc1/eQyNmlNmR/xblWOo3AhZm4kruIOU S7vgp28nXa/+Vfzn3QnYftEzABn1CqD4QxYzdGP/yZrVLL+5t7m2EmqXJ8BgNbwTJ7pa 86sF1JV443zIu1F1K1ceQa4pcl1TKtNRbIeA0oxXFls5mrfIpmZEVMAh39T+W4gzAUi9 cqew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711643732; x=1712248532; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RCUTxfQ4sQDe7I2H/wHmYFn/xpUZAljeyI/mp/W6HYg=; b=wV47lNyIzF2+w5oBi3jFApME2DnN7RL5YMHu02oUMxC8AH+BrmO1y1sBgTWVeHgmqv 03wjtCzQNuIEFtrewRuPkp9aR6tx19VVNqNHOTLSw6J/C9LhQC9nSUmgPx4YJm0HmQTR IYDer+YB+jJpWw//10DHVEpCLRQXpAsxjyHJLJFPgYB6uUOlkWjjAwnO7lWqp3p0TjFE GN7nuOTL5cMfCKPVeDcokj0FxT/ExP2mJRg3EEUNgco2eNvlW5jc+8YL+yzKRXpUuXMz XQtlO7q/vnrhmP0+kwrCkXV93t0eEFm92yJisUWhQta4uWK13sMWEcJLaCQVd4wUADhf /vpg== X-Gm-Message-State: AOJu0YyUiJYK4udFQAePqNh1FGb84MjpUYQXMEK85dSt1b46AiTSRzNU Y0tl5OPJIFQ6Pnq8gjohbVCoioS/EbH0L+9iuuGCj15K0zHnonzLDW7vNSRXwxQ= X-Received: by 2002:a17:906:228b:b0:a4e:4d9:7ce4 with SMTP id p11-20020a170906228b00b00a4e04d97ce4mr2492742eja.30.1711643731940; Thu, 28 Mar 2024 09:35:31 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id h9-20020a1709060f4900b00a472c4b9486sm937920ejj.84.2024.03.28.09.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:35:31 -0700 (PDT) Date: Thu, 28 Mar 2024 19:35:27 +0300 From: Dan Carpenter To: Arnd Bergmann Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kees Cook , Daniel Micay , Arnd Bergmann , linux-staging@lists.linux.dev Subject: Re: [PATCH 03/11] staging: replace weird strncpy() with memcpy() Message-ID: <695be581-548f-4e5e-a211-5f3b95568e77@moroto.mountain> References: <20240328140512.4148825-1-arnd@kernel.org> <20240328140512.4148825-4-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240328140512.4148825-4-arnd@kernel.org> On Thu, Mar 28, 2024 at 03:04:47PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > When -Wstringop-truncation is enabled, gcc finds a function that > always does a short copy: > > In function 'inquiry', > inlined from 'rtsx_scsi_handler' at drivers/staging/rts5208/rtsx_scsi.c:3210:12: > drivers/staging/rts5208/rtsx_scsi.c:526:17: error: 'strncpy' output truncated copying between 1 and 28 bytes from a string of length 28 [-Werror=stringop-truncation] > 526 | strncpy(buf + 8, inquiry_string, sendbytes - 8); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Since the actual size of the copy is already known at this point, just > copy the bytes directly and skip the length check and zero-padding. > > This partially reverts an earlier bugfix that replaced the original > incorrect memcpy() with a less bad strncpy(), but it now also avoids > the original overflow. > > Fixes: 88a5b39b69ab ("staging/rts5208: Fix read overflow in memcpy") I don't see a problem with this commit. The "sendbytes - 8" prevents a write overflow to buf, and the strncpy() prevents read overflow from inquiry_string. > Signed-off-by: Arnd Bergmann > --- > drivers/staging/rts5208/rtsx_scsi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/rts5208/rtsx_scsi.c b/drivers/staging/rts5208/rtsx_scsi.c > index 08bd768ad34d..a73b0959f5a9 100644 > --- a/drivers/staging/rts5208/rtsx_scsi.c > +++ b/drivers/staging/rts5208/rtsx_scsi.c > @@ -523,7 +523,7 @@ static int inquiry(struct scsi_cmnd *srb, struct rtsx_chip *chip) > > if (sendbytes > 8) { > memcpy(buf, inquiry_buf, 8); > - strncpy(buf + 8, inquiry_string, sendbytes - 8); > + memcpy(buf + 8, inquiry_string, min(sendbytes, 36) - 8); I think your math is off. The string is 29 characters + NUL. So it should be "min(sendbytes, 38) - 8". You're chopping off the space and the NUL terminator. This only affects pro_formatter_flag code... This code is such a mess. I'm not sure your fix is the complete fix. When I see code that's clearly buggy like this and it's not sure the fix is complete then I generally prefer to leave the static checker warning as is so that we are reminded of the bug occasionally. How close are you to removing all these -Wstringop-truncation warnings? Maybe we just add a comment or a TODO item in the drivers/staging/rts5208/TODO file. regards, dan carpenter