Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1267744lqt; Tue, 19 Mar 2024 19:48:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXNxkOhvMj8sPxt9TJXl/qrVYfLtVeeNxqB3OBNlPxov6KugVulzY0uZzJJHnXPwp/EZmULASR4I/5Pzebnptk5s8suHjzjAXQefoebZw== X-Google-Smtp-Source: AGHT+IHlJn2C1wPKoHgSCqyUiq5TyWESbLERBbVz+3V+ekiq88J5AN6ImO3FWdyT+j+5pRslCNuy X-Received: by 2002:a05:6358:4041:b0:17b:f03e:2bfa with SMTP id a1-20020a056358404100b0017bf03e2bfamr21660578rwa.21.1710902926578; Tue, 19 Mar 2024 19:48:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710902926; cv=pass; d=google.com; s=arc-20160816; b=CMjkkkA+yawbeP6kjVQw78mw2SNWyc7hiJd1fSc/03KfbznJ8ZGDi4dJBQlugiTA9E mMY6uqGTUWSe3HgxpdW3ibsVGDfl/e3oNxjxDFNDQ9FsYSb1ImgPjH1shSBxkKYrJK10 y7l/7hqqlODn6FkaVKmB9YL4vVkpX6Zc+4eL6bIHJMtZzbzjqhLNJiUYc/x9gMunN1Wr xsi2wfg5w/ivp/uNPFqiSni4T524Stp74fmzemjb3kdMVDlm86XG2yAQCt7wWcF9/xb2 IvYkcSzrdXYZ5u7TFR+N/1pcYqkhUmHrDA1VGov25cKojQWLQIQ2bx2s4avxI2FildEN aJyQ== 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=o2Ii+qg5LzdQ72UpZAw1asNIZXswSUTe3sjnBVEowPI=; fh=46G1ewdbM2sT2iMdxp/tPV+BgbfATS3phj4W1hhDXRE=; b=iqPgDUQec/RqHvjHw9nC/fxBMeu2xYvlmClWBZo98wMW4CeS83jJjsEvK3neq+w4Dk rEtuWGD4Jgf8DwD0oi3nDWFTnbhV/qSVfxJaR9Kguural1If3pBmwrBHdz1IWZGBpMRc DKtFNWIuuVx3k+TAJS0I3vo5sIH7XseuF6ghgd7rc+APjpkVVTLTV+IA0arU4c8gKWuY bZGFgtwokx859QmzvuJGox4D7HlHNtEJ2HPZgT/Mbk3k6COte825NlFiDaDMaAZpO8Kg rQ8aNiw66k2KcEhW6nhrQ+Ida0kDu7tXoYLaj3sIsz3Rz5p/2BRg0A0Z+8DHheOUWBrG d0qA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FpK80cf2; 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-108374-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108374-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p18-20020a631e52000000b005dc8762dce5si11508814pgm.51.2024.03.19.19.48.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 19:48:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108374-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FpK80cf2; 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-108374-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108374-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7B435B23B3B for ; Wed, 20 Mar 2024 02:45:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2219A38F97; Wed, 20 Mar 2024 02:42:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="FpK80cf2" Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 4976229D05 for ; Wed, 20 Mar 2024 02:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710902555; cv=none; b=t79aIRx5XpiuHuzcpjJ0LbAcdaTZM4STxkVfxGCsZst1VzdyngbjW/B4g39Udgf6pYFaDgPxePtYCOUa+LJBUNqwjIMMzyGzLYJTvdHOXch5lwZt1dnD75SjdcN8EBa8mVCqTZQX49GFPAdX8nzK+KHyrCPMEuE4P5Rfq+QZx98= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710902555; c=relaxed/simple; bh=s7xt3J/x1P5iR0tIyAeOfFanpdd7tKxd4ngYLSRwbIA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f+b9xI1UWN+RFUikBR8HVjXyBuCrzemwXKPaxe4Xi7LL4HkbGi7UzM3zN3P1UTQ4N3FNLszuPcJyipMNy2frNEEH/sCOSeEjWx+NQRbJtli8ARp8QnLrATL10zKMgbkoUAwS38+5bTWgDlqbLgwHoidemnDwjz0JkRhiSJqIGrw= 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=FpK80cf2; arc=none smtp.client-ip=209.85.210.182 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-f182.google.com with SMTP id d2e1a72fcca58-6e88e4c8500so49265b3a.2 for ; Tue, 19 Mar 2024 19:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1710902552; x=1711507352; 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=o2Ii+qg5LzdQ72UpZAw1asNIZXswSUTe3sjnBVEowPI=; b=FpK80cf2hM+7NsrMo3H6/99ZxSX+fOtbFEkSaWi8p3DN2NqOxOHPtTOkYEavLFkjT5 YXJaHKy6FKA12ArFyKOD9WEx+X6Z3d+QJbdN6O6TvYVK3+E1BnOTYovb9pY3ngHxO6Jc Fc16DNvtVH5bddpkenEerj37o+ETzsWjyW4dg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710902552; x=1711507352; 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=o2Ii+qg5LzdQ72UpZAw1asNIZXswSUTe3sjnBVEowPI=; b=gXrBtsm3PayZMuvFU4Pedp91nfDziR6BtRZIrU+ye2RS8wlLzD2z2+LVOHoAGJXySe aqg7KVU8K0I5m+kFy9YeRlKeEdQdO2UVwAoWAE14dFinSVyUv0VaXaISN6R5NKcKnVGo D88YD6LlHsMjleRT8Co5zql6UVV1+85ob2Mwim1ONafZDNwhIeRlIhgEZFmdouP81T3k aFitn07XeyIoFVMPwgnm1TdVB0L9DYi4CoabOZ2cbz0CH/QGiXnaRsjnivR+UmS7LiOH ov5BWFliRz7+5UwxT+/d7K8JMRhuVh24NHkYQO7QLPRKJWjpLc3xWBQrJf+W3gAFPmSG DY+w== X-Forwarded-Encrypted: i=1; AJvYcCUIFcYVkAEbn9cIVmxGRyZEFD5adog6leHWi/H8Al4zaRiC/LOGBo8dESK/J9UJzh098599fWkU2LHgGjGNozEAclvxy87aJp142EO8 X-Gm-Message-State: AOJu0YxtfEQZHBfGSQ9KUe2T0ikFmc4qXE114uMjzkNPKA4RcQnO8tbb HhzbBHlgLyVA+N7MX7TV2Gl7TxbfKXNUcBCT2996Pss4Exczhf1VZmOqabYopw== X-Received: by 2002:a05:6a00:21cc:b0:6e7:20a7:9fc0 with SMTP id t12-20020a056a0021cc00b006e720a79fc0mr9982708pfj.34.1710902552625; Tue, 19 Mar 2024 19:42:32 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id r10-20020a056a00216a00b006e6eb8e07edsm10032341pff.50.2024.03.19.19.42.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 19:42:31 -0700 (PDT) Date: Tue, 19 Mar 2024 19:42:31 -0700 From: Kees Cook To: Justin Stitt Cc: "Martin K. Petersen" , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] scsi: target: core: replace deprecated strncpy with strscpy Message-ID: <202403191941.D2818DB@keescook> References: <20240318-strncpy-drivers-target-target_core_transport-c-v1-1-a086b9a0d639@google.com> <202403191908.1B6BBA3@keescook> 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: <202403191908.1B6BBA3@keescook> On Tue, Mar 19, 2024 at 07:23:43PM -0700, Kees Cook wrote: > Hm, this actually fixes potential over-reads and potential memory content > exposures (in the face of malicious/weird hardware) since p_buf_len > appears to always be sizeof(p_buf) in callers, which means the old use > of strncpy() could have left the string unterminated. > > In practice I would assume it's not a problem, but, for example, here's > a place where the 254 p_buf_len could run out when doing the sprintf: > > #define VPD_TMP_BUF_SIZE 254 > ... > #define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN 254 > ... > struct t10_vpd { > unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN]; > ... > }; > ... > int transport_dump_vpd_ident(..., unsigned char *p_buf, int p_buf_len) > { > ... > unsigned char buf[VPD_TMP_BUF_SIZE]; > ... > snprintf(buf, sizeof(buf), > "T10 VPD ASCII Device Identifier: %s\n", > &vpd->device_identifier[0]); > ... > if (p_buf) > strncpy(p_buf, buf, p_buf_len); // may write 254 chars and no NUL Wait, no, it's safe; I got confused by the double buffers. The snprintf() will always NUL-terminate, so "buf" copied into p_buf will always be NUL terminated. So, nevermind! Regardless, still a good conversion. Thank you! -Kees -- Kees Cook