Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1637805rdd; Thu, 11 Jan 2024 05:19:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8rZRAabcbcyQi8DZN3eTC5iyGujSBe8j4FpCGHVH88fdUFirivLuEvjEs6fG/lmLrHtbr X-Received: by 2002:a05:690c:fc7:b0:5f6:d7dc:1705 with SMTP id dg7-20020a05690c0fc700b005f6d7dc1705mr591510ywb.61.1704979140569; Thu, 11 Jan 2024 05:19:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704979140; cv=none; d=google.com; s=arc-20160816; b=bPDLap2IMuOaFZ9En9qFooRUKlZa4V/kFyZzGVIbAz+/eFlMxHOY4tMoKyGBZ00o8s wVsLuC299ZfxNSgRQd1nX1Dhl84bYyTuhXzeB61ipGghD4VxvHMhInKvXGwpIrK9bUzT b48aQ4mKUNgZ37HrvpNxzkHgXzUtNAPm9rpFUpJsEeFeDVK/KHeBamgxmdQ3ntLUNPV+ xjvLo/wwdjsUd/oaiBZJ8elibhZfFazhrIyQ7hvp40UfAX31ShIejFQS8QEKSpfwCUuM W0gfc1CpUJhchh9HsIZbfbXp9gqeoLCMdCA5/FDwrX7H4AgBoohKBr5KgnPolUNLnDRX VBug== ARC-Message-Signature: i=1; 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=BK4rSqDRlGV0ncoRF15kdjScBmv/c8qz2IfeWXaE380=; fh=qUc1Gs7ndqsRUdJ6otj1JUPKa+ApxiBjq1vMeNpxkUk=; b=rCqEP67TtE71U3gHNk0OKqgKMiF4ZPfDltx++voDv6t4QO3LHznOwiHvE1JKK/KE1U dIRRx5idnfq9rHJ8AfMLbQe1chatAXFDdU5i2+xrc/diEdHd+956Ap0/B3rq/HXOGYoG 6axErym7OySKDOyRqY2dlZRNQsWkWdFWoeYI+qd1OEotcMwV4H67zN+dojRthfjM5ABL ZAzh/lG3+jRahX+fG00QGEbczFUmG9XpgpNR2aAYNQXr8Wh8/HiZywlEi//8Q64rU3EF armScMTvm2yO8VZP762OgP3I4ZvebzPCuMc8f7mSuOu0bWLh7jzsMg3egL/gcE8H1lby KOjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NslUajr5; spf=pass (google.com: domain of linux-kernel+bounces-23632-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23632-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v7-20020a05620a090700b0078326e1ecb1si868545qkv.161.2024.01.11.05.19.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 05:19:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23632-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NslUajr5; spf=pass (google.com: domain of linux-kernel+bounces-23632-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23632-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 52FF01C21DAE for ; Thu, 11 Jan 2024 13:19:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2C5E29D09; Thu, 11 Jan 2024 13:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NslUajr5" 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 2C58528380; Thu, 11 Jan 2024 13:17:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72A99C43601; Thu, 11 Jan 2024 13:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704979073; bh=H6jAa/1qm3fcEGYYR8xZvaYjmIAWKwCFiXdEuAok+aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NslUajr5yYffmjX0xTHEDPUKXWSepCDuYldFgyWbcAdo6zIEXGqzd6kP91UEd+rSt sU/gFDHsL7z1EQrA8i25sU4Uznxit8SxZles95BNEwRi/0k7zB+CXrYd6e/x2npnwB x4nQfId++/chpiz52ky0VzRiP+7I+p/mNp05AeRHY8CGnNGzj1SnZ0vqd4WT1JsyZN /DJA94SQbwa9YyY+fMZz+GZ70EH3gcUM6+Fjug6lPtPyLQs6YBsHyIt26TN5KD5OXV Gv8d+PvtHKyODKD0crVLUG7REoYcoqxVp/kxQdUK3VCUICVive9EI+w7Ap4R+ns3kP apCZ8OYKBPNEA== From: Lee Jones To: lee@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Adaptec OEM Raid Solutions , "PMC-Sierra, Inc" Subject: [PATCH 5/5] scsi: aacraid: aachba: Replace snprintf() with the safer scnprintf() variant Date: Thu, 11 Jan 2024 13:17:26 +0000 Message-ID: <20240111131732.1815560-6-lee@kernel.org> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog In-Reply-To: <20240111131732.1815560-1-lee@kernel.org> References: <20240111131732.1815560-1-lee@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 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 Cc: Adaptec OEM Raid Solutions Cc: "PMC-Sierra, Inc" Signed-off-by: Lee Jones --- drivers/scsi/aacraid/aachba.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c index 70e1cac1975eb..b22857c6f3f4f 100644 --- a/drivers/scsi/aacraid/aachba.c +++ b/drivers/scsi/aacraid/aachba.c @@ -1099,7 +1099,7 @@ static void get_container_serial_callback(void *context, struct fib * fibptr) sp[0] = INQD_PDT_DA; sp[1] = scsicmd->cmnd[2]; sp[2] = 0; - sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X", + sp[3] = scnprintf(sp+4, sizeof(sp)-4, "%08X", le32_to_cpu(get_serial_reply->uid)); scsi_sg_copy_from_buffer(scsicmd, sp, sizeof(sp)); @@ -1169,8 +1169,8 @@ static int setinqserial(struct aac_dev *dev, void *data, int cid) /* * This breaks array migration. */ - return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X", - le32_to_cpu(dev->adapter_info.serial[0]), cid); + return scnprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X", + le32_to_cpu(dev->adapter_info.serial[0]), cid); } static inline void set_sense(struct sense_data *sense_data, u8 sense_key, -- 2.43.0.275.g3460e3d667-goog