Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp777162rwb; Mon, 26 Sep 2022 05:52:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CFqInlte55SMq108do7ASmMN/0Z+bzheLua9eask8/ENBEpQVzbV2T3JBHYynYLfaUCZ0 X-Received: by 2002:a63:18f:0:b0:43c:24d2:c0f7 with SMTP id 137-20020a63018f000000b0043c24d2c0f7mr17508959pgb.470.1664196730170; Mon, 26 Sep 2022 05:52:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664196730; cv=none; d=google.com; s=arc-20160816; b=Pbx1avlQeEVg6jSSnFz/LTgx6Tsvtu7tpK4sYksWj8T7H/AuqoM6ZbD2G2y4sYhAAZ TYPShw2jTpHHCIhYn+pYevuZMVedIb0kNVEzFU1x97cbma3w05xGzgVrtDQZspkZjA3M 9ufr8XqXt0+n2ZupxVKwE0H9HWAGOLN0/2JhUXSm5MaQNIMPK+ZIJnrLrBoMwmvWWcll cAD8Xd9b/cm5XwQI0fgggvuZt7Q4+tb7QpfYhRTESzfrVHzVS8UpfU5LJkrEyeYyMqTC 5D6R5afu2Nb5Iz46Jp/0dRwjTyso4ZzsWyYUXDKac0lraP1A6wrQOYKplSfHqNVBjgo9 /SzQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1fVnfPNQl4OrtbO1NIKKUz3Wu9Y/viYsFm7Iy0Gklq4=; b=U6PBtiD9OAwjnfZhLuT5HO1/r/cmi8HCLh0WM6DwBIW6hm+YDRjSBvE6w/yx3bxHuK llQTjU9d7R5L+SUFvcOAO/gKC5j0iPpPM5Ng2eOW0+AAZmvks6BdibidGoKJgFyOMkfr HDQYpIvn9upvTHSb0CheqluB3ebxt/BLiiBa0RlqqZwaOLs/XlkzQ4EPY/39OiPPJj2u UrUvSYml7q2n/jqQe7KMyIG9niFeST6292tsnRpDMCSD9bBoSUShkYaZjW2OuNvSeE9d CBH+a/c1wPIE771Ji81NHoU1ksDvrBL//eHHl+lJey5HJhmC+xagv3Gk+Oy2IoZ7LE0D poqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jrbRmU94; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s134-20020a632c8c000000b00438d54cf8c5si18722116pgs.759.2022.09.26.05.51.58; Mon, 26 Sep 2022 05:52:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=jrbRmU94; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238185AbiIZLhz (ORCPT + 99 others); Mon, 26 Sep 2022 07:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238045AbiIZLhK (ORCPT ); Mon, 26 Sep 2022 07:37:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DF0B2ED46; Mon, 26 Sep 2022 03:44:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2FD3C60CD4; Mon, 26 Sep 2022 10:29:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E53A6C433C1; Mon, 26 Sep 2022 10:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188183; bh=wYMWX1RdKzeoF4adCEB63kIZCJOyfUXgVp3rUBJ24FE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jrbRmU94wCa/Pg4T0ylJlruUmgLzKl39TDn0NzNK8xDx0AJKA5g9boPRD6C/BxUqX VjeZ9yu2WcuWCTsGj1H7hIFXrmrZh5TrOHmkSvsKmAW2IBQQuLPKN6kYgx3fgxN7C2 wcsDt1CAauzEfKEu8CPz6LOkY16iwlNTRYEll4BM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Igor Ryzhov , Florian Westphal , Sasha Levin Subject: [PATCH 5.10 068/141] netfilter: nf_conntrack_sip: fix ct_sip_walk_headers Date: Mon, 26 Sep 2022 12:11:34 +0200 Message-Id: <20220926100756.896291466@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100754.639112000@linuxfoundation.org> References: <20220926100754.639112000@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org From: Igor Ryzhov [ Upstream commit 39aebedeaaa95757f5c1f2ddb5f43fdddbf478ca ] ct_sip_next_header and ct_sip_get_header return an absolute value of matchoff, not a shift from current dataoff. So dataoff should be assigned matchoff, not incremented by it. This issue can be seen in the scenario when there are multiple Contact headers and the first one is using a hostname and other headers use IP addresses. In this case, ct_sip_walk_headers will work as follows: The first ct_sip_get_header call to will find the first Contact header but will return -1 as the header uses a hostname. But matchoff will be changed to the offset of this header. After that, dataoff should be set to matchoff, so that the next ct_sip_get_header call find the next Contact header. But instead of assigning dataoff to matchoff, it is incremented by it, which is not correct, as matchoff is an absolute value of the offset. So on the next call to the ct_sip_get_header, dataoff will be incorrect, and the next Contact header may not be found at all. Fixes: 05e3ced297fe ("[NETFILTER]: nf_conntrack_sip: introduce SIP-URI parsing helper") Signed-off-by: Igor Ryzhov Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/netfilter/nf_conntrack_sip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c index b83dc9bf0a5d..78fd9122b70c 100644 --- a/net/netfilter/nf_conntrack_sip.c +++ b/net/netfilter/nf_conntrack_sip.c @@ -477,7 +477,7 @@ static int ct_sip_walk_headers(const struct nf_conn *ct, const char *dptr, return ret; if (ret == 0) break; - dataoff += *matchoff; + dataoff = *matchoff; } *in_header = 0; } @@ -489,7 +489,7 @@ static int ct_sip_walk_headers(const struct nf_conn *ct, const char *dptr, break; if (ret == 0) return ret; - dataoff += *matchoff; + dataoff = *matchoff; } if (in_header) -- 2.35.1