From patchwork Thu Feb 8 08:44:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 198219 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp29547dyd; Thu, 8 Feb 2024 00:48:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUmVtH12DXQxM7ZJYGvcnfPB9YfIZiTHDJvUMO76HlugvdCXAHzYb24U3MB0ooGw2jhreJWo9p2UI8qvGhTmgJPpTvgfw== X-Google-Smtp-Source: AGHT+IG3yNlTHsVqd/cH8h+bJkPLdLrteBln6BC54ZjH9bVqs8dY/bCI6iM2QnT8VshEcn+3sS+V X-Received: by 2002:a17:906:568b:b0:a37:c159:60a8 with SMTP id am11-20020a170906568b00b00a37c15960a8mr5972917ejc.29.1707382117024; Thu, 08 Feb 2024 00:48:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707382117; cv=pass; d=google.com; s=arc-20160816; b=K+2oLlF5j7GD66RDnCiFFgl9bxQkwWVbQHVyb9E/drSEW7Pyp7b/IFY1+Le8li8F9u u96r64burJqecQsq3pxQnab6Jfv2VPybSwrDgxwDc5MlQ4qmQZonR5k9sc1JW3pd2isW xkTxLujntRf8rJk4GdIxJf8KQ9CpitUU6Skpl316SpEQm/oeeHuqi+pCDe7cJcgXbKpM tLLMez79tdsRj5DYJSQwqesaQnqwvDvmSn/yI2Y5HtldcAErAa1nawsQQLZSQXGFL4mH 3oMUbMMeZ5b4oUV5t3At1KtmUEG13zckGqiqheLZJG6tbL2iZxfp5mH+WSYXkkxyxJiI ZJYg== 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=rc3fAsCWezLJC68KWVm5cxEpthBi0zdruh2dyo/t5xo=; fh=WZEW32myFhsTZExiLS2a3bvVIGwlX4a+MR9MxmnDOM0=; b=0Q8V69REeoOuc5FgyRD02zu9gPRExaYc83T8hQs1+XDzIxSRm8EYmcVpc4PTNCwfEK g9doXW4bkQUt1gZGVHHlUCho5vRuwnek43SVMsGxpPgFRP5gyz4aKrUzX8+p6nblOHYk L14eqg2/Uu1q7xEx+D5GAS7fa9iVyUeT9w9yw+RFuqPtQws/zbv0AAl3FdiskjdsQEB3 NBfNW9/a/j3dpERN8xapAHu50iS+XIxvhIU9h77MyIFtubNwsNIHOn7PrBMW6QWvP2rw 2JTYGkhR1aHuQkJ6/cDRwNtBy0leV67tyjxlS8L0l4cEroPqps3FM77IDU076IxbNMul GZYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=j4F5tGSr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57649-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57649-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXPk25ptUo8I1lTiTYs6Vrfw83EQ5WChljoOjbkpYDFKRXKMKqAQkf++uX+vA0GqmhfAwTvctlEKSPApyxTh087JnDdZw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lz19-20020a170906fb1300b00a3baa7d59f4si335230ejb.25.2024.02.08.00.48.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:48:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57649-ouuuleilei=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=j4F5tGSr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57649-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57649-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 726B11F24FDA for ; Thu, 8 Feb 2024 08:48:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57A116D1C4; Thu, 8 Feb 2024 08:45:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="j4F5tGSr" 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 93B786D1AA; Thu, 8 Feb 2024 08:45:27 +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=1707381927; cv=none; b=gOj0INfpeSWwWToc24QmiiDLry8NlBiAQEY9hMeaBwKD3OKIJBil3JSbgy/7dYKYO8p/dEziCugKyqpMUkwcuK2tGUU9FZapljN+uUpUa5voYuvApDVyWFdClDtP4W3/GrnGQSy1myvwmfeKRfYLb+/Zscj92ewnAQbe5nlIai4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381927; c=relaxed/simple; bh=kPQEC7JNk1nG41qzG8wfP+IddSOveAbpNnPvKYhI/4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DmON6N66CxrLyQPExgsS1GkXVS0XCKK33xy4iG8FEYdtMLpnT+vEytHQK9GHTkPBvhvGcHriXJL+qaOI10BvgQQFnoBnL0VsJTMeAUSxzTzLUcvCNgM6Pna2RgERmqAvpCItbmFMDWy+4q6lECHYZs8u565QrL0GpOWYnN8zK6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j4F5tGSr; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B7CAC43142; Thu, 8 Feb 2024 08:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381927; bh=kPQEC7JNk1nG41qzG8wfP+IddSOveAbpNnPvKYhI/4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j4F5tGSrD6ALzwj7JwdKg6N+UE+nGeZW0wCkS9VI3EkJV0qqDGxmuGDBKLgCPQXMK iXxeiPa/3/f5uaaaYz5302sabTiuOhOzBQ3WAaWPU5L3nrmQ7mLMjgeE5b6/rSNHZg iOBrDaxlgdQvVyy39RRyZJxP7KnzZULipwN0HI4I836QMXbIwPxkcnvyE3dMNuAKcv /N26Y1C+rCx8iia2dw6Yw1F7QLX21WKuKtqvIEz7S8E7EIR6k7+GxMV4cUwMjHV3Hw MG2SyFuKMKPvNh/hYb4GI3gdbqqybdhXR1QuIXORcwlsinZAWiR9G7QXQ+uigjISdb 7dioSC5x11JAg== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Finn Thain , Michael Schmitz , "James E.J. Bottomley" , "Martin K. Petersen" , drew@colorado.edu, Tnx to , linux-scsi@vger.kernel.org Subject: [PATCH 03/10] scsi: NCR5380: Replace snprintf() with the safer scnprintf() variant Date: Thu, 8 Feb 2024 08:44:15 +0000 Message-ID: <20240208084512.3803250-4-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790319910615855997 X-GMAIL-MSGID: 1790319910615855997 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 Reviewed-by: Kees Cook --- Cc: Finn Thain Cc: Michael Schmitz Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: drew@colorado.edu Cc: Tnx to Cc: linux-scsi@vger.kernel.org --- drivers/scsi/NCR5380.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c index cea3a79d538e4..ea565e843c765 100644 --- a/drivers/scsi/NCR5380.c +++ b/drivers/scsi/NCR5380.c @@ -421,14 +421,14 @@ static int NCR5380_init(struct Scsi_Host *instance, int flags) if (!hostdata->work_q) return -ENOMEM; - snprintf(hostdata->info, sizeof(hostdata->info), - "%s, irq %d, io_port 0x%lx, base 0x%lx, can_queue %d, cmd_per_lun %d, sg_tablesize %d, this_id %d, flags { %s%s%s}", - instance->hostt->name, instance->irq, hostdata->io_port, - hostdata->base, instance->can_queue, instance->cmd_per_lun, - instance->sg_tablesize, instance->this_id, - hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "", - hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "", - hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : ""); + scnprintf(hostdata->info, sizeof(hostdata->info), + "%s, irq %d, io_port 0x%lx, base 0x%lx, can_queue %d, cmd_per_lun %d, sg_tablesize %d, this_id %d, flags { %s%s%s}", + instance->hostt->name, instance->irq, hostdata->io_port, + hostdata->base, instance->can_queue, instance->cmd_per_lun, + instance->sg_tablesize, instance->this_id, + hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "", + hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "", + hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : ""); NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); NCR5380_write(MODE_REG, MR_BASE);