Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2485508rdb; Fri, 8 Dec 2023 09:24:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBJ3Sg2XO8a1m0rYLoCvjt3V+OF15uVyDfgP7hi++VDy7NInipF5J9yROZItOrY4mdC4Zf X-Received: by 2002:a17:902:e789:b0:1d0:5567:5c75 with SMTP id cp9-20020a170902e78900b001d055675c75mr335519plb.66.1702056250009; Fri, 08 Dec 2023 09:24:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702056249; cv=none; d=google.com; s=arc-20160816; b=s+5AkeHXNCMrMovQFFz9sRsBzsB1swaqli+ZgqZ/P9Zz92H4Dl/26+8/gtLoySTo2d jZLo4EKybHw3J2iYi4NRO0XlAHh+v9vxyJ8wzrMoinwaimtRPAc8W4WggIrjLbG/yA5z 7zUvw2jDOhiyk19MiRaNl7pHM8fM7IKrG8UHOAYXDqGHfwI9kOrkbcfCKMGZJMp+Gr9J ioxvdXtBFi2844M97k63zfQlEeEtBhZFlJTU8EcZIjV8+6dPBIpzoOtlxMGG+u55SIWo jrxcuAc9EQEBTvXR++8ZzmOyiU6o3MdtQv0XoMB8MA9AS8VaQiYpva8Wc3vvidAmKr0d LaTw== 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=cfBRrQiDkLBq4kbSWxx91dS9hun2XcIUpOw4uVoRhJU=; fh=IoFRKyVlUXDl9l2V+xHVBV/3U3Y1ckVX4s1qog+Dw0g=; b=o8iQOcv+uRYNMKpVh46zpvVuBpeCpJWZa0JppZoz0yMqhgnkj95TQOJiwKJeIneTAU v1wXIWEXozjHJQjUa9TuA7YgedkX625X4YlhpgSNpk6ZX0FXLMGhssmNXBirTRFxK7xt 72hI3TGn9K8xdMC7OlAUSxTygKAT2Vy1bIegJw3w1Uh/43XpK4mQW//DPegZ3Ytvg6Kg uDiDccQDKpwqQzBjBrNfPxtlbTJMdP4+OUayXLUZ/OG3lTtXGLMS22kgrTjioOWoqvcz Dr0f8MDSU+5UokmRwtBZgB6HXTjIUePfCGV6lGHAxOznJoZ3ENND9bt3TRboLigWtSa6 15xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bjVfEERi; 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 i1-20020a17090332c100b001d0259167f4si1919656plr.287.2023.12.08.09.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 09:24:09 -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=bjVfEERi; 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 15DB18116336; Fri, 8 Dec 2023 09:24:06 -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 S233743AbjLHRXu (ORCPT + 99 others); Fri, 8 Dec 2023 12:23:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233782AbjLHRXq (ORCPT ); Fri, 8 Dec 2023 12:23:46 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76871D54 for ; Fri, 8 Dec 2023 09:23:53 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1d2f1cecf89so4676185ad.1 for ; Fri, 08 Dec 2023 09:23:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702056233; x=1702661033; 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=cfBRrQiDkLBq4kbSWxx91dS9hun2XcIUpOw4uVoRhJU=; b=bjVfEERimN0gSZtQLetYbKdUOJykosXkQPNL+eoZeNSL9d0ZwIVoOMJPSWH5SRPuDz iSEEcn802Dqb0TzwNCcOVkE2pjAy5pujXmgfRRA96KSSETfRdA9Ss/3Hrz0bGPsCqkXi FcBqLB5j4QvlAIgKbsiIXvzhKFn4hpcwUU96g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702056233; x=1702661033; 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=cfBRrQiDkLBq4kbSWxx91dS9hun2XcIUpOw4uVoRhJU=; b=OnjeV5kYZ4IObXR67kOInxrrmMVREFyxhxL8ZADNMpuBjNiJ9r7LfnNr6plrByzw46 3TTSru3Wswye2io4EPM/jVfNio260DJ97tKwREThVEvH28PudgUmSiZ9Tl0e6/qbVC52 1XO7oau3wDfYGYgDB8I3RnuNz84Lsj/TgeVPzm7sAMC2+W48LY7OD5tuQAOVKU5R59Te LRIQ1+uZLeDGvWp67RC5SJlbu4LKS3+smzjPbWa2hb4a4rcwtVjx7X4irefSsqBgXPoO FFHk29GhcLXE+2p3gQJDnUjT59+BlyBb0+YIH/u+BnriyjQv0ZesE026SJQoiIR4nOfU rHFg== X-Gm-Message-State: AOJu0YwYS2P6FbnnXHy6c+bEe+fxtwooReJx2rIm68ggntZKMyQBso/H dORU5jpJRa/Tn+yPjzjKL0OMlA== X-Received: by 2002:a17:902:ab01:b0:1d0:c738:73b5 with SMTP id ik1-20020a170902ab0100b001d0c73873b5mr325670plb.0.1702056232945; Fri, 08 Dec 2023 09:23:52 -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 p18-20020a170902ead200b001d053ec1992sm1961580pld.83.2023.12.08.09.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 09:23:52 -0800 (PST) Date: Fri, 8 Dec 2023 09:23:51 -0800 From: Kees Cook To: Justin Stitt Cc: Andrew Lunn , Heiner Kallweit , Russell King , "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: mdio_bus: replace deprecated strncpy with strscpy Message-ID: <202312080923.7F537BE03D@keescook> References: <20231207-strncpy-drivers-net-phy-mdio_bus-c-v2-1-fbe941fff345@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231207-strncpy-drivers-net-phy-mdio_bus-c-v2-1-fbe941fff345@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:24:06 -0800 (PST) On Thu, Dec 07, 2023 at 09:57:50PM +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 mdiodev->modalias to be NUL-terminated based on its usage with > strcmp(): > | return strcmp(mdiodev->modalias, drv->name) == 0; > > Moreover, mdiodev->modalias is already zero-allocated: > | mdiodev = kzalloc(sizeof(*mdiodev), GFP_KERNEL); > ... which means the NUL-padding strncpy provides is not necessary. > > Considering the above, a suitable replacement is `strscpy` [2] due to > the fact that it guarantees NUL-termination on the destination buffer > without unnecessarily NUL-padding. > > 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, the subject is distinct now. :) Reviewed-by: Kees Cook -- Kees Cook