Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3025404rdh; Wed, 27 Sep 2023 23:27:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUzQkYpAJXFlqhjr7Aog3iyRukEAwahVCbf2PiPHHx1B/GhVBKllnSkGGHlHJOjkcy3yaz X-Received: by 2002:a05:620a:4726:b0:775:6731:faeb with SMTP id bs38-20020a05620a472600b007756731faebmr342592qkb.20.1695882453672; Wed, 27 Sep 2023 23:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695882453; cv=none; d=google.com; s=arc-20160816; b=seA1CsclGGQ/I5VcLd0x9JU7n8AWlZ1ESLg5w3v2EqGdSYDCOhiNOKpDZPxaOaXHXG tnjaMn6OHbkAaqhbYo09HtmMpiLDRON1FoB9SVcLO4F1Ui1D/HA0PAM/u+Y7xJKgod9+ fHTzZyxSuvrO89wKSJbvpTnP8ul+/+ogtjzXi4IWqUq8KGTyoEabwFcGMqLQOEjiPFzS TyvlVEdhADA9UFJDsff4wIffbR4/OPjgPsFCKRcFq+WrBRASvAoDY9uyeXE5Gup1wCGE yC3KDq8pkfktufHQPaWr0r4bMdocF6o8W2HuID6/rPCelt82YNoXK4Rx36idBs+yYOV/ Jdsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=o781UB75dWtQPWqWz6T4vyY29QjIlXMO7I9AjykpvSs=; fh=yHOoXedj4QSGO1bV+FLNN+a6hC023lI3xzhL/nO/3ac=; b=oYIxfcyN4rxkhWDnuqeW3+rMXPQA0u1/6Lyy0nUgIPvKS2AJV841ZagH3hi0f6RqE8 M2RHLC/gYXzl3b2HKMPhh5ps/rpR2eQ8yPYVbGs0fAHw0BSpCFbkj8Vy9e2zvIERVeas ULMwDQ1ANm3V4b7AfpG/ygvClCB1zI02p5C/s1V7tzn26seheNBbeCDwyZYkUS71lGZb s9BQmQy4vmquOxVbT7piJr79jkwb5nweTen4KEuGteuEFsJv9Xm1LAZOvgraAKYL/432 JfKK5HklxAU0EKyWJh9sONRuQ9U2Cz1F1xTSmZjagdB6che/uon+bvVPrZcYumYA+8Rn gWAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (expired) header.i=@arndb.de header.s=fm1 header.b=YOT4isX4; dkim=neutral (expired) header.i=@messagingengine.com header.s=fm2 header.b=U1yJVQKv; 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 Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id be3-20020a656e43000000b00578a30162c8si14510984pgb.537.2023.09.27.23.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 23:27:33 -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=neutral (expired) header.i=@arndb.de header.s=fm1 header.b=YOT4isX4; dkim=neutral (expired) header.i=@messagingengine.com header.s=fm2 header.b=U1yJVQKv; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 122E981BAA7E; Tue, 26 Sep 2023 22:52:43 -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 S229732AbjI0Fwh (ORCPT + 99 others); Wed, 27 Sep 2023 01:52:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjI0FwE (ORCPT ); Wed, 27 Sep 2023 01:52:04 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09A94DD; Tue, 26 Sep 2023 22:50:21 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 069EA5C279B; Wed, 27 Sep 2023 01:50:19 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Wed, 27 Sep 2023 01:50:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1695793819; x=1695880219; bh=o7 81UB75dWtQPWqWz6T4vyY29QjIlXMO7I9AjykpvSs=; b=YOT4isX4Z7eoYa9AnX A+p+d+XSOzWhESZ3HtZ5f6sQlTcTZ8CrMeGEqmzqdI614EcFxdsaYTaPfsrHPncP hwMC4AOqd2j+thNvvcFUF+CoxfFGfucoKRlRHyOz0NZaeiL4W9I7Gz2kunvnHwaS 4Q/9YvxoMperG28X25H3nf8af6f1T2CEHKX6hpkR8Ebx2MQPz2r2gzTu5SIU/5N4 Zc8BwIT4MX5KmMeVXUYIBvITzHvAGKRpVK2MDSTVjQrtn0OS3YLGzlxgYKZGGU8c tsG3PMUGlsDG+i7a4U4U3W5+FJh23Jyc0EoEPbTHWUTpn556ioRFqs3SWiADyKui MZCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1695793819; x=1695880219; bh=o781UB75dWtQP WqWz6T4vyY29QjIlXMO7I9AjykpvSs=; b=U1yJVQKvG270QvtV7tXFsPOcaZLLD yEEH2DxH+BOtgfVJJPX+5AawRPDaO9+TPqhh8raF0ml6dxYGFqoG1UmZyKy1VmZN KPT+bnVUmscNnHNdP5PDSx0MzZz2635/ofTrtwtfu9N2a0ICKfoR1K8N7/sdQwcA O9QcI3G3XAmq1pOd4KYqgJrA8ym7Jl46fNVpQqfLG9UbhTYlnfYMUaRV6ii2LLiU 1NNsVcsQRWJZHE98+znNbq5/ytyP3em9yfVxJeEFMt799bq694UUVd5PgPnR0HZY wy4HRRppFkWcWMrFPyvd7SpKeaDyuoQuXhXwukboxKgxBDYBf53nIS7/g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvjedrtddugdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdetrhhn ugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrghtth gvrhhnpefhgefhteevtdeviedtgeffueevjeevtedvkefgvdekudfftdefledtudeljeej hfenucffohhmrghinhepkhgvrhhnvghlrdhorhhgpdguvggsihgrnhdrohhrghdpghhith hhuhgsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhf rhhomheprghrnhgusegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id D043EB60089; Wed, 27 Sep 2023 01:50:17 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-957-ga1ccdb4cff-fm-20230919.001-ga1ccdb4c MIME-Version: 1.0 Message-Id: In-Reply-To: <20230927-strncpy-drivers-misc-c2port-core-c-v1-1-978f6d220a54@google.com> References: <20230927-strncpy-drivers-misc-c2port-core-c-v1-1-978f6d220a54@google.com> Date: Wed, 27 Sep 2023 07:49:56 +0200 From: "Arnd Bergmann" To: "Justin Stitt" , "Greg Kroah-Hartman" Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] c2port: replace deprecated strncpy with strscpy Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: 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]); Tue, 26 Sep 2023 22:52:44 -0700 (PDT) On Wed, Sep 27, 2023, at 07:20, 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. > > 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 Reviewed-by: Arnd Bergmann