Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2485139rdb; Fri, 8 Dec 2023 09:23:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1BTm/XnVh3ePRcsw+7qSQnJ9QVxhCH/VL6dxWSF7AL7O68fuYrDprIltGbzdbfdtRGv67 X-Received: by 2002:a05:6a00:14c6:b0:6ce:57f2:45fa with SMTP id w6-20020a056a0014c600b006ce57f245famr359560pfu.49.1702056210128; Fri, 08 Dec 2023 09:23:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702056210; cv=none; d=google.com; s=arc-20160816; b=GoQPkpxfZtY4Om29uxxdAeEa+ojwVpcXKYisuWwvQL6PVGmR3R2ZxxXYG0KwXRS/oH p0pv/71VMYK9zTsVliPGzJJ25XojfsPkqgxdm43JCCosQJmQoAF1MSq7Lyv0us4df38t VBSf5wpLw9085eJR6iKaoxV4lBsoPlL+vGj/R1AieX/HbnruPRTT0poJNj244XvmvkH+ hub/2Lk1GPn8i5ooX8rg27bx2KzgRA3300BefqyJyPek5rPIjFNdViBhcaF4DPIZx+SP o001303mdFPOGMnGsxvpE0HlXa+/WLKI9dWa0SeB68IA0yBRZnZOR0vhOVWQpDp/n7pa gFPw== 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=WNXDom1pGgFzD7z60+nX5wKE72JYAG4paS5sk2JCKg8=; fh=BQB6Vgp4iqwSyIkjMglIvMYFPTP9uApxB/uzuqgOagw=; b=gGKGbjFEydhT2VtNs7DTlvXrroO+inxEtfW9eRnjWPLFChIlv3EkzbcrcTcdAO0wjI bNglrT1Cvk2BtEMez+5Wu8qLbBHM8GbnoHgVcjef/TmB7DLpGe5aE4cYHjXk4qrRSqWo KamSN7CXOMqI3yFu1CH/eVmfMhtwA7H17mL2RxKSX+k5qRCC6fX/rQxDZtnDoY7cyIMA u45c348jt8PPDgjPUtoKqNR6bf472XDR7MbRM6Xavw74G7dBd8mj7vmPHVl9BX1O1n0Y 6QsMpsuzj1KTfoLMbUQA5Nti7epPZHksurJwxaEiTTxPabWSd8Z4oWU+uko9bAQXJWxu WFjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="GiY1k/0d"; 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 p125-20020a634283000000b005c6676349ffsi1760834pga.613.2023.12.08.09.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 09:23:30 -0800 (PST) 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="GiY1k/0d"; 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 5C0528116329; Fri, 8 Dec 2023 09:23:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233788AbjLHRXI (ORCPT + 99 others); Fri, 8 Dec 2023 12:23:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233514AbjLHRW5 (ORCPT ); Fri, 8 Dec 2023 12:22:57 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52F7C199B for ; Fri, 8 Dec 2023 09:23:02 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6ce93552cb5so1606266b3a.3 for ; Fri, 08 Dec 2023 09:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702056182; x=1702660982; 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=WNXDom1pGgFzD7z60+nX5wKE72JYAG4paS5sk2JCKg8=; b=GiY1k/0deCp31KIS/rscp6m71yTNYUEL+kB1zQ9qcDADBj76CBBvx96QLXr4UQf3Nf OYdJGf3XPP7YZoJg1Y2dC9/qVCN1IkX0g2Hy5/Ly98HxRGmVzHiV8Jv+CrND1k4IBlBo +AGAJa6nLkIv8JFMTzIl0elnYLMdooCku0EdA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702056182; x=1702660982; 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=WNXDom1pGgFzD7z60+nX5wKE72JYAG4paS5sk2JCKg8=; b=BTZAaTUrk6GcbguC4sQPBmTF/8ytyMLOl3lnRc+SugFyU/7NOfBOs7b6si4Vwn18sW O6M2u8RUNj6Sh8geJxuLKcpo2UxpYRvaJTdJIvKYEw8MyU0c3Pf9OZB3967Z/61eUz1n MQIZ6HgCAj42vQKGME2wjWEKDwRyk7MGcTyvbbuyMgbic6l9DI6FTvbyCj8Snf42NKqw WJ+puop4NJLhkpuZap36s3TG42Eo3JJBOzwWtYILktq2lZkAgOkxP9X7BistYxYBJKF0 tWCZWKorSurw/JHZU4Xn9lrDwRRcyhgwszhalz7Ub/gCNrEHH42OVy9QTieQlbVtdZjS gdGA== X-Gm-Message-State: AOJu0Ywq19TwDVIkPO3n1aXh8DwaM5lYJ2E37n5ad2dB9bRanWtzkkbA ieq7z6dQY45EQtNAur9EEowjOg== X-Received: by 2002:a05:6a00:1a8f:b0:6ce:50b4:a21 with SMTP id e15-20020a056a001a8f00b006ce50b40a21mr321026pfv.27.1702056181771; Fri, 08 Dec 2023 09:23:01 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id u3-20020a056a00098300b006ce7fb8f59csm1837731pfg.32.2023.12.08.09.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 09:23:00 -0800 (PST) Date: Fri, 8 Dec 2023 09:22:55 -0800 From: Kees Cook To: justinstitt@google.com Cc: Shay Agroskin , Arthur Kiyanovski , David Arinzon , Noam Dagan , Saeed Bishara , "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] net: ena: replace deprecated strncpy with strscpy Message-ID: <202312080922.881A1515F3@keescook> References: <20231207-strncpy-drivers-net-ethernet-amazon-ena-ena_netdev-c-v2-1-a1f2893d1b70@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231207-strncpy-drivers-net-ethernet-amazon-ena-ena_netdev-c-v2-1-a1f2893d1b70@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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Fri, 08 Dec 2023 09:23:27 -0800 (PST) On Thu, Dec 07, 2023 at 09:34:42PM +0000, justinstitt@google.com 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. > > A suitable replacement is `strscpy` [2] due to the fact that it > guarantees NUL-termination on the destination buffer without > unnecessarily NUL-padding. > > host_info allocation is done in ena_com_allocate_host_info() via > dma_alloc_coherent() and is not zero initialized by alloc_etherdev_mq(). > > However zero initialization of the destination doesn't matter in this case, > because strscpy() guarantees a NULL termination. > > 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 Yeah, this reads much better. Reviewed-by: Kees Cook -- Kees Cook