Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2001755rwd; Tue, 13 Jun 2023 18:15:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55zWNekhlTH1gsAvpwGXMXNitroBsatXMUXI07WKDBW0nUcpJTh+K5e9JueKfN19slmpF7 X-Received: by 2002:a17:90a:eac7:b0:25c:186b:8f76 with SMTP id ev7-20020a17090aeac700b0025c186b8f76mr300590pjb.4.1686705307957; Tue, 13 Jun 2023 18:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686705307; cv=none; d=google.com; s=arc-20160816; b=KwE2k2K5fXJYOGqWeiD/ujy81ecagENgfrIsRIoNy/Qv+o/ZLBAsCZSF7YZHoLQ+Iz 4GU86DrgSLTgHZNoO9oHZhT5CP+sYrEi5bUd6gVi2On8q6VjGNG8kKXxwVP5IDUM8OgZ /DluBdPdrOhWuJtDmXOKBD5ad4sFax8JM1Gm7SPFtjrT1dSw/T2fC9c84RVesM4rDnPi I+9lKlc+axArKgLhLt8q6SmdT5wJpSlayYjSbXxQQwyJfMjpyi3U8EqvvNy3I3Y+M5+D U6PYbA5ZzkhTCBPULowL2HvXDkRcY0UdhG5rnxr4BPajcLU3hY9/8JaxtrrBHQ4zniz6 nlWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:references:in-reply-to:user-agent:subject:cc:to:from :date:dkim-signature; bh=zRZxiwsnU2w4TlzYIIHUAR+53vVIA2OGZNKjGvlFo6k=; b=kgrNAAmIglEs/FYc3wLPGioABqg32GbmeB8v/WmpDbAlizTfzH+S+calYkwbk6tdq0 pwBUT2t2rqHLhI0ADBs3a3FI7Wkor4m4m92NPvvVM0rcFlNkHDcxy6T/KX7DMTBESRBj 7iTiiEK/NXuhJi/F4IPa2GmV29ztxQpZnIVAvSHOzSV7wK6o6DJSOpyRuPKlFKOGsppT Mv42GYJemqPC6CZj6WcDUbwxTY87lbYMddArZQ93uv/lTwilRGNBwXmWVQZJK2eYtp/c e2ZCdr84UHCkz+19I0vcgi1TG+b67M5Chplabu9K6192uCrztdMWL4V25hQtNvfW1T6u K/Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Hbko6dyS; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020a17090adb8500b0025c07e93ba2si3041444pjv.36.2023.06.13.18.14.47; Tue, 13 Jun 2023 18:15:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Hbko6dyS; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232576AbjFNBE1 (ORCPT + 99 others); Tue, 13 Jun 2023 21:04:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230397AbjFNBE1 (ORCPT ); Tue, 13 Jun 2023 21:04:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DA091BE6; Tue, 13 Jun 2023 18:04:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0579C62E72; Wed, 14 Jun 2023 01:04:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4403DC433C8; Wed, 14 Jun 2023 01:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686704662; bh=lsO1eVWZBM6MvyPnhWRML3twvD4cN5i1hHFtDXs+nXk=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=Hbko6dySTiq2eWSTr8BZvN7WscQfkrDv5setRSvi3YYEiu7/BfkJhp9wG/uU7FGuP gB/hmiwi0obdbTIcJIkVwKLxmDKLOiCnIxsnNQQlqWJ2sswwIac5eEUI0q4u/1Rx7x U15NrKi6VlrGUp012c5Ws+LWbqdXsSkeg6p9AU48AFe2NXy0qyusDn1MzoHvJzvKs6 NPX90LpZpBLIAuo6TDfcSs9xpk3dqy3lN01MCMa00YP2RYDJ/xk7v35oPoPQuVR4Hp K4QI2Qr76jQAu9zbkostHoGtmeqsXRjG5fz/IIflOne34zYzroMMifoQSo/5LEX5zS f+Lz3r4YU1Jtw== Date: Tue, 13 Jun 2023 18:04:19 -0700 From: Kees Cook To: Azeem Shaikh , Chuck Lever , Jeff Layton , Kees Cook CC: linux-hardening@vger.kernel.org, Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: Re: [PATCH v2] SUNRPC: Remove strlcpy User-Agent: K-9 Mail for Android In-Reply-To: <20230614001246.538643-1-azeemshaikh38@gmail.com> References: <20230614001246.538643-1-azeemshaikh38@gmail.com> Message-ID: <7E4A66A6-0B58-43AF-B9E0-62087F2EA11C@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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-nfs@vger.kernel.org On June 13, 2023 5:12:46 PM PDT, Azeem Shaikh w= rote: >strlcpy() reads the entire source buffer first=2E >This read may exceed the destination size limit=2E >This is both inefficient and can lead to linear read >overflows if a source string is not NUL-terminated [1]=2E >In an effort to remove strlcpy() completely [2], replace >strlcpy() here with sysfs_emit()=2E > >Direct replacement is safe here since the getter in kernel_params_ops >handles -errno return [3]=2E > >[1] https://www=2Ekernel=2Eorg/doc/html/latest/process/deprecated=2Ehtml#= strlcpy >[2] https://github=2Ecom/KSPP/linux/issues/89 >[3] https://elixir=2Ebootlin=2Ecom/linux/v6=2E4-rc6/source/include/linux/= moduleparam=2Eh#L52 > >Signed-off-by: Azeem Shaikh >--- > net/sunrpc/svc=2Ec | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > >diff --git a/net/sunrpc/svc=2Ec b/net/sunrpc/svc=2Ec >index e6d4cec61e47=2E=2E77326f163801 100644 >--- a/net/sunrpc/svc=2Ec >+++ b/net/sunrpc/svc=2Ec >@@ -109,13 +109,13 @@ param_get_pool_mode(char *buf, const struct kernel_= param *kp) > switch (*ip) > { > case SVC_POOL_AUTO: >- return strlcpy(buf, "auto\n", 20); >+ return sysfs_emit(buf, "auto\n"); > case SVC_POOL_GLOBAL: >- return strlcpy(buf, "global\n", 20); >+ return sysfs_emit(buf, "global\n"); > case SVC_POOL_PERCPU: >- return strlcpy(buf, "percpu\n", 20); >+ return sysfs_emit(buf, "percpu\n"); > case SVC_POOL_PERNODE: >- return strlcpy(buf, "pernode\n", 20); >+ return sysfs_emit(buf, "pernode\n"); > default: > return sprintf(buf, "%d\n", *ip); Please replace the sprintf too (and then the Subject could be "use sysfs_e= mit" or so)=2E -Kees --=20 Kees Cook