Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4422011rdb; Fri, 15 Sep 2023 01:21:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9a1iS+SCsg/ggcu5Jw81nYUHj0ZrUAGAO1C0K+qiES4PlZ/zu/kLWm3fFfxTHMC8HWeEK X-Received: by 2002:a17:903:32cd:b0:1c4:1343:8329 with SMTP id i13-20020a17090332cd00b001c413438329mr1159497plr.27.1694766115401; Fri, 15 Sep 2023 01:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694766115; cv=none; d=google.com; s=arc-20160816; b=ArB4EpD3s0Sr7uOd5F9QLqDJurp3cA3DjbxvEn6RJPPNorHUIZQgGNwQU8iRMcXA08 079ICfdFU5KauAthGeaC4X2jg4ad0NiiYxbQRZCsbuqP4UomPAYkUFOQX6cqeL+4RVA9 jpG1MKOt5jmWdFU6iikhGYvOC6VXFTuMN/NLEaMzkzSjaihLH4vSTSS6TFF8cVTlHLfH uPTxzn9ZATTPY15709Z8wzqsYGArlmZT73ZrYsQejWWlnS7y6hl+sa6lBZflv3O+onpb XRJ5vKxmltSP/sEV2siIGbrfolqssisexoBd674PSkYT1dWtH3XvMulofsZ2wwOkGTMc 1CDQ== 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=dSXFfyqgPwKVqMylZWaZxOwMkCRZt/DukldIcyDr7/Q=; fh=oRrAhsDK4D6LbuCFrJTVrASQDPpF9dyimmDWBPH7wSM=; b=QSi1dq29IS3CCr7ySuozzusMs28MfibqtCLYDNHBK34VC2gH5sKjWgzOWGiZM6G4nW pcZmQi/XVafYKOxOrJBqFvvrv6bzgfq70WpAr9ior9ZMKXSzvxyv/x1esuXLl94FXENS wiMT1I3sC4OD+UKBQ6AA8LLuVGrIO1bWl3CRNcC+x5w7VxEblS27A0lCpatc/ppfT6KV oEHZiSPFtmNqUcOG4nSA8b7Yux4CCnXirDb6/FZnjtW/BK4fr4V4lHaP6h7/meEROSQW zjbHkmw3xKV8uCP4HQp8BjsMTCGcnTEcGVjRCWUUrMcCvoA1djI0MZ1N/jLQJ2Hb1jcw GQ6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OLrBWk+H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id l15-20020a170902f68f00b001c4376ceadfsi519178plg.615.2023.09.15.01.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 01:21:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OLrBWk+H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 23C3F8344A01; Thu, 14 Sep 2023 21:01:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229554AbjIOEBH (ORCPT + 99 others); Fri, 15 Sep 2023 00:01:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbjIOEBF (ORCPT ); Fri, 15 Sep 2023 00:01:05 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB39F269D for ; Thu, 14 Sep 2023 21:00:59 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c328b53aeaso14505765ad.2 for ; Thu, 14 Sep 2023 21:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694750459; x=1695355259; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=dSXFfyqgPwKVqMylZWaZxOwMkCRZt/DukldIcyDr7/Q=; b=OLrBWk+HHUIEagXG9HPi9FmVAexOREXK8DbV4Qa9njdBrjDNZ5qiM3QaBAAGlZqgUS 84DVS843GER+iS3+9N1WMDQKv7VVywrngGQG/KZnAFFXGXI41pMQih2gh4yqU3fyWnWw vtPQ71EdCJ1HBaCHm/K6UabYgv+1faZsGG8Jc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694750459; x=1695355259; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=dSXFfyqgPwKVqMylZWaZxOwMkCRZt/DukldIcyDr7/Q=; b=b/SKfL3rvAguKR5Z2UrukxTbpGyr1cCRzPO6WsAfWaTr5CEsLZuiRPDh114pX1kAtY HwkHyaP1FGxmbP6crOEWzdKcpeyaQkcBJcau1vWoZEQS8zOleQ7g96ltiG2liJdTg3q8 xTomITc8TKkcTIVu+V0p6sDscdCZ3jITDaqzCFlmnj6F9T38jMJ75TiEKjjCxbCLhNEr tOKfPuRZU8wfRhwm9dzkB7Iuu/bHHGIr8+VYTs1LqBuajqSxiRrB5lKRpM6Femb7IC65 Ujl93S6JfnkV62yxLZ/zlWrr1gk54KBxUUh0usdoMFwd0+SYOPIRJAmjqwuqqMtY46x4 /4nw== X-Gm-Message-State: AOJu0YyN0tJz5fu00ZgudhJi9FyDfl8I6/6wbr8UIO64EUb8jOs+nMGI ivO4vgWRmNvmKV8DcSWf2e+Q1g== X-Received: by 2002:a17:903:2302:b0:1c0:afdb:1e6c with SMTP id d2-20020a170903230200b001c0afdb1e6cmr691210plh.8.1694750459263; Thu, 14 Sep 2023 21:00:59 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id jb4-20020a170903258400b001c0cb2aa2easm2350777plb.121.2023.09.14.21.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 21:00:58 -0700 (PDT) Date: Thu, 14 Sep 2023 21:00:57 -0700 From: Kees Cook To: Justin Stitt Cc: Thierry Reding , Jonathan Hunter , linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] firmware: tegra: bpmp: refactor deprecated strncpy Message-ID: <202309142054.8D93862@keescook> References: <20230913-strncpy-drivers-firmware-tegra-bpmp-debugfs-c-v1-1-828b0a8914b5@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230913-strncpy-drivers-firmware-tegra-bpmp-debugfs-c-v1-1-828b0a8914b5@google.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 14 Sep 2023 21:01:13 -0700 (PDT) On Wed, Sep 13, 2023 at 07:38:44PM +0000, Justin Stitt wrote: > `strncpy` is deprecated for use on NUL-terminated destination strings [1]. > > We should prefer more robust and less ambiguous string interfaces. > > It seems like the filename stored at `namevirt` is expected to be > NUL-terminated. This took me a bit to establish, but yes: buf[256] is used to store filename, so it'll always be %NUL-terminated with the 256 bytes, which is the same size used to allocate virtname, which means it will always be %NUL-terminated. > > A suitable replacement is `strscpy_pad` due to the fact that it > guarantees NUL-termination on the destination buffer whilst maintaining > the NUL-padding behavior that strncpy provides. > > 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 This one looks weird because namevirt seems unused, but I assume there's some kind of DMA side-effect happening somewhere? But, yes, after digging around here, I think this all looks right. Reviewed-by: Kees Cook -- Kees Cook