Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2638962rdg; Mon, 16 Oct 2023 10:07:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF20LujVv6XtmUji6pfjER61BYht2kUWzIn7BaxfP8M/LIszK4VhI0I156E5KZOp2MI/2ei X-Received: by 2002:a17:902:7d98:b0:1c9:cf1e:f907 with SMTP id a24-20020a1709027d9800b001c9cf1ef907mr14559774plm.57.1697476019996; Mon, 16 Oct 2023 10:06:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697476019; cv=none; d=google.com; s=arc-20160816; b=lhaQb6tqGi0b7+IXwKTvP15OMsn7gAQ1ZxxMzA3xcn6213mMpAxv9pS5EbgxJEyYpO 0ZSqUi//ZiLjEhcKleTXeeWnSWWfMXQo0Fx5EZnWgOklzCqtCoUFgrwR8RtND5VhaStw YIlJLmyS/3id4jda3h6YPe7EIta6rL/Eyd+3I4Lv02+ocPGGrqxUXrqyeDYaF5TTo1ar wPSqIvgP0O233xBfyCgXZybKEX3Wzo8zSl2GD+L0t/TIPIjAMCR1URo1UyLRnKIJWGq8 Moyjlaurl/+hAXSGOdVy1evFyG/+KTjST4vsT/wFxUP6fRRl2j4AARU5taWHNAPdZO7g SFwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:references:in-reply-to:user-agent:subject:cc:to:from :date:dkim-signature; bh=qTsEcR7mQQVBO/Sv9SuuASR52sGIVTsodBWDNLJzkKo=; fh=IldzluelaSoxmnwG4V7FtApOHR0ETvC4lJvWJEEw8y8=; b=Ju2I875xEYZGVtANn9hM9safqkUqmfYBfumcaqOh4pOGfNE2epCZ+/2H3r3B+eNpne zGxBACkjbpN1VKp9sNdwbvUBia6bnyZdW04L8QV/rY5wRFgwTa7XTwlNgXsptcayBFGH TPvjdVXtPAvj1miM67OpIdvKft5pnee5F9pPNKe8QfL+iy2Yzx6Y+p9nVlytvUfoc5mT yS9lfapiLWEAfQQQV+RPfNMGkiXehfWTbTSCOfjQh6cLIFQYWe6YrdsH1MTCV238eG0a BIA2SR8kHdqkVDpPy2fN7JTw+cL/S98+c1w8y8kVPffCdsY7pkW8bRHQ7l/EhZ7X5FGV PUgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J+4Tzggk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id i12-20020a170902eb4c00b001c39f2b4d2bsi453342pli.438.2023.10.16.10.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 10:06:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J+4Tzggk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 5B3F880401CD; Mon, 16 Oct 2023 10:06:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234394AbjJPRGf (ORCPT + 99 others); Mon, 16 Oct 2023 13:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234408AbjJPRGO (ORCPT ); Mon, 16 Oct 2023 13:06:14 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39B12100; Mon, 16 Oct 2023 10:04:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC7C4C433C7; Mon, 16 Oct 2023 17:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697475843; bh=PfysQKQ+U5oiVOeEEWSdmDvGFo/K4A19Hbz110sUuPQ=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=J+4TzggkoIquBGDze1MsMSJPBHkDy8YKKWcxCdmkCdY0evAc0vCDPTsGbFltdCzRW vm3HHHG9Zp8hANIV9o1QwqtVf0NwZSnhpzTJem3evF8aat8FqlyJpPCeV0UlLkRJkE RyNT3oJP6y4wgV3Xu9+zewRoBaiA0SCJqc9eTgtgZXy7XCIAajxKe/r6QodQ4E/fVb BCf9iMwM130jxv+7+hNrDUB61Gp5FeIcUlQNR8qrKk9/JJmbJQAkGd7BskIB/RRa9E tUHnUBnKISWQojXcvo6/1K0eMZHts1LA3FE7dP0LMLHcrCI5nuMqFFyBnuq1gWKXQQ Jj/G062WwDXkg== Date: Mon, 16 Oct 2023 10:03:57 -0700 From: Kees Cook To: 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 Subject: Re: [PATCH] hamradio: replace deprecated strncpy with strscpy User-Agent: K-9 Mail for Android In-Reply-To: References: <20231012-strncpy-drivers-net-hamradio-baycom_epp-c-v1-1-8f4097538ee4@google.com> <20231015150619.GC1386676@kernel.org> Message-ID: <123F9651-9469-4F2B-ADC1-12293C9EA7FE@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 16 Oct 2023 10:06:50 -0700 (PDT) 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 string= s >>> > [1] and as such we should prefer more robust and less ambiguous stri= ng >>> > interfaces=2E >>> >=20 >>> > We expect both hi=2Edata=2Emodename and hi=2Edata=2Edrivername to be >>> > NUL-terminated but not necessarily NUL-padded which is evident by it= s >>> > usage with sprintf: >>> > | sprintf(hi=2Edata=2Emodename, "%sclk,%smodem,fclk=3D%d,bps= =3D%d%s", >>> > | bc->cfg=2Eintclk ? "int" : "ext", >>> > | bc->cfg=2Eextmodem ? "ext" : "int", bc->cfg=2Efclk, = bc->cfg=2Ebps, >>> > | bc->cfg=2Eloopback ? ",loopback" : ""); >>> >=20 >>> > Note that this data is copied out to userspace with: >>> > | if (copy_to_user(data, &hi, sizeof(hi))) >>> > =2E=2E=2E however, the data was also copied FROM the user here: >>> > | if (copy_from_user(&hi, data, sizeof(hi))) >>>=20 >>> Thanks Justin, >>>=20 >>> I see that too=2E >>>=20 >>> 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=2E >>>=20 >> >>It's kind of normal to pass user space data back to itself=2E We >>generally only worry about info leaks=2E > >True but since this used to zero the rest of the buffet, let's just keep = that behavior and use strscpy_pad()=2E I'm calling all byte arrays a "buffet" from now on=2E ;) --=20 Kees Cook