Message ID | 20231005-strncpy-drivers-net-can-sja1000-peak_pci-c-v1-1-c36e1702cd56@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp479763vqb; Wed, 4 Oct 2023 17:05:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/cV+JjZ+UQfYQzmuOMrzdUZ3WElknAFMSVS0biYp1TbAPrzYT/Goa5ofkHowO6532E2oH X-Received: by 2002:a05:6e02:156b:b0:352:6fff:ccb2 with SMTP id k11-20020a056e02156b00b003526fffccb2mr4361424ilu.16.1696464357350; Wed, 04 Oct 2023 17:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696464357; cv=none; d=google.com; s=arc-20160816; b=QKIdD9Irux+uQXgZHB6cXQWpW69a8xMix4ilwkcxT4WXI+yA8y/hdG3XWLkCzFmkpI vFg0uVYOTxf7gGyoKL5vNYd3iRKG63LuZlKVkKyUlwVxrAlRbHyuhqq61EPP3Luq+gQD d+KTR707qM3AVPeIb2o7dHUX0+mgtdVgonxr3czXp9YXpTQBU1Uo41uhv8A5SMqz4BRk WNwVcxsMtUPX/DI6/mLudQ2jdXvISRWqi2wniwfBiW57P56lnA1zVxaxFTodh8dLWfHt WsFSQK9TQEFKNv8fPe9zJMWoedb8oqOcuE/ausOhGV4rChhJiYR9xGwLa4cyJf0/D8Va zKeg== 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.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id by13-20020a056a02058d00b0057750d57806si310968pgb.136.2023.10.04.17.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 17:05:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; 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.32 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 agentk.vger.email (Postfix) with ESMTP id EB60F81DDE6E; Wed, 4 Oct 2023 17:05:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244175AbjJEAFq (ORCPT <rfc822;ezelljr.billy@gmail.com> + 19 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; Wed, 4 Oct 2023 17:05:39 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d815354ea7fso540846276.1 for <linux-kernel@vger.kernel.org>; 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 <justinstitt@google.com> To: Wolfgang Grandegger <wg@grandegger.com>, Marc Kleine-Budde <mkl@pengutronix.de>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt <justinstitt@google.com> Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 04 Oct 2023 17:05:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778871809560351722 X-GMAIL-MSGID: 1778871809560351722 |
Series |
can: peak_pci: replace deprecated strncpy with strscpy
|
|
Commit Message
Justin Stitt
Oct. 5, 2023, 12:05 a.m. UTC
`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 <justinstitt@google.com>
---
Note: build-tested only.
---
drivers/net/can/sja1000/peak_pci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2
change-id: 20231004-strncpy-drivers-net-can-sja1000-peak_pci-c-9c2e5e32be83
Best regards,
--
Justin Stitt <justinstitt@google.com>
Comments
On Thu, Oct 05, 2023 at 12:05:35AM +0000, Justin Stitt wrote: > `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 <justinstitt@google.com> Yup, this looks like a standard direct replacement. Reviewed-by: Kees Cook <keescook@chromium.org>
On 05.10.2023 00:05:35, Justin Stitt wrote: > `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 <justinstitt@google.com> applied to linux-can-next/testing. regards, Marc
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;