Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp827341rwb; Mon, 26 Sep 2022 06:24:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6A3mqub+zx0kBZB4GwxEQqAp1yIZHKjHS0FAfoF0fXmkMQQExX1+wJJeeUGym9PaO+Lk9t X-Received: by 2002:a05:6a00:a83:b0:54a:e52e:9472 with SMTP id b3-20020a056a000a8300b0054ae52e9472mr23625441pfl.50.1664198689385; Mon, 26 Sep 2022 06:24:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198689; cv=none; d=google.com; s=arc-20160816; b=TkLRHqrbvPUR11hfdAR0Pw/a3RoW5dKguz1pMgzw9J8SXPNRQT4zTy8lmAF+B14hl+ 01CG7I4BCVSyosdqDbFi1m+7Eh35NL/cS7SqIf3Za/MeuUPF/A6Q8X1Fv3Wx4vxFKpE2 78D57P/QqwusxKO7yaPc19fMv+CS6FR5rH+y/yeUiqf8aohTbkphJpglZUoBLFXnGj6T CIVaFuuIUKOO0m4O4nowbKww9or4BgIiCWt7OyBntAFQ26WhbOSlHdaIqRhLQQXSLy6k DD2XaO9suY/HZsrJuYNwmgwbEk7n1dZzpCTQtzkkXintexfEjCTRrEGnJa/sZDO4lKLo 9oxQ== 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=KgmLwtQmSui9rMZfYUdvb/uHWpDGuiTSzTF8hAxyWqOAUs3N2ulbJUzOFRe1au6OYs Vi9gjk81WjzJFk3khRA2GzybZaxhdql52K5FCd7LEJ6hrOGkB3++sL1UXAKPAIttkThZ mJvMS0/U50RLqhXiI47SfIcofGgn1fYZ+K5gSMNETGoHtNhtTl9ugMC6pPlsddlVXsmP pMM+p9ByJbb98ny+nMsZqSZ7gQXzpY2qE8V/QT6NVN/QKhsqEfuOCSfJ4jUgng7Mi4ee Iw5NbAdhG7jo40YmJs0sg9OjyKp/7ktDvzGqrSuEKWV7q7Iwl6hId9HVzGZHYw7QqdmR Rncw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hCYqNtnD; 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 d2-20020a170902854200b001743c571718si11381389plo.177.2022.09.26.06.24.36; Mon, 26 Sep 2022 06:24:49 -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=hCYqNtnD; 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 S236604AbiIZKre (ORCPT + 99 others); Mon, 26 Sep 2022 06:47:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236839AbiIZKos (ORCPT ); Mon, 26 Sep 2022 06:44:48 -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 9A0B5564D8; Mon, 26 Sep 2022 03:25:45 -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 235EA60B9A; Mon, 26 Sep 2022 10:25:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 356A2C43140; Mon, 26 Sep 2022 10:25:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187943; bh=wYMWX1RdKzeoF4adCEB63kIZCJOyfUXgVp3rUBJ24FE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hCYqNtnDOLuGH69uCMy8cMALO7FJApT4iWcZx2p8OaFAcEK+B7jwA7WLl1mS3ROR/ NzRggAjoKRfRX1YlhghHzR8BohQ0Pi0lTCmP7x09uL5MWd6tQ5Ke6K38mjuEkBjxhX d4rNhKfMKRgmrq0qK6FfLXFcPZvy2eSchCbzFTQA= 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.4 069/120] netfilter: nf_conntrack_sip: fix ct_sip_walk_headers Date: Mon, 26 Sep 2022 12:11:42 +0200 Message-Id: <20220926100753.514780869@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100750.519221159@linuxfoundation.org> References: <20220926100750.519221159@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