Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp824679rwb; Mon, 26 Sep 2022 06:23:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4PHXCj0MymZIoKLR/YYIR6ngybzDMI35tUjG+tIdUMQY83OeHjsNWraXgPayRktgRCf/jq X-Received: by 2002:a17:907:3206:b0:780:a882:a9ac with SMTP id xg6-20020a170907320600b00780a882a9acmr17973289ejb.765.1664198583599; Mon, 26 Sep 2022 06:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198583; cv=none; d=google.com; s=arc-20160816; b=SkOtR99l/mGr+6upuswyFhb5+9eOaMT8/4wnZqgW65MdVfqnvoZ+tQlwqPXD6Ry2BJ BaBs0NpamalUFed+C5JXRbtPLxhTwUpwOI07NCfMjvkDQQmI5h2YL2EWYPpzGpguYfZl 3HIyi5aPNQMcV9IFAPrs0XtWCWmjlSGo5wsfdLl0zq7/O+XR8KrtuUjEpj7e9LXXtXUz 5445Bju5BhD4NFS5CyTH0xbXmZZ6h8DVTyOkO3xf8kHfKQwIaXV80w9XmxVGgZUfK15m q4jemKNK2EN4jbwF8xQkuEWIbdWHxTJudH2gcFyzxzqASvz5KLNDW8Gaw6tSr3zZCVGl Qm0Q== 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=a1vl7CTlRG9NBBIKFB9gHDmXA+EelV8UHQMQ+2DWyOidnjj/9zGcIedNYt0t1ZV2AM Sm30eAvzwQ5DSfQiA7HcNXJd6V+6Lxr0+PfNnxERJV8Inwy5ANhZGBSVW2+QATi4vT5D qG9QKpcpfSGGwcKNhiq8WS2+BIXP7+WYmgcehp/YjHAGV1dNqS0SF7J4iFCfnBZpVD7o tc4VmX+XlnpnETobKy2cLjYLceCDEh1Ny7Tx2rl755ZlXYscgof5U9sDoa9LSjdd2uvx SNZLYH/TjdS6tQKV+qDVowSFiCpSVjaCT41ncdD3S6bxnnbND74LISzSZ7iSq+rqoDb0 v2HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TtDxyNbd; 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 h30-20020a0564020e9e00b00456ff7eddb3si5677779eda.534.2022.09.26.06.22.38; Mon, 26 Sep 2022 06:23:03 -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=TtDxyNbd; 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 S238787AbiIZLrd (ORCPT + 99 others); Mon, 26 Sep 2022 07:47:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238788AbiIZLom (ORCPT ); Mon, 26 Sep 2022 07:44:42 -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 F32B773934; Mon, 26 Sep 2022 03:47:03 -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 C44E560BA5; Mon, 26 Sep 2022 10:45:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAA9BC433C1; Mon, 26 Sep 2022 10:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189144; bh=wYMWX1RdKzeoF4adCEB63kIZCJOyfUXgVp3rUBJ24FE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TtDxyNbdMhtQW2mz/BRAxrqr5+/jZSENsCV3E08fA1/6cC33Dzi42vOvnIMoR9UYO z0fN0SuZbgPWHRoGLWm5PxmvOFtqJ4f32hxG55kNH6jA0/DEsRrToBhpu8iN9RQ3pG UkWL2JyTTtZoOuE3CmaIf9nH3GuUldv9OQLhf36w= 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.19 087/207] netfilter: nf_conntrack_sip: fix ct_sip_walk_headers Date: Mon, 26 Sep 2022 12:11:16 +0200 Message-Id: <20220926100810.485028507@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@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