Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp456643lqh; Thu, 28 Mar 2024 07:06:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUeaFgMqP2n9jGBx+s5fg0H6pR7ckE9X3eO3YaisQvVO2OK79vKHUxSZjLjWOpj97knZu9ZvExKo4yQoKRQiR42hH1lKShOLLPlPYYarA== X-Google-Smtp-Source: AGHT+IGy64tPSaePTDMwxXg3XW4cTx+rR5KR2tj66yCc6bl8SA1HjCPCUSxr4Mp9tgL9LD5vVusn X-Received: by 2002:a2e:9001:0:b0:2d6:ee88:6d02 with SMTP id h1-20020a2e9001000000b002d6ee886d02mr2421366ljg.11.1711634796403; Thu, 28 Mar 2024 07:06:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711634796; cv=pass; d=google.com; s=arc-20160816; b=znjZwHraOjIO52cjr627UiCI9ERGHnITndE08lcDn0RZCPhlRPyjVZYI/6dDZ13RQW Ruo77cVuvFbj1K7Oq+22xrpFsnL3/GUTBzTArHNLsxopexCLHWaqqt4LqRoSfnkvTTgS AlP74Vp9HEhj0txhr3AoGEobL8+tcGPqPrdnoT2BQJiCDyIYnVKEewTQBQd07zjBD8wJ 2LbMt58X9UnvBHwVpK11XS7TBu0Aw0a2qydHdWAY4n3J9O+nxcywpzp4jissgWkCzeKz i4dMvquCVRHEMWAwd2JqPXejXlu5aFPIxlA+E0d+oLz586Kqe77q5hjw75xfJLV29gvP t/MQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gFnH/4OQgI3DHq+3GL7Fyyy3pbR8u7QBUvKVxZei12U=; fh=UxzNkLcRSq2dXXUTcD7l2YyCSNvzW2ygAzcK4eQVJqw=; b=0Ju5b+QwdslFChXdtFYiDPSnR2unvpv1rNTw8web1/FQoQHcChWnv1CKFir8HPUrmS D4NCN9Jjp6nJSCDtGEm/ipAX171Dj8Rx9G08g9PHlruG+FjqsPHAUE9HDVR4L7RUoHHl UZLMj9RuQaQetgBAsnqRjcoEw8SHtwcLJDRYNBRrwrC1CgAwKzt9IoF3FyxkcJNlEdT+ PMibUaY6585hZ02W0gbqvuJRk/2umos7QKbXejtuSz71DApI7IconKVG+Kr2aARliCYA gb0pSGumFvyQzWn/Z7BjEePuyrs3cT+mjMDcsXcBi6osCyUaiW98wQdILfnAlNuajLK+ EpGQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FvgGl0TD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123018-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123018-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x15-20020a05640226cf00b0056bea24ea94si812573edd.363.2024.03.28.07.06.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 07:06:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123018-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FvgGl0TD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123018-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123018-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 21FB41F26B55 for ; Thu, 28 Mar 2024 14:06:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAF8181AD2; Thu, 28 Mar 2024 14:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FvgGl0TD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD5C364CF2; Thu, 28 Mar 2024 14:06:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711634777; cv=none; b=N6LDImQxgNaMV0+lwvlDJwc452zGUvT/bMu5Uxglid2AgKjLOxvKJ/hegRMG+hEpslCCPQ3pYomMaSTwn8zKChDRmyEQ+0xjdxrNWUnqmC5oLwj+8Im16vbWREGRW6o67FrwRwHPi6iyJS/DFlofMvUboLvSrJ5ysmg/vwjLBAE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711634777; c=relaxed/simple; bh=gMylBYrmATWxZ5d+8c6bGwHQWzKICTyrQtHLw9Ti9DA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mY01wL1joDaulSCGlZUM0WzKJdp+1LUfvS5sNeMBR5vadawt92wxcpdTi4cuOQ47z5HyueAk6PWNQRFX3a7j89TwzpNvEmpYAUMUg2WDyW98rv976D33ijTCF9WGrAwBcm1fOE9X1kaRfQkAitUm6dBt5Yoh1mgVbge5Kwwe/d4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FvgGl0TD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03422C433F1; Thu, 28 Mar 2024 14:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711634776; bh=gMylBYrmATWxZ5d+8c6bGwHQWzKICTyrQtHLw9Ti9DA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FvgGl0TDBH4Ei13F0xA5j1Dfi29LBEHXzAToRTsK1pdtLFjbATzWe3pQeWq+zBVor UngHRavlLa7Kx+dH+Url/3wWbJBbf+ONDpKI6iD4QryPFLU/QRK0CIL+GskjFmnmAj NDobSqFxZdaTwUiu2SPQs0Uv0cBon2FlTQHVpdyrYy/A+xkKcZRSXQFM8hFRTrZP/B aSUEvlkgaI6UFqLUO4qJY8U3YaA/+mAFTEyrbookmYAnyvXBQ6NK8QHF6ScRnRKfFY xaCnYXF4xKEEEGuLweImK3fUKVGSnFVu/QnifeXWS8U2U21eNv4cOLmP9p3qYTMlMV HDe91isEP5b3Q== From: Arnd Bergmann To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kees Cook , Daniel Micay Cc: Arnd Bergmann , linux-staging@lists.linux.dev Subject: [PATCH 03/11] staging: replace weird strncpy() with memcpy() Date: Thu, 28 Mar 2024 15:04:47 +0100 Message-Id: <20240328140512.4148825-4-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240328140512.4148825-1-arnd@kernel.org> References: <20240328140512.4148825-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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") 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); if (pro_formatter_flag) { /* Additional Length */ buf[4] = 0x33; -- 2.39.2