Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp786757lqb; Wed, 17 Apr 2024 10:36:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW+iMDcEXsiCKe188silizxK5Kklhi82xkj/YLxxgI0xaqXG3Lll2v4atQYslNY8E9KbSXVo3v7XCLkZfeq2IjuoEY6rxuq35gRsrdG5w== X-Google-Smtp-Source: AGHT+IGIQ5WWb9gzjFhxgcxHq9fry3GtRO+zqiKgjcMPmcGEoDRPuYtJRqYZIROcsDL+b1yWc5HO X-Received: by 2002:a2e:9b4b:0:b0:2da:7934:768e with SMTP id o11-20020a2e9b4b000000b002da7934768emr8463988ljj.36.1713375362200; Wed, 17 Apr 2024 10:36:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713375362; cv=pass; d=google.com; s=arc-20160816; b=0jiZTe8p+08DfWPbG+k/at0rHTzYX6PMSmSHGaJbYEi4MoI1cU1hVUUTjJmDYqfdQ7 5kHPFR+TEX6ZR3CZFF6mxhjBmjzHrnnQJCp47xVI7zlmDWALl+NcISZecmocbi4rnz1K fz7WoLSZ7xRI9XHxuHhYskPwFSZ4059aAxxcgn0F+zxjyKkp9/WVAkwoct99QpnlbUFG 6Nn5o1SOAK0Z2ESccQM5RqpFDWK35zZtcVpOARhUxHnVVo6TezmZ26UyUECxaUy7QeCJ +VLRM4rRUzyeZ7jxx3JE47akZp9E5VkBKV7GxgIYSWCa/ay9SrZP86oUTProms1gQn09 blEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pBJiH4urg4DBG6eZbcNPwgnZOdXfIaMFo9RuiRFHB0E=; fh=st1dOkjG6xA0fdjzTGWDQKgsEfVQ0XUGPuMTHfrkB5U=; b=CPnKIDs8QJzG0dRviOi4ttFreAdsNFws/BrqaRP5ANFM4CkbpVScRQIjxCi1vnU+oF jflMmgJIcswump0QAETxZSx+6hgx7ZyQxqtvkUoL022sEkAmAiR3QUZXl7g9q/5DOeWQ uYO0i26YYv78dGX4knG+pINOfb5/FP/VMf9VSFfjr9E/UpTXPwV1XsgTLsfb38INIaRy cjnmZbGh6E7cB+9CLJvgb+e950egfbnYwgFf3nHbx2nLFGplCderrIq7HWGHqfkBFk0R sWAyYrKsQGxYegYNua2xGruPWD7LiCoPwoYQVsYmUWB2cfOw6ZA++YgEEo552TihlDdg V1cg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NsJKJOXw; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-149000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149000-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ne6-20020a1709077b8600b00a5239676f38si6212307ejc.877.2024.04.17.10.36.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 10:36:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NsJKJOXw; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-149000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149000-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 E14E21F2138D for ; Wed, 17 Apr 2024 17:36:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53E23172BAD; Wed, 17 Apr 2024 17:35:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NsJKJOXw" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 F1AB3172777 for ; Wed, 17 Apr 2024 17:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713375352; cv=none; b=pLByVhOuP6OV07nHXl4SQHcmVJb71eyo6jvgtlbnjYe+k6CtpPVvGO0GrRZws3Rg+F28n4AdhXDmNzH7hGBXJ0X0nxJ5Qnj577nhasazSJzqfweb+9biRZxPzKzCDzOC8VCTDB6jtLCYnrohyChJ9LhnB7rhAp1bdGhzxCBl2Cc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713375352; c=relaxed/simple; bh=EUEq5eCikvb1PA+1pE5jT5oLwrFNWhGgWfY9hb71rBI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hiZb5p0wTP8RsigVyezS03qNjfGeGJ2q8VrcVudaATC3tO+8a0FK5apl+oTFUJjzv2QemYV21b6sCaIANpf9176+a9HgAhgl50ZrdOpuzBGGZnOeTLlU7AySjWTYUFCMI9B2EeMiQuxQVED2NsXme1M7Nmsq0QtwdJJBn/Xw7mU= 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=NsJKJOXw; arc=none smtp.client-ip=209.85.210.169 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 Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6ed3cafd766so48089b3a.0 for ; Wed, 17 Apr 2024 10:35:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713375349; x=1713980149; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pBJiH4urg4DBG6eZbcNPwgnZOdXfIaMFo9RuiRFHB0E=; b=NsJKJOXwccHJwQ85rjFYE5qWw9ab4sPiSFGsQinb/nv07xhBj94Ty+ttoygJ0Ayekz IIgZxNprKvMkfksYKhW89s9hAPPiknzK/5deAJu7lU0fzVuUuzZEBlx/o2LjL3ZEwbWS JOzOo19mCKfQko9dmQUoQpDC+YeeC3P/p0bH4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713375349; x=1713980149; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pBJiH4urg4DBG6eZbcNPwgnZOdXfIaMFo9RuiRFHB0E=; b=vIfAD6fyPTeS1Y1ykAKrAqVXlHjDv01Uw/JdXVQdyCBr7ACLWVQ71hNkbPyssXYuFf nraTOtDN5uwLxnAoPLvFfNlU0em+81iHW5hiITsXceg6eimmHUbCVnjXW61RLsbWQ0pt MEplG9oZd7NWOrVm/jIr2anP0dwLLpWJIk1wprO/BF4sN5H9G4x9AAM8u80FqBb1V+jQ GwUw+SESKdlI1lC0lBp/aeTh86m7spQv/URblvMVHm8F8Xd+/1zA+xrUZ8ZWLgAF+gb4 4GJLxV6RdN0PApDE6EgG3VoInhmvgyIY81k3i7Y1M/oqtgwMjtXTbrZV5u/uSeYeAhHF GL/g== X-Forwarded-Encrypted: i=1; AJvYcCW27UufYszATATl+3JwJmVtZTLvInhrP7B0RaqyvuverGR+3EtFQZdol3gt1eWJ8TriAb8Evf3aVuamZB9Xt1AL5yl0V+sLS7tB2z33 X-Gm-Message-State: AOJu0Yw1FhORLRn+StSy/rq9rnybSWA9mgvs/X74aw2u+wKbUsdkB3sp epWGic8Z6Ytw1GRBboi3Q4fHadDXZuvjvB6OIMgwRgER4uC1iiINk12hsSriUA== X-Received: by 2002:a05:6a00:22c4:b0:6ec:ec8f:d588 with SMTP id f4-20020a056a0022c400b006ecec8fd588mr281477pfj.16.1713375349095; Wed, 17 Apr 2024 10:35:49 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id gx15-20020a056a001e0f00b006e71aec34a8sm10927754pfb.167.2024.04.17.10.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 10:35:48 -0700 (PDT) Date: Wed, 17 Apr 2024 10:35:47 -0700 From: Kees Cook To: "Martin K . Petersen" Cc: Charles Bertsch , Justin Stitt , Bart Van Assche , Andy Shevchenko , Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , "James E.J. Bottomley" , Kashyap Desai , Sumit Saxena , Nilesh Javali , Andrew Morton , Himanshu Madhani , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, mpi3mr-linuxdrv.pdl@broadcom.com, GR-QLogic-Storage-Upstream@marvell.com Subject: Re: [PATCH 0/5] scsi: Avoid possible run-time warning with long manufacturer strings Message-ID: <202404171035.BDFF28D@keescook> References: <20240410021833.work.750-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240410021833.work.750-kees@kernel.org> On Tue, Apr 09, 2024 at 07:31:49PM -0700, Kees Cook wrote: > Hi, > > Another code pattern using the gloriously ambiguous strncpy() function was > turning maybe not-NUL-terminated character arrays into NUL-terminated > strings. In these cases, when strncpy() is replaced with strscpy() > it creates a situation where if the non-terminated string takes up the > entire character array (i.e. it is not terminated) run-time warnings > from CONFIG_FORTIFY_SOURCE will trip, since strscpy() was expecting to > find a NUL-terminated source but checking for the NUL would walk off > the end of the source buffer. > > In doing an instrumented build of the kernel to find these cases, it > seems it was almost entirely a code pattern used in the SCSI subsystem, > so the creation of the new helper, memtostr(), can land via the SCSI > tree. And, as it turns out, inappropriate conversions have been happening > for several years now, some of which even moved through strlcpy() first > (and were never noticed either). > > This series fixes all 4 of the instances I could find in the SCSI > subsystem. Friendly ping. Can the SCSI tree pick this up, or should I take it through the hardening tree? Thanks! -Kees > > Thanks, > > -Kees > > Kees Cook (5): > string.h: Introduce memtostr() and memtostr_pad() > scsi: mptfusion: Avoid possible run-time warning with long > manufacturer strings > scsi: mpt3sas: Avoid possible run-time warning with long manufacturer > strings > scsi: mpi3mr: Avoid possible run-time warning with long manufacturer > strings > scsi: qla2xxx: Avoid possible run-time warning with long model_num > > drivers/message/fusion/mptsas.c | 14 +++---- > drivers/scsi/mpi3mr/mpi3mr_transport.c | 14 +++---- > drivers/scsi/mpt3sas/mpt3sas_base.c | 2 +- > drivers/scsi/mpt3sas/mpt3sas_transport.c | 14 +++---- > drivers/scsi/qla2xxx/qla_mr.c | 6 +-- > include/linux/string.h | 49 ++++++++++++++++++++++++ > lib/strscpy_kunit.c | 26 +++++++++++++ > 7 files changed, 93 insertions(+), 32 deletions(-) > > -- > 2.34.1 > -- Kees Cook