Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp16977rdb; Wed, 18 Oct 2023 16:24:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENVLOMhwbzBlVgyGoPN0VzIrWep7nUE6//oiazk/tVCWYyDBHFJ8Hnpaa5Yn7RjV1Wz6mc X-Received: by 2002:a05:6870:5b31:b0:1e9:8699:d20c with SMTP id ds49-20020a0568705b3100b001e98699d20cmr641348oab.53.1697671458323; Wed, 18 Oct 2023 16:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697671458; cv=none; d=google.com; s=arc-20160816; b=t+Wc+PNUsT6HfWCktXJqStMNGvyWSByCzTDlkdOXyezBNIQtFHRSwyaK5QHNFYhvLC F/e63tyYHIYdaKXGqnJxAPMD7RY8q0wbAAkUZPRz0fGu/geW1WFD9vhrhugTSShnmV+r RRiY1PUw1I4YsTfFHHV+2VYAVv6tusbpJjVtjmFKTOArhLGDMIsGA4wXWH8lioqLqYGw rIIi1YRdMVTlwPVRSdneUQzTqyKM6C4WUaQE8WJYL3OiBbJcYfzFaWwm/TJ2x27GOUKm h8kOQv0fxGrnsIoHiP6XqoAEA6ML124ht6botrrtLsifMarhibRlYOuaf+05c3Ti0dgD xNsw== 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=Qnkqkc8e9j4DGQOzGoypqZ4/Iy9gsHg7tmNLbGbn02Y=; fh=IoFRKyVlUXDl9l2V+xHVBV/3U3Y1ckVX4s1qog+Dw0g=; b=vapOFVoRSVSr4BThjnatsOe7Dx/Npph2pdp9A4vpQgkR6F1qNd6FuOP3CPTC7EDSm6 nyWUfg9EcaBdFfYP4r68SSdGgf5rcfB7xF2qy3Z1OvN+DTUlaPDveKk2sAeIgq+GDKCg YSuTksD/sPegzGryZ5GLfhnK4Gvb40h1HiOxDKKwbsxGwLgSiEjIKL3snD4tXvYIPh1p oAAJOgQOvNrZaTM/Rt4nr4052bqgsVufY49LNFN97xdaIcuJYwIDSLOCoEwrNa9lJgBL xqQ/cSzN7ib/mowQqiPuJYVsp0/KLYxer2BvHGTnf4mrxdMvIS/uPA5nU1o3vxliyZ1b f0ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KXQtJrJ7; 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 o7-20020a656147000000b005859e224617si3162443pgv.818.2023.10.18.16.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:24:18 -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=KXQtJrJ7; 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 60CB2820BF3D; Wed, 18 Oct 2023 16:24:14 -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 S229679AbjJRXYB (ORCPT + 99 others); Wed, 18 Oct 2023 19:24:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbjJRXXv (ORCPT ); Wed, 18 Oct 2023 19:23:51 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BABCB116 for ; Wed, 18 Oct 2023 16:23:49 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5859a7d6556so5577042a12.0 for ; Wed, 18 Oct 2023 16:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697671429; x=1698276229; 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=Qnkqkc8e9j4DGQOzGoypqZ4/Iy9gsHg7tmNLbGbn02Y=; b=KXQtJrJ7FN8yY2G255q9jE1lEqKCsLLM4q76ekLK3iUoAmkRw7IBV77PBiBslFb3t8 splYxx0KO2yN9QRVuViuD+VfhQHU5Z4kUyB10EWdfdEC5B1m4BfQ5ncEi1hbNMV3Vd+G os6AXll9bYEyOZCEFdQp7diYmfyv3UtxeoO54= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671429; x=1698276229; 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=Qnkqkc8e9j4DGQOzGoypqZ4/Iy9gsHg7tmNLbGbn02Y=; b=d/v6fRjDZy7NroV9PWabkgqm+yNRSL9hoTAqUhNo9582rCeN7Gw6a5qr8YZVbzvi+l cnTMuirwYqDnvQ0r6mQmUXG8h3PZHfwUTrhZF0LvoSDDKgQ8gDVjuf1ntG/owUcYCoH4 Kg10apIXRvVyUqjD0khUncLa+9cLtQ+e0uRakkILpdb84Zs011MCxgGunzlIGLHYx0oe 8OKBNeoMFPu71qU3zvXbXtATJP9np/FTri3++ieeXkhTwBvn0icTEe+y9twSkWV26D8j hMneIklHE3FVyjmqx/WGgsubJzn8ZfTFHVQXqWlTKReYNVNOi5gOvGDrn9BtgfRvzzwS rUVg== X-Gm-Message-State: AOJu0YwW54JzKHVbw9tYeHoH2H4YUDXXmcQTnGSlwXWS7fL50Sy67iQu 49ennQ8aqRDntneGrES0P7utCw== X-Received: by 2002:a05:6a21:1444:b0:16b:e46e:1246 with SMTP id oc4-20020a056a21144400b0016be46e1246mr549725pzb.30.1697671429185; Wed, 18 Oct 2023 16:23:49 -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 w12-20020a170902d3cc00b001acae9734c0sm465446plb.266.2023.10.18.16.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:23:48 -0700 (PDT) Date: Wed, 18 Oct 2023 16:23:47 -0700 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] net: mdio: replace deprecated strncpy with strscpy Message-ID: <202310181623.FB6FA17@keescook> References: <20231012-strncpy-drivers-net-phy-mdio_bus-c-v1-1-15242e6f9ec4@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231012-strncpy-drivers-net-phy-mdio_bus-c-v1-1-15242e6f9ec4@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]); Wed, 18 Oct 2023 16:24:14 -0700 (PDT) On Thu, Oct 12, 2023 at 09:53:03PM +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 Looks good! Reviewed-by: Kees Cook -- Kees Cook