Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp129596rdb; Thu, 8 Feb 2024 00:49:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUawVy4XR8P+aQ+OU3PV8ODEfgPq5c9rZdL77mjzMvqYr0d6Re2JUjcKKZSrgdX6CXiZcZ6od/vo1d9GT7VEcI8lrn3hpSFP+lRGPqvXw== X-Google-Smtp-Source: AGHT+IE7rL3oE/ddgeoTdB5fbEfTLQKr0NSjkfMoZKMX8zIUcdhBveEtNsZ4T4mXfjHTM+PggZ9X X-Received: by 2002:ac8:4787:0:b0:42c:18b2:f8b2 with SMTP id k7-20020ac84787000000b0042c18b2f8b2mr2426279qtq.14.1707382157250; Thu, 08 Feb 2024 00:49:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707382157; cv=pass; d=google.com; s=arc-20160816; b=StpQAt8E4rYn/tdepRPA/OQP+T+Ro6dTqpbkoQF27vtLQP6JdAEl2VVoTM2qsBJ8aL VXbcgkbZi2eBc2eEbop928ewxGL25F2Ahd3hgSnGFSqnIPHtMxSsFKAw6GnM72GsHBNl DnLHhZR/AsDxOWZfOVDKRgzojd+kQRCn7Rc4n71XVd6/NAjEPSSAyqtaMBy+GNYjurCs usxP4Hb0pnNKl8m1igKcLG3xJst4eAmjgHjwbMIsCJ/EhynjiHmxI1iPUN40IoHFXQZv p2QGlJ8qxoZ/oOUqqSZ5WqOXJURzeorGFz+Y1IMNz6ipzS36NQjHvIpA4cBiQypAQ8mo +1wQ== 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=l0L8ciZwLC3c25nf4Mp4T1utbUQPGcw4aR9MOKxycvA=; fh=jeFbwwll48L7OSXGwr5/1eOva6K3AEw9Jk0j2HAWus0=; b=E+XXWkEHTYKIaEkCrbhclUufo0oFzuHYqUs41weqZlsNycDZSG+56nv7QoMZr3ztcR gqw7qtTEGiFPtFY1fXexlbI/V2mX76ameiZhWXOioaiebt/SnCnMkmKa3W2M76ewgIUD nb8AnIWEaBkB9XVOBS34bzlCzYKJnsgp5wfprxwut6189ccUz14EUrEeyIBLK6ZIQ+dq 6w0bJ1no/ijQWFcKu/uZZvv6KC2MNyIAmu22NObsFWGhJW99+78mBFiK/kUdTgyO2XXs wvZuPmawV9+w81JqJEpfnW7QhH2nopPgtfM6/EgPaMDSwi78gyzOS8aVGHsb7DdbAyCT I20Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JYv3wWWf; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57652-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUtAJZQHr04dWs93kWOBOvYzWDQkjSUwOHDiebx3tt9obPZDP22pwmIFxs5EMZ9WgXvju6NC/z/y87AautGEcWoKoIQfHfInvMo8m1vhg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u20-20020a05622a14d400b0042c4290b8d5si2532028qtx.423.2024.02.08.00.49.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:49:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57652-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=JYv3wWWf; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57652-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 060241C24E55 for ; Thu, 8 Feb 2024 08:49:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 67DD773164; Thu, 8 Feb 2024 08:45:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JYv3wWWf" 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 7DC7371B4D; Thu, 8 Feb 2024 08:45:32 +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=1707381933; cv=none; b=mBW3B3d6pI8fMVCqMGsEJ1yCBoWlnRRpAhNhmUckW6SKupjNUijJkYQxxs39wFTbEFdyitu/mLXzWpCxKKlsk7uwoXybugGl/0xrnX8Rb2jRCG2hcjfldQEREL4NdFwbK4iihNJ4WiFjD9c+gpicmKEgotfOD9xJ2VLKEtRJx5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381933; c=relaxed/simple; bh=PbzPd7ROc5va5PvBniGi9yT6iZxcViGR7FsGtUiYZPQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ax340BOOpImeQx4RMtE5KZ8gORbhvmtEyCceuXWAQwz3GV7QtcS30zAWS+bcRwBA5XxycrFrx15NGfQn+J5vBYHk+TDHnePeltwPi1rdUfYYr1ZqmmbiKz9P3eYhzaqEmtjPrdyiUiG2gb9k7RacFeGdEGDdUh2zy8MvBFhXLJw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JYv3wWWf; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECCBEC43394; Thu, 8 Feb 2024 08:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381932; bh=PbzPd7ROc5va5PvBniGi9yT6iZxcViGR7FsGtUiYZPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JYv3wWWfitgg/S4wiWCNHUkrl6YEq7UHvBTMANfUjrWE6exn3/m3eE4TUhkWPXN+Y rRCC2FVaAkQZqV1mHCuFnaHh1E4JzU8l38xR/iT/qXy3v/vrN2OxQVG3lrZhMJjvCx o4T+oxyev2+cxar+vWyjTi6fPg7ODFt8JIJFQLVx0HGBORpVmo99miUmNAWAEXz00J mMdCOBIQwXoI84M6/sfhzlFbrNwoOdvX9cGpijg9bbVq5vEsPeuulOXxkJeOp03YD5 OMN6+cLmOLws/InUorErs1VlC3zfGGKrspeOEalGaY6iN4L2ycp8QkTyggjGOJ6JbQ S9VvuxHfX7/Ug== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [PATCH 06/10] scsi: aha1542: Replace snprintf() with the safer scnprintf() variant Date: Thu, 8 Feb 2024 08:44:18 +0000 Message-ID: <20240208084512.3803250-7-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 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 Signed-off-by: Lee Jones --- Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org --- drivers/scsi/aha1542.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c index 9503996c63256..b5ec7887801a5 100644 --- a/drivers/scsi/aha1542.c +++ b/drivers/scsi/aha1542.c @@ -772,7 +772,7 @@ static struct Scsi_Host *aha1542_hw_init(const struct scsi_host_template *tpnt, goto unregister; if (sh->dma_channel != 0xFF) - snprintf(dma_info, sizeof(dma_info), "DMA %d", sh->dma_channel); + scnprintf(dma_info, sizeof(dma_info), "DMA %d", sh->dma_channel); shost_printk(KERN_INFO, sh, "Adaptec AHA-1542 (SCSI-ID %d) at IO 0x%x, IRQ %d, %s\n", sh->this_id, base_io, sh->irq, dma_info); if (aha1542->bios_translation == BIOS_TRANSLATION_25563) -- 2.43.0.594.gd9cf4e227d-goog