Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1945285rwd; Tue, 13 Jun 2023 17:17:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6R0FiFbjJFGb0MHjYRG616PrU01LLFZKhxfiCyYlMtdwEbMzhUSKPRAyFSss+wZgefyEHJ X-Received: by 2002:a17:906:fd8e:b0:974:1eeb:1ab7 with SMTP id xa14-20020a170906fd8e00b009741eeb1ab7mr15052763ejb.24.1686701855217; Tue, 13 Jun 2023 17:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686701855; cv=none; d=google.com; s=arc-20160816; b=L98WVs5nFWWKRCd8RUOMQkrNMDd/vn5GrVSnXYyJ4Oaakb7V/i+4aWZxReLQg3QKTB G4ORhlimJXdu6Ll8xyyzSC4qk5shV4OUHkPaoTjPpOiQaiQ4D8yMyS0jlyo9xtC6K/2d 95/0N8LhhPYosayTCtBeHKd71ypC4LebXwIZleb5TzrkmpEJ5uOXne764hpVF8zQ2E4W bJJoYQPSdMIw5cospDi9oibJiJxeOHjEelAwkJr036pbzZVCiUn9lWB+aMc30xYc5Q3O /mBapEqDcYQCz2vkr8sYvCoVCMeTLJrRcOo/YqLcFcLpfSSZstvnNgPoqakmJykVfD8F uLoQ== 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:date:subject:cc:to:from:dkim-signature; bh=fH6FmxGt/Oa/LI1in+ZqKzhAOMdBsI3JiFQigCkDIqc=; b=r6pTLa70m/zz3kz0vc4ZXyXktaPmIRPET+X39oU5nY4n1NKeI+Lb55nxKEF+VJ3MAA 0wlkkYypmNtHXdptmLt0Sks/nW/MuduzEJaFFpPI375sutUTQ7ch1pD0R2uJldtUX/Z1 CwBWSu/dwG1Hn8ShHHWSqg7QouiGaQ/rdFCXMOzBoog7fl8dSoELh2+7MK/c7ylv/j+3 JROLgJhv5T4fuxzqjC5FdMWhZmM/Ht/ZCHgwpzobVbz3wbFN55817T57zZIR5P3dnqSn EJC2WKvvl4v+Y2tE0ag/QHXfMRK9qbxMfvPT0VLrRTjcq53xAksnAflF+cIBExkZzwP6 HlrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=pYt2RDhw; 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 qc9-20020a170906d8a900b0097888f13313si7106089ejb.745.2023.06.13.17.17.00; Tue, 13 Jun 2023 17:17: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=@gmail.com header.s=20221208 header.b=pYt2RDhw; 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 S230456AbjFNAMy (ORCPT + 99 others); Tue, 13 Jun 2023 20:12:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240872AbjFNAMx (ORCPT ); Tue, 13 Jun 2023 20:12:53 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65FBA10EC; Tue, 13 Jun 2023 17:12:50 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-3408334f13bso3357965ab.3; Tue, 13 Jun 2023 17:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686701570; x=1689293570; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fH6FmxGt/Oa/LI1in+ZqKzhAOMdBsI3JiFQigCkDIqc=; b=pYt2RDhwc1sIPeNdgwx+UjMvY5EHQ25+1nToJd1CC7SPfwXpYYeDp7rXg6Qpu5ZqG4 x1VA9PKkrTPoobu997BcRhjMOBdrXNMzJgca8ddmkVD5Y9H0ZDfoAkPkibPK1PhRCXCs ZgjYPKMWVlZgfucyDBSJUkCB13636HGvCMOK1mTSx0AvP4FBZlyIsJTmBCerfVgbmjEf RsvbdmNrMPuO75dzAnEC4TuYCo/9rzLWc3IfQrs97y7QhREzNfrEHpa+yGlGC3hHgjh5 MNtGnuTU/Kt7wh5C/A5uOXWEUr8+A0AUWrGszSehAiyn4v5dJoVEB6/itmey48XFGx/1 KxUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686701570; x=1689293570; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fH6FmxGt/Oa/LI1in+ZqKzhAOMdBsI3JiFQigCkDIqc=; b=RI1XqNA5F3YQpy7jBVfM2HQktmJAYSAf+2GfEOCK66HyzMvRL8YdidvuOwswp2UhMY HFNYrIBaeO7cTVWZ1knO87nQTf+Mb44vHoOjDu/XYA19fW1Je2s32/fDIwcBw2t6BVv8 oMb4y8t6aL0MIv9Fcmp3EvbnFkrbN6gACr6c7E68ZO/mO2sCiib8+OLRC4fTGAgFHQYZ XutxOG5apOmSJoAPMH5ljIH6MX1uJFnVG/jEU6uj9P+gbjW6hFAd+Q8+Aegjr8enjznc Jn/tGaqQysgcOqZwlXhZHOIZeLgD4DxVOOdore9vDgRZN1HO80D4/NwZtd9ZrGZ2jw5b NzLw== X-Gm-Message-State: AC+VfDxkro6ljxnBIlGoLXoZ7KKCR7qyJHVzsM9rUnu7QHWrpHvu4aTh rFCWQfMwvyGaX7zlh2BCMxk= X-Received: by 2002:a92:d450:0:b0:33e:6378:d917 with SMTP id r16-20020a92d450000000b0033e6378d917mr10816259ilm.9.1686701569555; Tue, 13 Jun 2023 17:12:49 -0700 (PDT) Received: from azeems-kspp.c.googlers.com.com (54.70.188.35.bc.googleusercontent.com. [35.188.70.54]) by smtp.gmail.com with ESMTPSA id p10-20020a92c10a000000b0033b27117120sm4090039ile.13.2023.06.13.17.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 17:12:48 -0700 (PDT) From: Azeem Shaikh To: Chuck Lever , Jeff Layton , Kees Cook Cc: linux-hardening@vger.kernel.org, Azeem Shaikh , 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: [PATCH v2] SUNRPC: Remove strlcpy Date: Wed, 14 Jun 2023 00:12:46 +0000 Message-ID: <20230614001246.538643-1-azeemshaikh38@gmail.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,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 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 sysfs_emit(). Direct replacement is safe here since the getter in kernel_params_ops handles -errno return [3]. [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..77326f163801 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 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); } -- 2.41.0.162.gfafddb0af9-goog