Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2727717rdg; Mon, 16 Oct 2023 12:58:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF64nrzqsaCXxtwZm9ZXdFDYLXO2lSh9+q7cnVFIQvwruJDW0tyRTf8Gk31giRIHv1ehd6+ X-Received: by 2002:a05:6a00:1516:b0:68f:dcc1:4bef with SMTP id q22-20020a056a00151600b0068fdcc14befmr232369pfu.7.1697486328345; Mon, 16 Oct 2023 12:58:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697486328; cv=none; d=google.com; s=arc-20160816; b=s/llyE/dNqmJ07rvqmtBPYyfIBezBoTLiUHz7LmJx1DYKyM3+lOdv8FF9OOFBQ0j9G /jY+cjz85Ieba2SY8nc1azHyDBYf1RU08EMTjZTLcMY/nMmd5X6hBmftmlnvDnk7auAA 9+PMz2y58Cm25LUHpVy7Yfg6qsLT6OcRUqt7SWGVsyoSQEjXtQVocRhd/wIlVImj+5To d4ErsW5p23gfXoWsBjZgL6lna5w635bYPHAZxfx2KkLkbDrkM9rE0fbAr8r1i8pRN6w7 q+YMJZ0mSIBFjyvdEJEH7z7iGTE+Mtzc19jrt4Id+97gPCmTTuafn3JAllDK/o3DDKm+ OOFA== 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=opn5qghDBcSJ6deRaUic/NeDyIoAO0RNKTQq1liYZb8=; fh=YkvbC0AZLuGU+o7ra2MP5zBU+/07f9Cb5NDegcgYaKM=; b=yd925OIw5ovECP+VXV1D8pVgtg5VM5zdQy0yu9BqDsU6O8YOerH11fg2SOE6YkA/fg Ht33Qpa7w60btcmDG2ZXm29h52RD59XW5xNdnEM5NpSFnHNOE0Zn6v340VL2juY/T+Nh xeO+xS2LAJ1PPjD5epnluaudAdPDbbAkJX9yK4YmI0Sn6L/hl/ca8MlkqTpNV+wZCxWI 4R9YYSZvEsAejXYen8bdspR5h0kRAYensoApTzffkMf2ru9X2PQB4w+2pRD9cxIRSJey vgxk3QoBsLb2yATJ0LXpjaj2c6qwXDO9NxDB8HGJW4mIS+0PrCJsZrbB418MFqMmL34I imoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FX6MQtvL; 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 g5-20020a63b145000000b005acc951c57esi34682pgp.526.2023.10.16.12.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 12:58:48 -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=FX6MQtvL; 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 E48128029C60; Mon, 16 Oct 2023 12:58:46 -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 S233871AbjJPT6p (ORCPT + 99 others); Mon, 16 Oct 2023 15:58:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232996AbjJPT6o (ORCPT ); Mon, 16 Oct 2023 15:58:44 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47D0CB0; Mon, 16 Oct 2023 12:58:42 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B660BC433C8; Mon, 16 Oct 2023 19:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697486321; bh=QJt2FjmAOk4+5+b+Cj8Y/yCy8j4cnH5smrJ3zqV3En4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FX6MQtvL92gviz8tSxWSfFL5w4oPc6M/5NeJ4RfP2w0ZjzCQNmfkcliOrohxxdXRu mGf7jkY+Qp5+gnHnuKwnfGIOb/LYqvb7lLStTNsS5gmREJuEkVMPP5zE9qKJqsXX+h fjP+2hFDYTIHs2Fkw5mxJ65yjcMcMJbItI+s02EDjyW8kghqpS03VNdQ5OMrWCydCP DmUI2rWd5/7TberVoCzCL9sZYaaHCgCWWyq/OrrxP/rjg3kR5kWZSdhIeH2na82psT jkfMsfUdXTGz7eb7AIk0Aj2tV/3myWkuU/HPgTAkuVs5YQVN0or+J4/5Jzjq50e9bI O5EYsKIjUxeyw== Date: Mon, 16 Oct 2023 21:58:36 +0200 From: Simon Horman To: Kees Cook 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 v2] hamradio: replace deprecated strncpy with strscpy_pad Message-ID: <20231016195836.GB1751252@kernel.org> References: <20231016-strncpy-drivers-net-hamradio-baycom_epp-c-v2-1-39f72a72de30@google.com> <202310161242.B0F9B693@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202310161242.B0F9B693@keescook> 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]); Mon, 16 Oct 2023 12:58:47 -0700 (PDT) On Mon, Oct 16, 2023 at 12:42:22PM -0700, Kees Cook wrote: > On Mon, Oct 16, 2023 at 06:42:42PM +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 based on 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))) > > > > Considering the above, a suitable replacement is strscpy_pad() as it > > guarantees NUL-termination on the destination buffer while also > > NUL-padding (which is good+wanted behavior when copying data to > > userspace). > > > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > > Link: https://github.com/KSPP/linux/issues/90 > > Cc: linux-hardening@vger.kernel.org > > Signed-off-by: Justin Stitt > > Thanks! > > Reviewed-by: Kees Cook Likewise, thanks. I prefer this over v1. Reviewed-by: Simon Horman