Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2453248rdh; Wed, 27 Sep 2023 03:12:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IER/MPc/s6ww35uCnhQkpAbwzqDfdorT0Prey80Hz5/l6NT2g++GEk79MhU/lJMgh8JKGas X-Received: by 2002:a17:90b:3785:b0:268:13c4:b800 with SMTP id mz5-20020a17090b378500b0026813c4b800mr1361670pjb.21.1695809521826; Wed, 27 Sep 2023 03:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695809521; cv=none; d=google.com; s=arc-20160816; b=ZDuaO4wMRhHP4afOAqoxQeD7eq35/gA4Fo4Rf5iLj0gtaMgoSRUSZzJikBpA5BECYB 1T5kvpY2S5x+6p1TFbM3syA+w0PFXOo9MP3cagI7wcNBIU40Q3jA3oAyvRK561B0Q/ou kTPg+QCAv2rUZUlDMice8ovpXC6vXLIkdQwDdSIMwbEYpUumLAwmewrNkIbPEvXXs5Q9 qB03dg7Ms2vrQ16w/9gRy89NQw96W96Di96YKcpqfxxjYLzQ/LvD2y7rLkYSVpjnAADe A81ZBqCNQ36ywJMeUS8zs8D1elI2SNXNoltUyxA2YCiqacClLODanQD7egOjjvo8Wvl/ dB4A== 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=lz/tzt2FhoJSlisVyBotc0Kj5HYUeKExNXWDpILSgIc=; fh=cJI/+0BUhef/5QIIweDWRKH3RfXQG3bzIdy0ZDtFDCg=; b=d+HZxODQOuMHG3XKfezXo5faTVi7BP9gNEfhEpr5Gs1sGHDwKP+ZaCO3apZC3Epf7z iaBs1woUPPG+nqrWHK5D44YUKDYx3tav5JKXfbkMTRqDVa7PcEj0iWXCco7bCvxNa097 8sIRardxEiFtUX6pNYvgwo4SE4vYNnvrfUKisx7OGMoscmnOzv+ymFRsilD4DXfUr6JA dZnII16RNE2pii/H5ANct6Xmt50UqBLBqkXckqHqU1hDwRix6wJgHDxuuAh9HPVuAZ/I CjFpjJjkpyh4M251Ev/oWsEjnNL5XkOhJNyU4M3ZDC1Uqn0Yri5v1zg12xpmZ/G9Snks PsWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jxPSRuCh; 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 gd22-20020a17090b0fd600b00271ae22eea7si16898486pjb.117.2023.09.27.03.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 03:12:01 -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=jxPSRuCh; 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 69C6F8037963; Tue, 26 Sep 2023 22:24:52 -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 S229579AbjI0FYh (ORCPT + 99 others); Wed, 27 Sep 2023 01:24:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbjI0FXy (ORCPT ); Wed, 27 Sep 2023 01:23:54 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D79F4205 for ; Tue, 26 Sep 2023 22:21:00 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d81e9981ff4so15177536276.3 for ; Tue, 26 Sep 2023 22:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695792059; x=1696396859; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lz/tzt2FhoJSlisVyBotc0Kj5HYUeKExNXWDpILSgIc=; b=jxPSRuCh2GiA5ml2AR0opCZ88ky6+UTpPBhYDJpn5sXvyQwKuI/mwdBIZOaYL7wPtu i3FzcUZ4jj65FV/lLI1grLztvVU44S5nygVz7YhgY7+8ZKaPHbUw70ciOMexYtYJb2c0 obnHNiTmphB52b7IoHuoOz+KZV+Wkli92J2JazC8U/ZoyEZIB+lydEqI+GRitHeTwqIL bxUHGZxMECI0AqCkcSBdLgJAHYPzQWQoBYMn1dQqldu6zSyAJNJBcXtcqI/PgnVNFa7T gFH2s8OJzbJfmJo15bwRGJ1PI1z0ZbXPqRxkJe9lVf1EgDnZYT4uwzk266g3Cr9zUesi X7OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695792059; x=1696396859; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lz/tzt2FhoJSlisVyBotc0Kj5HYUeKExNXWDpILSgIc=; b=wJnhf6U3Sl0nYSaEu52aEMI/tXXmgAMkJL4tKh935IJvXpk1cQtuh5ajYQ2ZPid+ue gvDREWkU8R5hNy3UYG5CbRgzk78n2ONi0eS37KTCodjq1dwd9fGJYKXYeqgVrwk7YgJD dMosGzqd+URTF9XjugBHcF0e4HIysHIPPwOrMzavPlXERTRNu6cGDaVilDFAGt4MnNrP 6PqRwvjOeQXLYiFA6byWQDnLfykmBspgTtM3agUKhIaglZ3c2RCh5VK4PktG+yskRLkF O50DTbvIf5Se73SvvIkwhGr3dj7ioUHQvMaq4/fqItxf6hp/jh7VYReLRqy9cbpFmk8h K/wg== X-Gm-Message-State: AOJu0YxRhJaRCp9p00cPMFQeOsJYCbJ1gClcpuDx7w64CKu8qQmt6mLD 9oi74kld278ZUqGMZOngRvg8xK8OmPfm5sWKFg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:aa09:0:b0:d7a:6a4c:b657 with SMTP id s9-20020a25aa09000000b00d7a6a4cb657mr12365ybi.0.1695792059592; Tue, 26 Sep 2023 22:20:59 -0700 (PDT) Date: Wed, 27 Sep 2023 05:20:58 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIALm7E2UC/x3NQQqEMAxA0atI1gZsZRS9irgoMc5kYVsSEUW8u 2WWb/P/DcYqbDBWNygfYpJigasroF+IX0ZZisE3vm0G36PtGilfuKgcrIabGCH5nHRHSspIGII burZzK9MHSigrr3L+J9P8PC9p7qJ0dAAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1695792058; l=1837; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=yQqGrF2k0OLEIxxzfq32VFlgneWmvHqUwZOd9GeKl9Q=; b=GcVEbzE3m6R3BQuN95/HUu/Su4qXiV7N+d85g46JeEu4i/Hy5Trt6MURz/eeYNCmmQt/TOPsI UCr87Jtq+Y9D+Uya8HayxqfYkZrp7eEP4oaqYAlYThIOw6C2MGCel/P X-Mailer: b4 0.12.3 Message-ID: <20230927-strncpy-drivers-misc-c2port-core-c-v1-1-978f6d220a54@google.com> Subject: [PATCH] c2port: replace deprecated strncpy with strscpy From: Justin Stitt To: Arnd Bergmann , Greg Kroah-Hartman Cc: 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]); Tue, 26 Sep 2023 22:24:52 -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. We expect `c2dev->name` to be NUL-terminated based on its usage with format strings: | dev_info(c2dev->dev, "C2 port %s removed\n", c2dev->name); Moreover, NUL-padding is _not_ required as c2dev is zero-allocated: | c2dev = kzalloc(sizeof(struct c2port_device), GFP_KERNEL); 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 drop `C2PORT_NAME_LEN - 1` for `sizeof(dest)` which is more idiomatic strscpy usage. 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. --- drivers/misc/c2port/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c index f574c83b82cf..2bb1dd2511f9 100644 --- a/drivers/misc/c2port/core.c +++ b/drivers/misc/c2port/core.c @@ -923,7 +923,7 @@ struct c2port_device *c2port_device_register(char *name, } dev_set_drvdata(c2dev->dev, c2dev); - strncpy(c2dev->name, name, C2PORT_NAME_LEN - 1); + strscpy(c2dev->name, name, sizeof(c2dev->name)); c2dev->ops = ops; mutex_init(&c2dev->mutex); --- base-commit: 6465e260f48790807eef06b583b38ca9789b6072 change-id: 20230927-strncpy-drivers-misc-c2port-core-c-aa196361fec5 Best regards, -- Justin Stitt