Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1701426rwd; Tue, 13 Jun 2023 12:51:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ik4OqzeAR4WZzBtYgzGN6hoPokwENT9Oqgw1IEWa0Ajkv8taUZAb1pmWHStvVjM9fmq5d X-Received: by 2002:a05:6358:9dad:b0:129:c50d:6a37 with SMTP id d45-20020a0563589dad00b00129c50d6a37mr7103394rwo.16.1686685895796; Tue, 13 Jun 2023 12:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686685895; cv=none; d=google.com; s=arc-20160816; b=MJa62/BMYHJ/SCA1cVhCT3YGc/vwCQ0BskjQSqv9Bg3Aug4Atgg/yOoYE6Cojtq6d1 zGYy28zzhdtJ9c5ovjQ/na3dYN+VwWv8lWE9hQINYwq7IVKAacH+Cf5WMVI1rRJBE+zy bY2BZFDFbpJT2M/zQnHUkCadJBnk+KdI+r3asVxMHBIszTi8d6lMd81hz3raCz2OZyim MyejuunXXmRPtLhb2D3RGUM8shfvifZrlIj05tPtDH+lNqQq817A9WRPGILSPIpmhSNZ yCNsHYtj6+R7x2KFKLaL2Ci6ywRq0RKaJB2FwucwOHj2DW1sNOTvpdsQjhLbrEs4wKCc ARRA== 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=ZxEcj49+vGwYkRgl1icr+yGC9c7gL0eXEsyVyEAa72I=; b=AAf/1jNC5dScgMgIRICPMebdFgRnc6OrlUQfS3vfeKIKGirL29cDJGteVLv2uMN2le QqPKM0CrBQ2JWBLIg43QJCeZ2bduJyHD7ZsWkNg8cpZS/PA7MY+nnfKeKmuaCm2I3jhj AggONzdYbPpKUxlqwn/kQHX6nZPNXIz6o5in82JErg5JBnnXnhjzIgMmVAH5JpzTkr4w fpn84SKKhAxD6zqZiOMzDz0vlP0R+/VL+eNcKo6+xwqzRta8TGs3GnFNJw8sXPOqwe6z yjD4gcNUbMdbdKNQn1v1IYe23uWfL+OPUW8VEB0zSDVQl51xxpTEVI8sYECom4rHkBrb l8Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QDF6Xybu; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r16-20020a638f50000000b0053481d76f48si9316614pgn.288.2023.06.13.12.50.49; Tue, 13 Jun 2023 12:51:35 -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=@chromium.org header.s=google header.b=QDF6Xybu; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239193AbjFMTmW (ORCPT + 99 others); Tue, 13 Jun 2023 15:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231545AbjFMTmR (ORCPT ); Tue, 13 Jun 2023 15:42:17 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 535A7171A for ; Tue, 13 Jun 2023 12:42:15 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b3afd2f9bdso22038695ad.0 for ; Tue, 13 Jun 2023 12:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1686685335; x=1689277335; 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=ZxEcj49+vGwYkRgl1icr+yGC9c7gL0eXEsyVyEAa72I=; b=QDF6XybuuSbESC6lsMPSOgkZPqsKAZRVX6eAzuQeJFFgsCxewr0dbZQsAQcrNv/Jt/ cUwNgWA3FaBmym/Q0URJfdCq/RYEH3el9I+AIsJg4wNI/j3dqAL883+nv6ycCEqwu8Is szTUB9KYgk+4+OrfO9cFjQmr2dHKH1dCCXOEo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686685335; x=1689277335; 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=ZxEcj49+vGwYkRgl1icr+yGC9c7gL0eXEsyVyEAa72I=; b=ceEEZaR/W/a1sN0Y02mEzymVtA80Oyd+ZT7OVWwIXQl6kJYHU8s0f7qAfZ5sbrlyjM eHnDzpQiOfGTzfi968keHvDfr+Ccpu3zLkxZk7ZtN75w+GnOrNPSB9bqxWIoXSOcEpwz am9kTYgXpp1LOh4o3GXhupz6udgUEJHgoNBtrnvwf2OyTmoHoNvMYlJWLH4qBOK0Xivu 61DByk8gBZFhFXUEyJKE7b3PuAcOVTH3xzEBesKA+NqvSx85N7/7wIUyPyv7yY5szwvM mu8UlL0vLyQLoIpGT2fPkfwWGBirkmUjZNvH/NHrgoL7qVgs/r9BNo4Lv0MA6u2fmzhd bzUA== X-Gm-Message-State: AC+VfDwh33sNbblTVank6Fhd1jucfIo+zjcLrA/eIHK0FZ9wsBlQLjv6 8DcRVElqwL2dtqQgXzyqtd/pcQ== X-Received: by 2002:a17:902:e88f:b0:1b3:ebda:6563 with SMTP id w15-20020a170902e88f00b001b3ebda6563mr2783752plg.53.1686685334830; Tue, 13 Jun 2023 12:42:14 -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 t10-20020a170902bc4a00b001b3c48d01d0sm3902plz.65.2023.06.13.12.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 12:42:14 -0700 (PDT) Date: Tue, 13 Jun 2023 12:42:13 -0700 From: Kees Cook To: Chuck Lever III Cc: Azeem Shaikh , Jeff Layton , "linux-hardening@vger.kernel.org" , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Linux NFS Mailing List , open list , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "netdev@vger.kernel.org" Subject: Re: [PATCH] SUNRPC: Replace strlcpy with strscpy Message-ID: <202306131238.92CBED5@keescook> References: <20230613004054.3539554-1-azeemshaikh38@gmail.com> <01E2FCED-7EB6-4D06-8BB0-FB0D141B546E@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <01E2FCED-7EB6-4D06-8BB0-FB0D141B546E@oracle.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 Tue, Jun 13, 2023 at 02:18:06PM +0000, Chuck Lever III wrote: > > > > On Jun 12, 2023, at 8:40 PM, Azeem Shaikh wrote: > > > > strlcpy() reads the entire source buffer first. > > This read may exceed the destination size limit. > > This is both inefficient and can lead to linear read > > overflows if a source string is not NUL-terminated [1]. > > In an effort to remove strlcpy() completely [2], replace > > strlcpy() here with strscpy(). > > Using sprintf() seems cleaner to me: it would get rid of > the undocumented naked integer. Would that work for you? This is changing the "get" routine for reporting module parameters out of /sys. I think the right choice here is sysfs_emit(), as it performs the size tracking correctly. (Even the "default" sprintf() call should be replaced too, IMO.) > > > > Direct replacement is safe here since the getter in kernel_params_ops > > handles -errorno return [3]. > > s/errorno/errno/ > > > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy > > [2] https://github.com/KSPP/linux/issues/89 > > [3] https://elixir.bootlin.com/linux/v6.4-rc6/source/include/linux/moduleparam.h#L52 > > > > Signed-off-by: Azeem Shaikh > > --- > > net/sunrpc/svc.c | 8 ++++---- > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > > index e6d4cec61e47..e5f379c4fdb3 100644 > > --- a/net/sunrpc/svc.c > > +++ b/net/sunrpc/svc.c > > @@ -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 strscpy(buf, "auto\n", 20); e.g. return sysfs_emit(buf, "auto\n"); ... > > case SVC_POOL_GLOBAL: > > - return strlcpy(buf, "global\n", 20); > > + return strscpy(buf, "global\n", 20); > > case SVC_POOL_PERCPU: > > - return strlcpy(buf, "percpu\n", 20); > > + return strscpy(buf, "percpu\n", 20); > > case SVC_POOL_PERNODE: > > - return strlcpy(buf, "pernode\n", 20); > > + return strscpy(buf, "pernode\n", 20); > > default: > > return sprintf(buf, "%d\n", *ip); and: return sysfs_emit(buf, "%d\n", *ip); -Kees -- Kees Cook