Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2940249rdb; Wed, 4 Oct 2023 17:08:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkNOtabS9YMNaLfjjRLtlYaczvNcKoFd5+wleU2igZfqzqdcit8110KRgjmE18MKPUlDlW X-Received: by 2002:a05:6358:7247:b0:139:4783:5140 with SMTP id i7-20020a056358724700b0013947835140mr4420485rwa.16.1696464506008; Wed, 04 Oct 2023 17:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696464505; cv=none; d=google.com; s=arc-20160816; b=0wQTkqagWCyq94ywmKg5woszx2+w/PcyU0T+v0qIm74SIcr83pFYpgR/NPordV7Fg5 s++gQwv8TvaAs4YBfPokL6lI7yfpLBzth1p91qSBFEttQCE71Mvye6P0vnG7GGSoBDfK YOt8EMD1tQVarSbYB4GKZdL8/zzXdnlxtKGrws6MNV5Alvvgqx8cmkTHTlhYlWUVI8cw g6Y5QwXZoKFkp+Y5GxEWsgYEF5ZjAdItGVcmxlPaGNAHFN6IZdsKzYH8m6Y9xLT8/o98 YMru6VldqFc06sGl17XyZv3NpwulZJchdIUA4zW6KtAgEPiO99T71qvMnJnuQAFkuDJq zQ3Q== 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=kDV9H2uqIJhr2H0MOz02/qFIRGm8ZuULD9yNay+8KCk=; fh=TQI27PASouGVZF3JMqjWnBFEo6hmdQjMrDhLJNizATY=; b=ASCC0u/KspVSY0g4diV7tHh1KV4xe/+7vtY7HWYC5Bsfu6hkAphswyNP37ySNnK4mK XszszO4i8AriVFAqfiDT7vWrN26zYoHhPDUW0uy9B2epPDLiYPtHHr2kI5ErzbhQ7ane xeUsszsxP+YYeIiioXTV+RdKscgXD5vHRsBJId2urflNvEWIdZ9IQYjyq0IcRpJtRjVt kUUF7CQwDm9WMrA11AMLDFjeIqRxMy8PU7FN5C/8cn1ls+B6Ei3DV5AM7TmmziJqEkW1 grjLD9x9oPa7giA52lOkGLe8yMfLIKRjJfDhiz5RJeWw9pQI1VFBw1cHaoVVtDtAcrSX MM5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K02LwLZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id mu9-20020a17090b388900b00279435d74d8si2741212pjb.135.2023.10.04.17.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 17:08:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K02LwLZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id BF43C8534F1A; Wed, 4 Oct 2023 17:08:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244166AbjJEAFq (ORCPT + 99 others); Wed, 4 Oct 2023 20:05:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241171AbjJEAFp (ORCPT ); Wed, 4 Oct 2023 20:05:45 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C445E9E for ; Wed, 4 Oct 2023 17:05:39 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d815354ea7fso540846276.1 for ; Wed, 04 Oct 2023 17:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696464339; x=1697069139; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=kDV9H2uqIJhr2H0MOz02/qFIRGm8ZuULD9yNay+8KCk=; b=K02LwLZc/Smk0mQ3VBoQ78isLxECitC5Vg1GfKQCmUOBsHVwhyu91I3xP2xKgA8nWl CnX1iJnJrwZ7KrrEGxqlP92wWGiAiPhfniOSbUneU2YXRa7KPaJDNUlnGFgI8PizHRAX p2OgXY8px0NT3V1hLj/ABoeKF1tB5dis+bgxVw0InN4z9UjJuyMd+rPf4fn3sSE2IBBH 5mU2Q5tgptwk+smA7bxPCOQepKL0vUpiQ2eln94WaXK/SSf93WvWNlZGPK27FB8nNIUN 6flZmVKfvMnGXBJkJVyIGntT/Bsw1Op++gCOcTro0LRWAuJ7VHFrhuEITcQ1EXoHpR67 dZIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696464339; x=1697069139; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=kDV9H2uqIJhr2H0MOz02/qFIRGm8ZuULD9yNay+8KCk=; b=eOhsb3el4Gk8uzqz7ipbFTYiEVzjlk6pJwpNsxUdI1DR6QvprT26w2RSx/5pScMl6/ P/UeClike86Nse1A/bj3UGQKm7rYx0IiNut2B6BvgjV5pywIowt3h1VE+4ETz21lsxnQ 7Kh/yAJ+UhdKIlKeZPkFxUutbhy6a1e2FiUZxcqdkRPeKSBf1HJS0Ede1DkjtuULkIxA 75NV7EvP/jZAXS75SB+hFHBOofwZtyT/XQlaFsfWAmMV2uTdcEiWOpyIxVhk5TMYA5wC +n/4r6U4HZ3WSrFJ7NhbbqZBBehmaFM21yppaQdGN5gZ+3LAMmhF8yv4FwbU93SUidjL cTKg== X-Gm-Message-State: AOJu0YzxZd1Nrbru7/1Cn+Y+HEgEPhUbjd2HlZzmXCA6WOp5JR0dVYFq Hkqxi7VMuq4vU8U1el8IVtTNvwvqdp9t11r/TA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6902:85:b0:d86:5644:5d12 with SMTP id h5-20020a056902008500b00d8656445d12mr65620ybs.4.1696464338892; Wed, 04 Oct 2023 17:05:38 -0700 (PDT) Date: Thu, 05 Oct 2023 00:05:35 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAM79HWUC/x2NUQrCMBAFr1L224U0qaBeRUTi9qmrEMNuKUrp3 Q39HAZmFnKYwunULWSY1fVTGvS7juSZywOsY2OKIaY+hIF9siL1x6PpDHMumFhyYX/l5gNX5Pe 1irLwUSL2SPGGQ6IWrIa7frfZ+bKuf7wKd7p8AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696464338; l=1704; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=apMk3PAp7wXCg1G7f65LzqlG2jyMKCWZrLKd+QMkLV0=; b=KC7laJ0xXFcTNOKm5F+aafeyNRacesWewOUckhjMrjqfd5s8iINWyi0XoECH8dh8asYPWgvfu BkhfjUaE7GHDyMxgXBmMJY/o+OV6NUTP4UvGyJ2uJ8NkWTata7w8+5A X-Mailer: b4 0.12.3 Message-ID: <20231005-strncpy-drivers-net-can-sja1000-peak_pci-c-v1-1-c36e1702cd56@google.com> Subject: [PATCH] can: peak_pci: replace deprecated strncpy with strscpy From: Justin Stitt To: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-can@vger.kernel.org, netdev@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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 17:08:25 -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. NUL-padding is not required since card is already zero-initialized: | card = kzalloc(sizeof(*card), GFP_KERNEL); A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. 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/net/can/sja1000/peak_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/can/sja1000/peak_pci.c b/drivers/net/can/sja1000/peak_pci.c index 84f34020aafb..da396d641e24 100644 --- a/drivers/net/can/sja1000/peak_pci.c +++ b/drivers/net/can/sja1000/peak_pci.c @@ -462,7 +462,7 @@ static int peak_pciec_probe(struct pci_dev *pdev, struct net_device *dev) card->led_chip.owner = THIS_MODULE; card->led_chip.dev.parent = &pdev->dev; card->led_chip.algo_data = &card->i2c_bit; - strncpy(card->led_chip.name, "peak_i2c", + strscpy(card->led_chip.name, "peak_i2c", sizeof(card->led_chip.name)); card->i2c_bit = peak_pciec_i2c_bit_ops; --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231004-strncpy-drivers-net-can-sja1000-peak_pci-c-9c2e5e32be83 Best regards, -- Justin Stitt