Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1888065rwd; Tue, 13 Jun 2023 16:10:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4sQwTjLEwvolngmOBE7b4eU/t4DKdNyUqp3rO6zxarOgNk+ULdBZU3ZjmtLAjIBkYMqK9R X-Received: by 2002:a05:6402:1112:b0:518:79d2:208f with SMTP id u18-20020a056402111200b0051879d2208fmr1923406edv.35.1686697851466; Tue, 13 Jun 2023 16:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686697851; cv=none; d=google.com; s=arc-20160816; b=tO4Ign9cMyD717OiFplvCrTAhTSaeiM4iidBD0+AfIlr4YQFzF5aperFSYiKC+nCxv UHaM4qAKDt8yujfVjY0zgJFYuTaSAav+ZUmu+pocjojPX53YaZJZn9tUF41Vn6EhR2WI pXO7KPJfXCzGC5GHh7vdWsxV5EV4ikGxwE9igKrqaVf8fzkqy/kOUW8ULfdsD7cnOwQw u+9m7SAq9n0HHHrj1yCpjgkT/GPdt+jBi6+3qUho8sah9L3J/pc1FhP7BFkpiB3b91KG bysJYbUzk3VzLL7aUrKHOLzNLCgDsv8eYus7LLJ1U+aNeHfv2JIJwbffpeX8dxdyFpo7 GTwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ANEXcWjrRTe+RbBc7gwOrDGNXmOQrXArQ6Sp/mtywzs=; b=lRMaGY37b/ETeuf8GdAO7iQ9XbTfH31WKdAhjzvaVzT0URb+Rlwe3/cy0GlF1Ob3Wn j3xhFVveSjGWwlV+6wmk5E1c9Cqgo4qxUVUhCG25Bx3cMPo2Ie4MvVfhVprnNFp47VwK XZ5p1mJJL7fVuF0XL8DyDM9YT2aC12mzFrwtRVSyYBHl1gRGIgA6TYLnGhhbuoKQ/2k1 f9GrVCSdeTed+8imUEpwM+Njm94fzh3EDopFS1v1bwW0wAj2UXqmIfuhpxcMfhjeqG2e 7vxdqdPCguj9dRENP0MwfbATh39JFjmGoH5JNLR7SE0iS78ENafoHMCc1edO97pJjSka Sw5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=YL3YERGo; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a50ed8a000000b005187bb07b86si604143edr.353.2023.06.13.16.10.17; Tue, 13 Jun 2023 16:10:51 -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=@gmail.com header.s=20221208 header.b=YL3YERGo; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230017AbjFMWzl (ORCPT + 99 others); Tue, 13 Jun 2023 18:55:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbjFMWzR (ORCPT ); Tue, 13 Jun 2023 18:55:17 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7393698; Tue, 13 Jun 2023 15:55:16 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-977c89c47bdso13597966b.2; Tue, 13 Jun 2023 15:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686696915; x=1689288915; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ANEXcWjrRTe+RbBc7gwOrDGNXmOQrXArQ6Sp/mtywzs=; b=YL3YERGon/SIzeeTtOmvAE/PrjlURwrDL8eGxn/wCB+JCYZclaPqTNDMw0n0U4QJ6/ qjgKwRewC2bbg0VnMYvbCS9St2U29LArgw582NXTskNv2wdcOTPYW4X0TwpgGb6NO9BY vewxZwr6Y1GgRNmFG1OBcRMimQJAFsimI4IADBZN1GDttt7RIqCvvWwAcYOB1DVHR29C OLTUM9AkM9zCMReF4i+CMU7BKJo5dYl4va4neQ0+NDz08GWe3lQYpRAL2Ri9C79wapzd cdzZpdrGZWSV15GB+ZuidX/2B/6hy/ZpURqxyDV5FJF8jQKwClAz4vk2TjxMk0iemqsx 7dmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686696915; x=1689288915; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ANEXcWjrRTe+RbBc7gwOrDGNXmOQrXArQ6Sp/mtywzs=; b=hKhcREfDLsXoMt7ZSuA4jcGWcd5/e8mCHr6mCxtmFw9m5ANJkZhGFLm4ZeoJZfYzj5 sHUBLKf3ofkK4ZM8DiiWByMW9M9fsdZnxdjqebYW6YaRuVaZOD22x+vl9vG54mAuFSmX q41ywB7J+4gxTv2v2JlIy/6G2ktLZ9L5y6coKVVcitg+SgPuf0Zx6uzRoKG/6y08dv2R Eje7DMmRjnogemRxex9WDDhOs4ChlzLaYu46HMFcNXgbODSfTj3v1WCkro+35rjGi9eY pHxLaQFu2LYambU9PHgNrwH8oYK2Xfj+phBGD2qkEJM1MrKWsZF0f563jvUANdwOkK+z 0YuA== X-Gm-Message-State: AC+VfDw1ZW7aTSPJshI0Rt60TlQoEsQTXBOpBmGuMAls4agPY3c9ZNr6 Sc83/5UVKEPRTMQNliEO1MeR8RLLI3B7+oMX6Z0IlzAHJ/NrwQ== X-Received: by 2002:a17:907:7202:b0:96f:cb13:8715 with SMTP id dr2-20020a170907720200b0096fcb138715mr13782006ejc.69.1686696914632; Tue, 13 Jun 2023 15:55:14 -0700 (PDT) MIME-Version: 1.0 References: <20230613004054.3539554-1-azeemshaikh38@gmail.com> <01E2FCED-7EB6-4D06-8BB0-FB0D141B546E@oracle.com> <202306131238.92CBED5@keescook> In-Reply-To: From: Azeem Shaikh Date: Tue, 13 Jun 2023 18:55:03 -0400 Message-ID: Subject: Re: [PATCH] SUNRPC: Replace strlcpy with strscpy To: Chuck Lever III Cc: Kees Cook , 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" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Tue, Jun 13, 2023 at 3:43=E2=80=AFPM Chuck Lever III wrote: > > > On Jun 13, 2023, at 3:42 PM, Kees Cook wrote: > > > > On Tue, Jun 13, 2023 at 02:18:06PM +0000, Chuck Lever III wrote: > >> > >> > >>> On Jun 12, 2023, at 8:40 PM, Azeem Shaikh w= rote: > >>> > >>> 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.) > > Agreed, that's even better. > Thanks folks. Will send over a v2 which replaces strlcpy with sysfs_emit.