Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2031840rdg; Sun, 15 Oct 2023 08:06:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEp9QmIdC5hmQoKxuri6wLup48ZEsMLWLVjG1XR8ynQhUsp02nggYsbbI9mVI6KX/+iFlLO X-Received: by 2002:a05:6a21:a58d:b0:132:ff57:7fab with SMTP id gd13-20020a056a21a58d00b00132ff577fabmr42406396pzc.2.1697382401514; Sun, 15 Oct 2023 08:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697382401; cv=none; d=google.com; s=arc-20160816; b=wohtIZTrY8abOAvUphqTQbX0xW1R0NqEli7+5czy4bGHF/skxPq3tFHhQ7pz8kBLqG ji0zELGXVhPp48GR/sydInaRYfZQelzO61GA1Kv5eyXzLgxbR8ID3IKwWNobrWyzDexs WlH3iar2QO747ZuTjb4J3TAGZ+ftPvxmxO5J/mZbR4tjHbqkY5Yeg4JPGS90lW4DLR2A w6H3Nk7diwtcJSSyJiFsKOLzsdN8VUsTag6yJgKKn2uO2qCSnFYXZRZ/PWlANB/wki0/ 0hIuG42yb51kS7qgmIuVd0kuGokb/1oS07Jk53voCDM+J/0VXb9Bo3PY71VcugZw58ER krwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=t3ac5d/j7zy/hXNb3HAAnF8QY4jZaN0fokUR3V3I2y8=; fh=bvNIF4Gcb6CASXFKIR7uS8PFj77vDBu+VFfmy85Ako0=; b=z7RNKqvLg9Pg+fg3/3wykC/2N9ArsfkHI6wwxRFJHHHvskqGU+B7Wt3xC22JOadGKt ztfzes1UqlpzZTU0SakxoJa7m3v+qYPPn26/4v7vjH9wiUrXABrNGMAmLvE9qnOBtcM3 v/zFlJVQ8RJqKxj9id/1zxIaxhXuUpoqdlkjZnaKsboIL5wpTujpCLdnVn6X+Xuo8lRv +PyLNZKrMCCOswtVEar6X+UTVZo/nAnjQ3c7rIi2hCj+uzzkc5UP4wX7tQA1XMsK30gp ycJz3RCbnM+Cjbt0USk5cOt61+2otpm1wQnzUK4/eN+hd0UeXnOHdMf+SVkcYCAXf0EJ M0Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KmPkmpkk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id j2-20020a170902da8200b001c8920e3021si9333180plx.539.2023.10.15.08.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 08:06:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KmPkmpkk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 8457C80A7E66; Sun, 15 Oct 2023 08:06:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbjJOPG1 (ORCPT + 99 others); Sun, 15 Oct 2023 11:06:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjJOPGZ (ORCPT ); Sun, 15 Oct 2023 11:06:25 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98317DA; Sun, 15 Oct 2023 08:06:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 201E7C433C8; Sun, 15 Oct 2023 15:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697382384; bh=VFgG/GeOFjZBpWQhFBCt12gjtE4bL5QgGojqf6ykkEg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KmPkmpkk8dxofiw/rBxB87ue0PkE1wqtTN/hWDFuBD6+kgyN/F2bsPnDK5VssS0yW YczAhfcBOERdXnuB/NGwNdLd6upUPdXPfNdbVve3NwXWxqvwOk8O4yGbiw2sDA3Fnv FuBYJNZsSjkTgOG1i8r6dpaEbHjIgl9gh4EMG53XP4fbCotfhaR5wKyPpW9xY+fmD7 Ya7VX+o7Xi55Q7B89miEkxf9k27VUdfQPm0juny7V7zmWyPNcX1o/mUU0ABKV2KPfm faUxYFIBv5vED/iwT9jvC/CmAlSR1k0l2SdVaq2F8jXIhymnA+RHd1q7CFVKlWN3Z9 7j4SGgGJgAy/g== Date: Sun, 15 Oct 2023 17:06:19 +0200 From: Simon Horman To: Justin Stitt Cc: 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 Message-ID: <20231015150619.GC1386676@kernel.org> References: <20231012-strncpy-drivers-net-hamradio-baycom_epp-c-v1-1-8f4097538ee4@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231012-strncpy-drivers-net-hamradio-baycom_epp-c-v1-1-8f4097538ee4@google.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 (snail.vger.email [0.0.0.0]); Sun, 15 Oct 2023 08:06:40 -0700 (PDT) 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. > 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. > > 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 ...