[08/10] scsi: aic7xxx: aicasm: Replace snprintf() with the safer scnprintf() variant
Message ID | 20240208084512.3803250-9-lee@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-57654-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp30152dyd; Thu, 8 Feb 2024 00:50:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgP206ors4W3ArIXuCG3wSiK76XDZM3VVQJlK5SwgscBd82+xbZ79jRGDcChITTiI8QBZ6 X-Received: by 2002:a17:902:f68f:b0:1d8:e1c0:1bb8 with SMTP id l15-20020a170902f68f00b001d8e1c01bb8mr2846907plg.27.1707382225793; Thu, 08 Feb 2024 00:50:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707382225; cv=pass; d=google.com; s=arc-20160816; b=QwtSUI4Ea3fBGZBbgxYeGAeTh4pXFi3kIrITZh/6uXXvnJZYkLHWofxf3cGOFNGER8 DZdLFGztVce1Wg3PDSy9YiXIkEiXQQ1CjA8KkCAxSSnGqzIirxopWoWQImmT+W1thRHx o7o4VfZ8Fn2UXoThkuvl2VS+y0oAg6hCCl4AyHENjae6g68Yc5Aee1VQ5nfM5fLzkNpv rsP/mqB3N57Zhtmrenwdg5HnJ8531tHwSERhC8ymEDIIKI+BtaRcbwAQL+KpbS94JIKb sFbSzXLDjSJY7aeQEPbuN81zahXzn5U1Y6pAZhT42CnHAWCHQoH/gPYgktncxa4tPiGg qRQg== 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=m5yualySpHoFfZEhuJjtfMU6c4zp55QaGu8LpDOCOJ8=; fh=yUfz2Tw7N2QmDgDwlLirB+vVu0bMBELts3XPkpcNMSM=; b=mzEl+Bgu2Y31wVeJUiaITOdGzW9whmLvf8pI8dU9DSvffdicqfsFQNb7NiOHGdZsVh h+8vrhnn7bWU/kDUHQRCfvTpm7T4jVkD4tH3+1QsYuxVJBHJmniC45MlEw9Btwp6WZkC 6ZEKZjQSffr0kvlWwco9vWW8Mf/Kul/a3MZIWfvf59d+217IfMj23NwiyP0kHWFxiCmW p2LrzaOAfCeXmsVo+NHT9t0hg33QqgHJwxVq/Cbk6XgtfrnirADTBEbMzAZsco/PLAtu e/VmJRg9+BLXm+EVqwH9OLL1Rr+Hw1pBavf/lDMYcNJRKS9i1RpWm8DV3OsMrMuRPp4d lk5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=flkB5vKC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57654-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57654-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWW+3vAmoLw+Ki7aFFvQhkhPNUY7tc/FSOofrAiy3aLZOsVuhAuqofAoiWFP9SguAXVI54LZbGKzWKaOBpYEhld7pTTaQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id im23-20020a170902bb1700b001d953f4021csi3381246plb.196.2024.02.08.00.50.25 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:50:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57654-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=flkB5vKC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57654-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57654-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6B759281FDE for <ouuuleilei@gmail.com>; Thu, 8 Feb 2024 08:50:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8D6E74E31; Thu, 8 Feb 2024 08:45:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="flkB5vKC" 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 CEF3973197; Thu, 8 Feb 2024 08:45:35 +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=1707381935; cv=none; b=P5SIe56mslZgqf4RR5nwrJDU9Yk1J9q87rR60UE8q21T7MMvb5y4xU+TCseACIZnx+QIc8OcQYwFfoX+TNeDCljTXMMX4PZ4i26Ca1lP0E/+kisWZRrORX02sqxThLQsfUURFOl3zvRDO+cfvuPhSG1zKF7N1BGVRnG7VUHQZsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381935; c=relaxed/simple; bh=QcWkvLbuXqKsmCSILThA1RfLwMeDripObvnvLFWiq34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fDe2rypoyWtpnB06izoJQSLDq47rc6o3uHT2waOB85hlw/BcTJUUZnfYbeUp3EsQTDq0EUcNO5rxyjbhb5E1slsTIchW3Sazk6TiYqp9A765vXVJLh0DLs7RkcMVnVY7uDeFdKCMumFBfiXUhV5RtL7qjQX2wiJkpj5Ilpu9JNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=flkB5vKC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A257C433C7; Thu, 8 Feb 2024 08:45:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381935; bh=QcWkvLbuXqKsmCSILThA1RfLwMeDripObvnvLFWiq34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=flkB5vKCBQYz/TpY0INSUaOZjllm7VrkDUbKFVgCIc3ASXj/qazrW94Yryh3JnsNX NJlgNNRcRUnXProGsUi8C60pgUya/Fr+EbvRfWtqbhO2YHZE25gcmPGLdWv0WujarZ cWbsO1A+1oAk30b0gsn/JJRxxxx7v+Ya+QMQQeTauB49jBXRvaud7rZaPGDH6v1Sm9 BshS6lbql3Lky3xkzhJ3qkII+o16i592ZP1lJ90hMoELZdsv6nOxN6LrniXK5qTPYr QEA8Dul1ponHXK0/KmqqAqeurIbVE98UbjMLuIfEWXQG0CQZgxl22y8j+OgKOr8sY/ u8EUQhEi+CBGg== From: Lee Jones <lee@kernel.org> To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Hannes Reinecke <hare@suse.com>, "James E.J. Bottomley" <jejb@linux.ibm.com>, "Martin K. Petersen" <martin.petersen@oracle.com>, linux-scsi@vger.kernel.org Subject: [PATCH 08/10] scsi: aic7xxx: aicasm: Replace snprintf() with the safer scnprintf() variant Date: Thu, 8 Feb 2024 08:44:20 +0000 Message-ID: <20240208084512.3803250-9-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790320024491996681 X-GMAIL-MSGID: 1790320024491996681 |
Series |
scsi: Replace {v}snprintf() variants with safer alternatives
|
|
Commit Message
Lee Jones
Feb. 8, 2024, 8:44 a.m. UTC
There is a general misunderstanding amongst engineers that {v}snprintf()
returns the length of the data *actually* encoded into the destination
array. However, as per the C99 standard {v}snprintf() really returns
the length of the data that *would have been* written if there were
enough space for it. This misunderstanding has led to buffer-overruns
in the past. It's generally considered safer to use the {v}scnprintf()
variants in their place (or even sprintf() in simple cases). So let's
do that.
Link: https://lwn.net/Articles/69419/
Link: https://github.com/KSPP/linux/issues/105
Signed-off-by: Lee Jones <lee@kernel.org>
---
Cc: Hannes Reinecke <hare@suse.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Lee Jones <lee@kernel.org>
Cc: linux-scsi@vger.kernel.org
---
drivers/scsi/aic7xxx/aicasm/aicasm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, Feb 08, 2024 at 08:44:20AM +0000, Lee Jones wrote: > There is a general misunderstanding amongst engineers that {v}snprintf() > returns the length of the data *actually* encoded into the destination > array. However, as per the C99 standard {v}snprintf() really returns > the length of the data that *would have been* written if there were > enough space for it. This misunderstanding has led to buffer-overruns > in the past. It's generally considered safer to use the {v}scnprintf() > variants in their place (or even sprintf() in simple cases). So let's > do that. > > Link: https://lwn.net/Articles/69419/ > Link: https://github.com/KSPP/linux/issues/105 > Signed-off-by: Lee Jones <lee@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org>
diff --git a/drivers/scsi/aic7xxx/aicasm/aicasm.c b/drivers/scsi/aic7xxx/aicasm/aicasm.c index 8d995186e557a..bc758e78d3c06 100644 --- a/drivers/scsi/aic7xxx/aicasm/aicasm.c +++ b/drivers/scsi/aic7xxx/aicasm/aicasm.c @@ -331,7 +331,7 @@ back_patch() if (cur_instr->patch_label->type != LABEL) { char buf[255]; - snprintf(buf, sizeof(buf), + scnprintf(buf, sizeof(buf), "Undefined label %s", cur_instr->patch_label->name); stop(buf, EX_DATAERR);