From patchwork Tue Oct 24 21:55:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13435313 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC6D8C25B6B for ; Tue, 24 Oct 2023 21:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344415AbjJXV4F (ORCPT ); Tue, 24 Oct 2023 17:56:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbjJXV4E (ORCPT ); Tue, 24 Oct 2023 17:56:04 -0400 X-Greylist: delayed 454 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 24 Oct 2023 14:56:02 PDT Received: from smtp.smtpout.orange.fr (smtp-30.smtpout.orange.fr [80.12.242.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A6F910C3 for ; Tue, 24 Oct 2023 14:56:01 -0700 (PDT) Received: from localhost.localdomain ([141.170.221.62]) by smtp.orange.fr with ESMTPA id vPNUqJGNq1FecvPNUqURC8; Tue, 24 Oct 2023 23:56:00 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698184560; bh=PUTDQPvlFyPiEvyDiwi2WaoHEwZQ4gD1D9wjPH22Tg0=; h=From:To:Cc:Subject:Date; b=m3a5cy2Fq0IFJO5I90Z2OyNKDQtVh1a+EOqxMi1KRWgteOCtrQ7bKPq2vV+1rch2+ BP2NfvJYJPBRumCe4D0AQLFe00sgurSShw3jE7Ju3suGti7jr3UlnrdFpslqZGvRw9 mwk8PAfy3Hx2JBfsFXRY4risyQs+jfH3GrGVftKAk7zYWbKuA0EMsK0vB1RNJw1f2B 8ex1tKMtO/cNL8nYqFkYhJtHs3Opcf4HknbQpIaXmzaLpLLZCqUHKMVbIQ9dk0Ky0G uA4pTg0GzMeXGCi7Sp54hrkiG7LT5pe1VAOoq0ac1NdsNN/ikSDkIvqepcd5BQBe1p DARy2dv72SFow== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 24 Oct 2023 23:56:00 +0200 X-ME-IP: 141.170.221.62 From: Christophe JAILLET To: chuck.lever@oracle.com, jlayton@kernel.org, neilb@suse.de, kolga@netapp.com, Dai.Ngo@oracle.com, tom@talpey.com, trond.myklebust@hammerspace.com, anna@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] net: sunrpc: Fix an off by one in root_nfs_cat() Date: Tue, 24 Oct 2023 23:55:30 +0200 Message-Id: <856a652a7e28dde246b00025da7d4115978ae75f.1698184400.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The intent is to check if the strings' are truncated or not. So, >= should be used instead of >, because strlcat() and snprintf() return the length of the output, excluding the trailing NULL. Fixes: a02d69261134 ("SUNRPC: Provide functions for managing universal addresses") Signed-off-by: Christophe JAILLET Reviewed-by: Benjamin Coddington Reviewed-by: Simon Horman --- net/sunrpc/addr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c index d435bffc6199..97ff11973c49 100644 --- a/net/sunrpc/addr.c +++ b/net/sunrpc/addr.c @@ -284,10 +284,10 @@ char *rpc_sockaddr2uaddr(const struct sockaddr *sap, gfp_t gfp_flags) } if (snprintf(portbuf, sizeof(portbuf), - ".%u.%u", port >> 8, port & 0xff) > (int)sizeof(portbuf)) + ".%u.%u", port >> 8, port & 0xff) >= (int)sizeof(portbuf)) return NULL; - if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) > sizeof(addrbuf)) + if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) >= sizeof(addrbuf)) return NULL; return kstrdup(addrbuf, gfp_flags);