Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp483671rdh; Sat, 23 Sep 2023 21:24:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGdML86/Y76TT1M848/cCBKevWTrih+KPRVOl8aMWa3Ola5qGB7l4xsYerGGN+bFWtBX1s X-Received: by 2002:a05:6870:2d5:b0:1c0:5f7a:896f with SMTP id r21-20020a05687002d500b001c05f7a896fmr3832941oaf.8.1695529446696; Sat, 23 Sep 2023 21:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695529446; cv=none; d=google.com; s=arc-20160816; b=EaWtAC6jR2baRGW6GJG+ez9gYXrRNeIF+Tu6AdmguaTfZfrBaMa8kS6Oj4IZPIkTM4 vcypbIVfCf5dbrSVXkql6MIuLkNpVc/sKegaPxYBxWpczqmufQ5Ph1qRhPAds9U4wrEj SgGCpGg3czxCkGph1rWSnVIn9flW3SV2BDX8rXy2N+mvVAcwPexhMFsIbm7kiIzcHSyF XvdGHqhwSBnI3N50eOFPCC+ieplbq4B5mfEjFkinrfow4mU1PCKJisadprSBvAWlzEbP 2d1ZEmvvTeZn31JtY5vGryzi+NoKuHQmzyrBh6QBqIoM5Fee6D1KYgwdZCBhruYZd3y9 +/dA== 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=Vm7SCjjGy1Czz0oUxMb12CgrgnjC7R0vO3/WEnyLchc=; fh=Zmnz3APWHps52r7yicvGbev+2h5ER7kbQfcIH+SvUrI=; b=gcof1oO6x2Plv04X2+1FKvUpO0hiS4z+2sOJi2mBACVFCg/4lcaYuPQDeiwLZP9g8k G2lF2vD90rMDk530Hi8mmcOLF5TlT4i8twCzvnSf7tWoHpTeDeC72hF4NzXQF+Jc+kQq 9nJkUQCTHZi/VQ4tVcCpnSadzseya6DbvyI4EJFtAX1VRZRsSRZMTOuP5JC3AxYUZSHB 0JJ7Iq8nMDUbY0Sp6o5INcT5pvsQHvQcYELSIhpEukv0t3vhGk/yG+QHmSrHtJjX4MFZ Hr7qUJ4PUnO9StzMAZBLz9UVTbpfUdwvXGVqTh3vaGOBWygAEZFPBA9DzyiwF//LhT9Z aSpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nnMWdjCM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id 144-20020a630096000000b005780b4905f1si7211899pga.460.2023.09.23.21.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 21:24:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nnMWdjCM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id E2A5180C7AFA; Sat, 23 Sep 2023 20:21:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbjIXDVE (ORCPT + 99 others); Sat, 23 Sep 2023 23:21:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbjIXDVC (ORCPT ); Sat, 23 Sep 2023 23:21:02 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1C6A136 for ; Sat, 23 Sep 2023 20:20:55 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c46b30a1ceso38283935ad.3 for ; Sat, 23 Sep 2023 20:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695525655; x=1696130455; 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=Vm7SCjjGy1Czz0oUxMb12CgrgnjC7R0vO3/WEnyLchc=; b=nnMWdjCMIB1XJ7/J5zhYC2iOXRCSPzJkNbPokyjM6/w1ON8c5NpFRHs6XmX0DheMSK 0eKC9bDoU3yogqLfAGT/5ymWdu72faS05bCtYgEkxc49u9PybwIuyk88IDx0YjgDQJaK 5ZdSZsitUR9UlwMBSwy9xPVIZZWgtha2YhZ3s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695525655; x=1696130455; 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=Vm7SCjjGy1Czz0oUxMb12CgrgnjC7R0vO3/WEnyLchc=; b=f41DgMgiNHMGaP1rnnnXKre8tqsH8S6rYAqoxcdQZaXYWLzJp4U31BelovYT1BfjN8 sigWze+YLhhvK1GiDM5Y4h+etQvYy9bGySRqdi6zRkdpFsDRn5gwt+FDfA2F+CHtSo8O 8XUgTjUcFaCAeCFHK0N756/JtjS0iCmv2qVp2mSNz0c1CpLjzqTWplCVAIslPIHi7lqL 9ARPblFHerMPLbpV4ftrZoR86TUsfMunl/Y4Q6w5YKmMWzqAVAHXgxisqNQnbZDMenKt Hvrc6Wjv+uW81eeN6hWxy+mJiAEFhIU8WrNJsEth4XsbXpIkkBIJj1uMv1ifOFMG2sC+ hOow== X-Gm-Message-State: AOJu0YzjbotHhFKh4YXq4O+4le93s9E+Ja6weQJk0aSR65RQS0U3Yb2I yuNh5hkysJ+ueQK2T8Krd2B+hg== X-Received: by 2002:a17:903:120a:b0:1c4:2641:7744 with SMTP id l10-20020a170903120a00b001c426417744mr4619036plh.25.1695525655440; Sat, 23 Sep 2023 20:20:55 -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 n11-20020a170902d2cb00b001c1f4edfb9csm6070846plc.173.2023.09.23.20.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 20:20:54 -0700 (PDT) Date: Sat, 23 Sep 2023 20:20:54 -0700 From: Kees Cook To: Dean Luick Cc: Leon Romanovsky , Dennis Dalessandro , Jason Gunthorpe , Justin Stitt , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] IB/hfi1: replace deprecated strncpy Message-ID: <202309232019.BE78A9C0@keescook> References: <20230921-strncpy-drivers-infiniband-hw-hfi1-chip-c-v1-1-37afcf4964d9@google.com> <169537858725.3339131.15264681410291677148.b4-ty@kernel.org> <2f4bd46c-664e-4253-8d57-16bd46dd3be8@cornelisnetworks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2f4bd46c-664e-4253-8d57-16bd46dd3be8@cornelisnetworks.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 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 (howler.vger.email [0.0.0.0]); Sat, 23 Sep 2023 20:21:13 -0700 (PDT) On Fri, Sep 22, 2023 at 09:25:39AM -0500, Dean Luick wrote: > On 9/22/2023 5:29 AM, Leon Romanovsky wrote: > > > > On Thu, 21 Sep 2023 07:17:47 +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 see that `buf` is expected to be NUL-terminated based on it's use > >> within a trace event wherein `is_misc_err_name` and `is_various_name` > >> map to `is_name` through `is_table`: > >> | TRACE_EVENT(hfi1_interrupt, > >> | TP_PROTO(struct hfi1_devdata *dd, const struct is_table *is_entry, > >> | int src), > >> | TP_ARGS(dd, is_entry, src), > >> | TP_STRUCT__entry(DD_DEV_ENTRY(dd) > >> | __array(char, buf, 64) > >> | __field(int, src) > >> | ), > >> | TP_fast_assign(DD_DEV_ASSIGN(dd); > >> | is_entry->is_name(__entry->buf, 64, > >> | src - is_entry->start); > >> | __entry->src = src; > >> | ), > >> | TP_printk("[%s] source: %s [%d]", __get_str(dev), __entry->buf, > >> | __entry->src) > >> | ); > >> > >> [...] > > > > Applied, thanks! > > It is unfortunate that this and the qib patch was accepted so quickly. The replacement is functionally correct. However, I was going to suggest using strscpy() since the return value is never looked at and all use cases only require a NUL-terminated string. Padding is not needed. Is the trace buffer already guaranteed to be zeroed? Since this is defined as a fixed-size string in the buffer, it made sense to me to be sure that the unused bytes were 0 before copying them to userspace. -Kees > > > > > [1/1] IB/hfi1: replace deprecated strncpy > > https://git.kernel.org/rdma/rdma/c/c2d0c5b28a77d5 > > > > Best regards, > > External recipient -- Kees Cook