From patchwork Wed Apr 10 02:31:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13623474 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A37328F3 for ; Wed, 10 Apr 2024 02:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712716321; cv=none; b=GOVZRvyJUANkEVvYBJ5Uy0y4ghkLH4b8AeXHxjZeX7tgOV5u1L6RnSiejwC5Drp2IYE9sHGHXo2lEockMA9yHOYKWkUQJ8EDNFfK3mF+S73+JPb4OrW0wwT9Q6V7hH3fSAGMDQI4XDmFUs2BrPma+BhzkJuOlsxIQZ19hpoO5L4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712716321; c=relaxed/simple; bh=JCsgCprEWa1l4SCGDGbUB8ubZ+h1Yzs/Ma0V4GeDTGk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OLozJfTsNqY+tQRJGi+tOYBP6BepuBWnM5rqAZWPQFBPCj6ftJRBiWb/wEGl8Xp4WoqCVDRHvpmhmBZlTSmdlrsYXnJtEPTtzB1rcKHTYciEEJXCVMn6jd3MP91eEWLMDp7frdQCJAdb2++b+iZ2eT5Tl+lXhLBOJ5qOWyaUzZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=SrjgMzCH; arc=none smtp.client-ip=209.85.160.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SrjgMzCH" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-22f078f1aecso1959627fac.3 for ; Tue, 09 Apr 2024 19:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1712716318; x=1713321118; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vHRtLi+awmnGIE7fYkBoAx7My8kibiodg7yHDLCH7Io=; b=SrjgMzCHjCwLVE0DmA2jtUfljAsa64Y0dpMP2DqvpSH3EgnxOYJMEf3pb0WpYXdLOl bD+jrEop+NuUU2VOGumehkgikm/fVjFqCySQvpg6xJoo6ZVGpPjnoV7RL/Aa0q/GlXct tKtz0VMN3sSs1CDv8+V86ayWric/r32NNK03w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712716318; x=1713321118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vHRtLi+awmnGIE7fYkBoAx7My8kibiodg7yHDLCH7Io=; b=Ekd2XWC8WF0PU2iz8Qk/hahnmeDZ6RiQ+/1s7w7LnUfwzKh3pOeURHrBmSAWYmjwha yQkW53cZO3i2R6Xfe9yLeOKPvhpXwhmtoVOT59jyM99nLTd4ZtloN7nQmXbCB/OJe19L JNu1EeWR/ROClKD554efnoGcjBCYznwfQr+a2zBQOiXyGwskGpR7yaJPSqqarJhC2zk8 vzfWOLTSuj2NZbyOGiWbi/AklqGotAZ9daG3wkN+vKHMzRoHjMyi1yVrS0GGuUzYVOSn H9IrN8qcz1tKF+OPn1XhH1kCtO8E18UA1tMKBND42bSyUL06c4NkKvI5Mb/rkT11+WJ9 ozig== X-Forwarded-Encrypted: i=1; AJvYcCUIFZhQxRt42OneKNJcBqxGcBCuOmjyDNK58HmoMsRzMsBUv5L2y1Q2KCVw/GlHtkr8pNz2h1Yq9dEx+S6vYX1IN3th+fYH8HPUerd1r2Nh X-Gm-Message-State: AOJu0Yw/9KY1V7V+lM+gmptLDwV8LqAINr66pfCwpCuqC5TBgdwXl0zY cIQm3giWish7Z1Iz6BzlYzOZll8nCiFGLR5zQzCxv8zfVRMYtsk4g4P/dqa05Q== X-Google-Smtp-Source: AGHT+IFRyXg0eTdw450Vq36zHeNUtw3iCaUhs4VSlyDJfb0DpKJHBxFM33ehx65aD4AK2nBbeg7RxQ== X-Received: by 2002:a05:6870:13c9:b0:220:6edc:1fd7 with SMTP id 9-20020a05687013c900b002206edc1fd7mr1259703oat.1.1712716318261; Tue, 09 Apr 2024 19:31:58 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id p4-20020a056a000b4400b006ed06399e0csm8065458pfo.72.2024.04.09.19.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 19:31:56 -0700 (PDT) From: Kees Cook To: "Martin K . Petersen" Cc: Kees Cook , Charles Bertsch , Justin Stitt , Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, Bart Van Assche , Andy Shevchenko , "James E.J. Bottomley" , Kashyap Desai , Sumit Saxena , Nilesh Javali , Andrew Morton , Himanshu Madhani , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, mpi3mr-linuxdrv.pdl@broadcom.com, GR-QLogic-Storage-Upstream@marvell.com Subject: [PATCH 2/5] scsi: mptfusion: Avoid possible run-time warning with long manufacturer strings Date: Tue, 9 Apr 2024 19:31:51 -0700 Message-Id: <20240410023155.2100422-2-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240410021833.work.750-kees@kernel.org> References: <20240410021833.work.750-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2470; i=keescook@chromium.org; h=from:subject; bh=JCsgCprEWa1l4SCGDGbUB8ubZ+h1Yzs/Ma0V4GeDTGk=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmFfoapA0jSRgfPR1sV3aqPHMnroQNsZpklKX1t cw5ZZgf3nmJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZhX6GgAKCRCJcvTf3G3A JtFpD/9RjRSGfqMioS+VbASHaxCQLXGu+eeHR8PmV46+1XHXwlDmiB4qhXcJVPn5SxTvumjfLdX cdsWdPitwCDd1rmdkhZFQBFbApN7JZY19OPk1IznV224pMgEJ4Wr3CjGYAKwQhkLPfr+FJ4WBeQ YAZWx8wxcI9qFgauL79FwHCAksDToU5TsQTVoIjEUThMSk0bbOqxzurszTfbe0CiwGXs6ihSFvZ 6SSrzNj9YZADh+Vb25DzyScDWlEdcsnhbvjgjQUofPfR9l9VnqbnXxtUy6f/Rq26f6cL8VDnTI8 EiJbj6cZy+Os+xtOACFtn11kqXedJhygwP3STSt8nhs4vHK/ZnTEiQV+ZV9jKBXPJTuCFpcUf5n LcmgL5exH6LePjRTgbfTBxjcN2nj4Byc4uEG1InJQWdyhQW2CuHfNgLfjldBNVE2ovcAcrBVSma tj20k1udmZ3v+YmUNKx9p5idV3ouKxHF0mZQeVFPCzkdHEWZuLJp7m9oFGu/B6tTZ1tIb0HmDoQ gln22cDiz9N0izlWpnyyseCi5ph1I6BDaOMRX45SXJ956/M2yor0WSprV24qbsHQQtVNBd/qx+t PpZRkeOXgc3/6Kk6dE0eFaSgNcq51hvmrE3Gq/T7Mj+1kL1UnGf0sNdJZvXj0mLL2emiFR9g2r9 S3cIpGQntVIb/GQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 The prior strscpy() replacement of strncpy() here expected the manufacture_reply strings to be NUL-terminated, but it is possible they are not, as the code pattern here shows, e.g., edev->vendor_id being exactly 1 character larger than manufacture_reply->vendor_id, and the replaced strncpy() was copying only up to the size of the source character array. Replace this with memtostr(), which is the unambiguous way to convert a maybe not-NUL-terminated character array into a NUL-terminated string. Reported-by: Charles Bertsch Closes: https://lore.kernel.org/all/5445ba0f-3e27-4d43-a9ba-0cc22ada2fce@cox.net/ Fixes: 45e833f0e5bb ("scsi: message: fusion: Replace deprecated strncpy() with strscpy()") Signed-off-by: Kees Cook --- Cc: Justin Stitt Cc: Sathya Prakash Cc: Sreekanth Reddy Cc: Suganath Prabu Subramani Cc: MPT-FusionLinux.pdl@broadcom.com Cc: linux-scsi@vger.kernel.org --- drivers/message/fusion/mptsas.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c index 300f8e955a53..0f80c840afc3 100644 --- a/drivers/message/fusion/mptsas.c +++ b/drivers/message/fusion/mptsas.c @@ -2964,17 +2964,13 @@ mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc, goto out_free; manufacture_reply = data_out + sizeof(struct rep_manu_request); - strscpy(edev->vendor_id, manufacture_reply->vendor_id, - sizeof(edev->vendor_id)); - strscpy(edev->product_id, manufacture_reply->product_id, - sizeof(edev->product_id)); - strscpy(edev->product_rev, manufacture_reply->product_rev, - sizeof(edev->product_rev)); + memtostr(edev->vendor_id, manufacture_reply->vendor_id); + memtostr(edev->product_id, manufacture_reply->product_id); + memtostr(edev->product_rev, manufacture_reply->product_rev); edev->level = manufacture_reply->sas_format; if (manufacture_reply->sas_format) { - strscpy(edev->component_vendor_id, - manufacture_reply->component_vendor_id, - sizeof(edev->component_vendor_id)); + memtostr(edev->component_vendor_id, + manufacture_reply->component_vendor_id); tmp = (u8 *)&manufacture_reply->component_id; edev->component_id = tmp[0] << 8 | tmp[1]; edev->component_revision_id =