Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2111017rdb; Mon, 9 Oct 2023 12:58:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFp3GTW5S18/+I85dkC5gUWKu4f+GlEO2yfsoyn8mRsJ+372luCShtyJhy3b78gcIHLdMmj X-Received: by 2002:a05:6870:6390:b0:1d6:5892:d279 with SMTP id t16-20020a056870639000b001d65892d279mr19687994oap.3.1696881528298; Mon, 09 Oct 2023 12:58:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696881528; cv=none; d=google.com; s=arc-20160816; b=jS06Qqkl5m5uA/HYdsuCs4UnkMi3zpXBLa5NCuTkS1EB60sL6747wg4GZ1EfOdsbI2 xTO0GNYb25D9R9oizXe2w3lGq0zs3K5c435DuPYLoWRDJek/VWqLr13GupnriIWSFREO LP42kIq2bhLftGG2M9rQj0yFdwvZ57YP1tz62GuBJLHAfVatazsJ+cqtTovX4zsKolVe i83U7IGRZQF8mOfdM9FH4QhmAu6MSKSkZrKxpCty08r893a7qUQDPIM7+eveiUjqs6O8 /MEq3pciI4p0FKhuVZY3O9wtTNi7M5tDk2QIPH9l0c58vrg7omMooc5Wj7AUIkiJOvq0 erRA== 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=KLuHSTvxz6vkfDxRZ/vqO8f0OQyjGiohBBwWRgjVl/4=; fh=pdn22mWdiQ9VXuWGBr7SubX57F54BbEJIwoOBIgG8i8=; b=D01AGtddMqPOG2ykAJfHVwzliz8CvBvv2LlJMT5GIW8foQhoLnieVKZ9xecYpmON8E DpvMN+Cdfo5SwBzSN+Yi6EKvbUf44f75nZHKIpVJLdS6oDH8V1603EDIRqxNmPCOESkw 3BMo1e6uqtDAldWmfc5yH1tJLGfpkaIjWZaTHMCIu2Flh0cYPdpDyQixbvshAXi8fLzr wSJSbMl3t8QEBcAdr2fKlJIX9br10Ct4hS8X6ueH1vED+K2YoIgGA9MMmkRgxqx01PTJ JWO3itkezXcWbhDE5H7L/MNylkhdMOvQCqnDcORFCiu9HwQKdsgFW9+lBjT/yc2Ff1jv l1Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JNz0qgsY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id be11-20020a056a001f0b00b0068beea8071esi7759132pfb.221.2023.10.09.12.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 12:58:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JNz0qgsY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id DEEE18082DF9; Mon, 9 Oct 2023 12:58:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378491AbjJIT6i (ORCPT + 99 others); Mon, 9 Oct 2023 15:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377401AbjJIT6g (ORCPT ); Mon, 9 Oct 2023 15:58:36 -0400 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9486594 for ; Mon, 9 Oct 2023 12:58:35 -0700 (PDT) Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3ae2ec1a222so3465151b6e.2 for ; Mon, 09 Oct 2023 12:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696881515; x=1697486315; 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=KLuHSTvxz6vkfDxRZ/vqO8f0OQyjGiohBBwWRgjVl/4=; b=JNz0qgsYuK3TBnHTDPh/Cc8uro9vD0eEaeoje+InVGLUF7ebq4oIiwWPlHW3hBV6cm K5bjjD0d0TKKi4kyiXF6pWHhu2v34gR6/+gzFX/pBfEXU1HoIc/8oqKMyQop8Mjq+knU ND32KrXG51kEUrvqVOwSZmwbIrEJiBpaWMGa0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696881515; x=1697486315; 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=KLuHSTvxz6vkfDxRZ/vqO8f0OQyjGiohBBwWRgjVl/4=; b=kC74SGreQNc9/niKNDrrnTBOtNBpPtr/rZ5rOTBjNPXVA46+DVShBvrToPpmmIZunB iKCs5PVxLEv1NSy6sDx3ZtgyB/h9IsIkPKam697LPltT2HUN8Xw77JNhAMEUIYe2LcBs 0EPyBuEEssLhMyBQZAbsR2yr27AgHT+YeDIm1RdeX0CVLOLaedFt1LP0qbuiRyTNw/+t pXq09UtnekJfSoGlK0TbhL/I4cYHqaRbS8hKj1COv1LA4aAbGOQcsnFTtSXVioshhkMu orFSu0pWZcgM6k/xU7WWxWX8DimJaIlQQUZP2HeCbJzYdJ0A2BIFe0pbQZvaFUjKDEYz jnPA== X-Gm-Message-State: AOJu0YxLcqJfl6d0eEoC7BdXZQvMhwxaPXSXnRV7/xXD2iKK3qhBd1YC 5Ab/bGQ8OfwPVbRrMOEjzgYYmg== X-Received: by 2002:a05:6808:2d6:b0:3a7:3988:87ee with SMTP id a22-20020a05680802d600b003a7398887eemr16427801oid.58.1696881514875; Mon, 09 Oct 2023 12:58:34 -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 i6-20020a633c46000000b0058563287aedsm8906706pgn.72.2023.10.09.12.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 12:58:34 -0700 (PDT) Date: Mon, 9 Oct 2023 12:58:32 -0700 From: Kees Cook To: Justin Stitt Cc: Rasesh Mody , Sudarsana Kalluru , GR-Linux-NIC-Dev@marvell.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] bna: replace deprecated strncpy with strscpy_pad Message-ID: <202310091258.C4CDBBED7D@keescook> References: <20231009-strncpy-drivers-net-ethernet-brocade-bna-bfa_ioc-c-v2-1-78e0f47985d3@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231009-strncpy-drivers-net-ethernet-brocade-bna-bfa_ioc-c-v2-1-78e0f47985d3@google.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 09 Oct 2023 12:58:46 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 09, 2023 at 05:45:33PM +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. > > bfa_ioc_get_adapter_manufacturer() simply copies a string literal into > `manufacturer`. > > Another implementation of bfa_ioc_get_adapter_manufacturer() from > drivers/scsi/bfa/bfa_ioc.c uses memset + strscpy: > | void > | bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer) > | { > | memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN); > | strscpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); > | } > > Let's use `strscpy_pad` to eliminate some redundant work while still > NUL-terminating and NUL-padding the destination buffer. > > 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 for the update! Yeah, this looks safe to me now. Reviewed-by: Kees Cook -- Kees Cook