From patchwork Tue Jun 23 19:56:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 223463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84AE6C433E0 for ; Tue, 23 Jun 2020 20:30:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4606A2070E for ; Tue, 23 Jun 2020 20:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592944235; bh=eJs28hZF4bpr/WA/e/9lWBCpigJo+1IXR2t6AefAoJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=k6fav/QPws6FDhHNWiBm/rovCuUaUk0nfY79X3HH/a5TAAqYWdrY4ct48SBIBEdI+ 4eZg+zR2pULuUnhKaEn2nCEyVaHFlXi9DAQAbINVcHhEeGSMGi2VLmBfuXn55RYQSs v1R2X8Z0SKdkKRuWs5k/Gbw/Rjb3wA0dAIeFi1PM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391114AbgFWUad (ORCPT ); Tue, 23 Jun 2020 16:30:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:50852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391138AbgFWUac (ORCPT ); Tue, 23 Jun 2020 16:30:32 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7767E20723; Tue, 23 Jun 2020 20:30:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592944233; bh=eJs28hZF4bpr/WA/e/9lWBCpigJo+1IXR2t6AefAoJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ejtn5bMzWBU2NP6qKTu8iL0eRsVdtxPa0f9u0UVnj/fWeU7FuEe3EEjgaOAB1ZIzx bvxyP44zEzMwElz4A5IW3B0rZR51bLJAUCB7meXxnVgyNx4ii0251+IURb2Ed7ahPL VCo+9M0H3fQ18V0sZWNRamFG/uwmy2F6JypZyRf4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fedor Tokarev , Anna Schumaker , Sasha Levin Subject: [PATCH 5.4 197/314] net: sunrpc: Fix off-by-one issues in rpc_ntop6 Date: Tue, 23 Jun 2020 21:56:32 +0200 Message-Id: <20200623195348.322558108@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195338.770401005@linuxfoundation.org> References: <20200623195338.770401005@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Fedor Tokarev [ Upstream commit 118917d696dc59fd3e1741012c2f9db2294bed6f ] Fix off-by-one issues in 'rpc_ntop6': - 'snprintf' returns the number of characters which would have been written if enough space had been available, excluding the terminating null byte. Thus, a return value of 'sizeof(scopebuf)' means that the last character was dropped. - 'strcat' adds a terminating null byte to the string, thus if len == buflen, the null byte is written past the end of the buffer. Signed-off-by: Fedor Tokarev Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- 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 d024af4be85e8..105d17af4abcc 100644 --- a/net/sunrpc/addr.c +++ b/net/sunrpc/addr.c @@ -82,11 +82,11 @@ static size_t rpc_ntop6(const struct sockaddr *sap, rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u", IPV6_SCOPE_DELIMITER, sin6->sin6_scope_id); - if (unlikely((size_t)rc > sizeof(scopebuf))) + if (unlikely((size_t)rc >= sizeof(scopebuf))) return 0; len += rc; - if (unlikely(len > buflen)) + if (unlikely(len >= buflen)) return 0; strcat(buf, scopebuf);