Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2789256rdg; Mon, 16 Oct 2023 15:19:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFr5fQK2TIVT1urdklbsiJpk5F3YqOrkTf8Tupk/rMERoZxAD1iFyRDqMyZUBxPvNPCuMep X-Received: by 2002:a54:4486:0:b0:3ab:5e9e:5206 with SMTP id v6-20020a544486000000b003ab5e9e5206mr663615oiv.5.1697494744670; Mon, 16 Oct 2023 15:19:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697494744; cv=none; d=google.com; s=arc-20160816; b=o8YSnlIcxHwdsQn3tbXWO5BPMRTvx0e8e6qQrk1n6rRb4/9DjlakUEHCgNPeGcg8sn n0I9/kdhTSdrhklCNTu8x1GCGmxu4XqdkbuO1ZQqlJk66y7AehBWP0dprAhQpzk4X8Qt iS5lCDOCzq+2l5tyrZBk0mYChca1qrYf/cK5Zz1914yc7NuxtrXSqXNmZqqFhLjGO/zV YT9httlBEjDeNEC6gIePjaOzNjkrTAPFKDZdPfzfsckNKnLEKCzKbw40Xb1RXY+D7LlV jD82pKS46fFZ121oYUlrEwUldXM1Wb4ElHNQ2U5G4IaD3NXSyuunTuKdcXicinfEnxW0 8R2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=d6znq/+hwOoOtlAq0vxf3t3uFvVHfxb7ymnzjeKSrkc=; fh=pVgo2gjNI/3jgxCr98Xunqo/Mhv21+EtvXgjW+YP484=; b=g8J8N0rYZX6M6hTfgSxLgkqurOW9TWtiT9xURVI9JFi9wB4WPG/8UG10piKnW2DXzn s0BHFADqzg4v2zBeFqRMXkrr+tI3qE7xAB+5wbh3noeQUtsEm63kyDTctQRPn19aiBpc 4GeVXqzAow+GYl3ty2SWZlcTfsa2q9M4CTtcc8ONq8bb3pipdDRXEYxpMLm2BPj3JcW3 USACU3D/0AEEVZncL0Jqc+wyG4OlwW1ziO2Dg26q/AGT3wtypVDU/lDaszMw/xArM9IZ AhRausSmxGauCxKSzUNSbfgCwi3f0EUr3q2WbYwFlvHA5wlvVHanbXDrMOafWbFEay+Y MQtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@blemings.org header.s=201708 header.b=RCKsOt0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id x4-20020a63db44000000b0056a19c7c2e5si267251pgi.361.2023.10.16.15.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 15:19:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@blemings.org header.s=201708 header.b=RCKsOt0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 3ADE6808494C; Mon, 16 Oct 2023 15:19:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233494AbjJPWSt (ORCPT + 99 others); Mon, 16 Oct 2023 18:18:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbjJPWSs (ORCPT ); Mon, 16 Oct 2023 18:18:48 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2429F95; Mon, 16 Oct 2023 15:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blemings.org; s=201708; t=1697494722; bh=d6znq/+hwOoOtlAq0vxf3t3uFvVHfxb7ymnzjeKSrkc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=RCKsOt0wc6mBzYU1kS1/U/XycX/WkrH8liDOp4mgWoaiLDF2i0+Z4T9PfWGyofehT HpSRBKYHViKBY2X8toNH9lTpasWbtah2wRh9bcsT0jbF+2rOpEN8Q/8K5DQuYG0KDT 8cznpFi9iMDLLzTF2V/OzQrrdLcCeiZW5LROUtvhsgS2oxZyiDzNi8fg94mmNar/AE zKvuk9qx3XqMkdjk/d6RPiHAPZYln9PdkxUUnGYJkjaK4qc3ZXp1lZgCFK7kTHD2jp vr3fIkszmh4vDyPweWNVKv2K4t61wa7zzED66ipqQxih8LJfNlyG4BOLS7biTE6hzT RO4KlClzvJ0/w== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4S8WjC6qqXz4wcN; Tue, 17 Oct 2023 09:18:39 +1100 (AEDT) Message-ID: <2b9fa498-e099-4987-89d3-dd1a5df24705@blemings.org> Date: Tue, 17 Oct 2023 09:18:38 +1100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] hamradio: replace deprecated strncpy with strscpy Content-Language: en-AU To: Kees Cook , Dan Carpenter , Simon Horman Cc: Justin Stitt , Thomas Sailer , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-hams@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20231012-strncpy-drivers-net-hamradio-baycom_epp-c-v1-1-8f4097538ee4@google.com> <20231015150619.GC1386676@kernel.org> <123F9651-9469-4F2B-ADC1-12293C9EA7FE@kernel.org> From: Hugh Blemings In-Reply-To: <123F9651-9469-4F2B-ADC1-12293C9EA7FE@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 16 Oct 2023 15:19:02 -0700 (PDT) On 17/10/23 04:03, Kees Cook wrote: > > > On October 16, 2023 10:01:20 AM PDT, Kees Cook wrote: >> >> >> On October 15, 2023 10:47:53 PM PDT, Dan Carpenter wrote: >>> On Sun, Oct 15, 2023 at 05:06:19PM +0200, Simon Horman wrote: >>>> On Thu, Oct 12, 2023 at 09:33:32PM +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. >>>>> >>>>> We expect both hi.data.modename and hi.data.drivername to be >>>>> NUL-terminated but not necessarily NUL-padded which is evident by its >>>>> usage with sprintf: >>>>> | sprintf(hi.data.modename, "%sclk,%smodem,fclk=%d,bps=%d%s", >>>>> | bc->cfg.intclk ? "int" : "ext", >>>>> | bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, >>>>> | bc->cfg.loopback ? ",loopback" : ""); >>>>> >>>>> Note that this data is copied out to userspace with: >>>>> | if (copy_to_user(data, &hi, sizeof(hi))) >>>>> ... however, the data was also copied FROM the user here: >>>>> | if (copy_from_user(&hi, data, sizeof(hi))) >>>> >>>> Thanks Justin, >>>> >>>> I see that too. >>>> >>>> Perhaps I am off the mark here, and perhaps it's out of scope for this >>>> patch, but I do think it would be nicer if the kernel only sent >>>> intended data to user-space, even if any unintended payload came >>>> from user-space. >>>> >>> >>> It's kind of normal to pass user space data back to itself. We >>> generally only worry about info leaks. >> >> True but since this used to zero the rest of the buffet, let's just keep that behavior and use strscpy_pad(). > > I'm calling all byte arrays a "buffet" from now on. ;) > A tasteful change to the sauce I think. ;)