Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1460025rda; Mon, 23 Oct 2023 13:20:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzm/yyFuDQx7Z/fu7gNxOQfIv5abV/4WcEpQ50niRg3DERwkCfrzx5boQju4hs9EspqMQY X-Received: by 2002:a05:6a21:6d86:b0:14d:5580:8ff0 with SMTP id wl6-20020a056a216d8600b0014d55808ff0mr713056pzb.25.1698092445136; Mon, 23 Oct 2023 13:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698092445; cv=none; d=google.com; s=arc-20160816; b=fpuhLu19UdLMA3YDYy+idSp1e0bqiWI7qTArnmT4K088nBWzlZuual5z8uGVHGnW3H Wkn4vrdOcTc9uk+eapWzfyPDA0P0Z3nmxgXKYie0xKHHjznDZG0t2sz1JkabSfC8aCS+ xdYArm1vLyuV+lEODmjKrFjTRKgJcCnl9TAhgMjPPptmhJTOARE6E9bU5NHbiqCqdkPl oa+WcHia6hdgMek/CqWmLpiGz6RChlsn5fDYHbqceYjXSlrWb+Y83ZHj1/khPymksg0a 58WRAITA73nKiBgExIY8ol/SpqClUeyVlYKs3aQIoce3W1F0Rit1dvV14lh8utB01/sO e3Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=HC2YENnbBf3idqNUjad+LLWvlI/rBfsrY/3c0Jg2xIA=; fh=HiJWt/kG7tSyY6Uo4iC/jAFuHTi6jLnaFsj+qSd/6Bc=; b=ItyyEv7e6MyYSpR55J2j7nFCTWpyLzYHxl/kbiHQeG/IlbhBMHvNxeFBAT7T60w8Bx KXCfJSY7YwqWazVHzFOHMRok78+JTlIh/4fl0hfQe/11PuVv/g2ZWYDEEv+bRgN0+HAk 67Tu6XHYRWg0y/IplnI49Hsw6OXiOAxB/OcFi0MnU1TB8LcvhRox+sUc+6kRnKRd0gKy bExvavwNZDVXNU85gWYC0tWxd+i7uyMf+I2LEPXtf4RSGCWirfkSuJ4euLs4AE8YU/FI 2JPR2FpUulqppld2GVt1bXl2UG5HLPo4s2gW0fDnPFRHrRfSX9s8SizoXPKZD3XIYwYW z44A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IsgfIm2m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id h14-20020a056a001a4e00b0068fe7c4147esi7076085pfv.391.2023.10.23.13.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 13:20:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IsgfIm2m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id BA73A807E89E; Mon, 23 Oct 2023 13:20:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230197AbjJWUUW (ORCPT + 99 others); Mon, 23 Oct 2023 16:20:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230489AbjJWUUT (ORCPT ); Mon, 23 Oct 2023 16:20:19 -0400 Received: from mail-oa1-x49.google.com (mail-oa1-x49.google.com [IPv6:2001:4860:4864:20::49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42921D79 for ; Mon, 23 Oct 2023 13:20:17 -0700 (PDT) Received: by mail-oa1-x49.google.com with SMTP id 586e51a60fabf-1e9c1e06ce9so5130665fac.2 for ; Mon, 23 Oct 2023 13:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698092415; x=1698697215; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=HC2YENnbBf3idqNUjad+LLWvlI/rBfsrY/3c0Jg2xIA=; b=IsgfIm2mc9Q+Tt9DydoqQ0cdfhOX9jeku/ZRH69WHJBzKa4KY6kyuhwihDbTXYbAJ/ UkJkP5L4obeZQJVEAG9BVtK8JUs1uh6APJP3bjEwLktkhCkq45j+AyXzXYbVsN8+muYP J+EaVd+zYsRE+jWmYDQjJ5PA53eCGvQMUBUvgXjilkkr++2/CNHjdoltZY6YQU5kstn5 ks92vNdzmToSdUhtDpGzNfyxlkfq1UPaqVUYJtuxM1Qlk9+kYgcnBdGLGgu59EDnsA2r MMxAIy3C0r+MPiexD02omEMVi0O9EzVAm2OxCjEj6w91Erm5cOW1DURALWdSHdye7tSb Qwww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698092415; x=1698697215; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HC2YENnbBf3idqNUjad+LLWvlI/rBfsrY/3c0Jg2xIA=; b=XIppENXCP2f1c2/6GZpL+F9gMgfyw3YGSLIA4EP707hdxoncIOpPHdLIQEW/WyJzfg +rHXSi4qyWuVEbLzzmEaQoxMkVFt882Fd7nU/FBwGqzVX1BDWFNVaZyTrR13xmR2mMgR ltaQm3ykkPbknkcj43X90RtcOfDaCkhZowOuEtOvs6PE4FrrR3r3hX9t4ZzqQVSlJfYj 6HhGsv0MflSGL/EmV2xmt2pzeuLO0SvW2b3tTTAPxOfr4K7vL98IQTYdvJkNQu4trYYc rHNhnliQVx7gUuXrNU5gkbsldcnGwy8vX2ib3r6/TNbXDNgL1YkW1zzOJsq/Mc4SJrWx GJHw== X-Gm-Message-State: AOJu0YxB6+VbeX7DE3Ztp4+U/XkQ/D67jJUq5+9TFuELfZuHZu/NBHZv 7SnHqE30+aZ2WABhDO3U6bpuVTzPM+5stfsvkg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6870:171d:b0:1e9:9202:20c2 with SMTP id h29-20020a056870171d00b001e9920220c2mr4686466oae.0.1698092415210; Mon, 23 Oct 2023 13:20:15 -0700 (PDT) Date: Mon, 23 Oct 2023 20:20:14 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAH3VNmUC/x2MsQ6DMAwFfwV5riWSMPErqEP64oKXENkVaoX4d 6ION9xwd5KLqTjNw0kmh7rutUt4DIQt11VYS3eKY0yhw/6xivbjYnqIOTtcGRuDY3oFlIwpAdT 7ZvLW7/+9PK/rBviHA6drAAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1698092414; l=2576; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=u26UkFA2pIT/4F5ARGnp0D+oEDN12dlRus5r6WZtCT8=; b=Ct6Uk8Ut9tGzpS3O6U9vzqDZRCJthZZmKeW5UgOFzxoK3M24GkZxicWT3gFJsfPzm9KZNClPv mwwAPCHwo5nCv/HfOtU+WtuThMSa6XqR6GQRXu4XZZcWh/6mHKr/yNm X-Mailer: b4 0.12.3 Message-ID: <20231023-strncpy-drivers-scsi-ch-c-v1-1-dc67ba8075a3@google.com> Subject: [PATCH] scsi: ch: replace deprecated strncpy with strscpy From: Justin Stitt To: "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 13:20:31 -0700 (PDT) strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. These labels get copied out to the user so lets make sure they are NUL-terminated and NUL-padded. vparams is already memset to 0 so we don't need to do any NUL-padding (like what strncpy() is doing). Considering the above, a suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. Let's also opt to use the more idiomatic strscpy() usage of: (dest, src, sizeof(dest)) as this more closely ties the destination buffer to the length. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- Note: build-tested only. Found with: $ rg "strncpy\(" --- drivers/scsi/ch.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c index cb0a399be1cc..2b864061e073 100644 --- a/drivers/scsi/ch.c +++ b/drivers/scsi/ch.c @@ -659,19 +659,23 @@ static long ch_ioctl(struct file *file, memset(&vparams,0,sizeof(vparams)); if (ch->counts[CHET_V1]) { vparams.cvp_n1 = ch->counts[CHET_V1]; - strncpy(vparams.cvp_label1,vendor_labels[0],16); + strscpy(vparams.cvp_label1, vendor_labels[0], + sizeof(vparams.cvp_label1)); } if (ch->counts[CHET_V2]) { vparams.cvp_n2 = ch->counts[CHET_V2]; - strncpy(vparams.cvp_label2,vendor_labels[1],16); + strscpy(vparams.cvp_label2, vendor_labels[1], + sizeof(vparams.cvp_label2)); } if (ch->counts[CHET_V3]) { vparams.cvp_n3 = ch->counts[CHET_V3]; - strncpy(vparams.cvp_label3,vendor_labels[2],16); + strscpy(vparams.cvp_label3, vendor_labels[2], + sizeof(vparams.cvp_label3)); } if (ch->counts[CHET_V4]) { vparams.cvp_n4 = ch->counts[CHET_V4]; - strncpy(vparams.cvp_label4,vendor_labels[3],16); + strscpy(vparams.cvp_label4, vendor_labels[3], + sizeof(vparams.cvp_label4)); } if (copy_to_user(argp, &vparams, sizeof(vparams))) return -EFAULT; --- base-commit: 9c5d00cb7b6bbc5a7965d9ab7d223b5402d1f02c change-id: 20231023-strncpy-drivers-scsi-ch-c-23b1cdac43cc Best regards, -- Justin Stitt