Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp812936rwb; Mon, 26 Sep 2022 06:15:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5F83CknG1W7Sk5Tbuhs1hRrQmBNsqbHB9vMhwzeYNKG3qoSgjMY5wIEYg7+/TtrxA1XGp2 X-Received: by 2002:a17:907:7602:b0:783:78b5:d4e9 with SMTP id jx2-20020a170907760200b0078378b5d4e9mr4498336ejc.50.1664198104097; Mon, 26 Sep 2022 06:15:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198104; cv=none; d=google.com; s=arc-20160816; b=F8picrxPwWcTo4f6nyCUmuwHYqBwMYRJjT6ODbfdGKtFRH81lI94PdjkIo7zCQvPj1 prH/YgbG1VmlaaI8IxBnCuyNXzo0W2JhW/ZrqaLsIFJilSgd16cZqJbQtuW7U4JNL+ts 6xj11lD2fUpTOypVnHVAxq+mHG4PS5zNaWObBOSfAQjDAPB0QrCbu9XnzKViTz9qx2Eg Hu6EXMZyADUBPq9c29J29qsl5zeHUa7LWqXZmuaJ9gAfP9UC1Jej8xVnYcIwr/JObFKh z7yscBSfiHxLkdE4y0f5YjEa/HbpLosxXFPI+ipBVjv902dwN973n/YtmH+yYttAprza fZuQ== 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=Ch+HAnG2UKkwO0+M4PcYb5+xjzUAiZEuzGDXIKvqu0g=; b=tfG4dO6XWJyQT/Y1PDoMeTojQvG0B4f3ajAIaeFvBW0dM2wcSq2C3/KSSlysx2vB1g kbOImqnry7BX9rsGXP6a6oZjamXvYL6TvC1+JKr442LYDry04p1WK3AQh/XV9ZhUCl5q bS3iKIR/vfUsqyyiODgDcwRb98+agtgS7MtF5wlecdIqdAfsgqwwr0c1DQ5d1kya/Vx9 GZdEWDGfsBYgTxFC/NdIcKn9VE4K/PR6S5T4lS53FmYgl0PNlvkCBX64iJzt7O9YY6Xa CRwGJRY95HrE4QPb3tFDscIXSB8BJq33D9KuzSGQVjBqPJHmgoS3/K/UQhYOH1TJKfmP +Ztw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ObD+37BJ; 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 n21-20020a170906379500b00730babc11e3si12704178ejc.640.2022.09.26.06.14.38; Mon, 26 Sep 2022 06:15:04 -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=ObD+37BJ; 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 S235688AbiIZKaS (ORCPT + 99 others); Mon, 26 Sep 2022 06:30:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235560AbiIZK2L (ORCPT ); Mon, 26 Sep 2022 06:28:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05AA44DB71; Mon, 26 Sep 2022 03:18:51 -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 ams.source.kernel.org (Postfix) with ESMTPS id BFDD3B80936; Mon, 26 Sep 2022 10:18:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7045C433D6; Mon, 26 Sep 2022 10:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187528; bh=5yVkGeIa9tVEy8jpr69BZmy26C/8lkf9me70+HR20uY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ObD+37BJFWKHV/6CpWjVhmT+P+UYDotgm0hVv/HQBrYK41t4CUJpPAnf5Qy4+WdIS /DEfBVbNEXgjvPhowEGxgikhCIz+SlsGAyakqZ+qBRYj4WwIgvbfMzm7lt57WkNE9e sN04xTHF5npxcldVaAw3/vQEIkbhN+NTyxY6MglA= 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 4.19 36/58] netfilter: nf_conntrack_sip: fix ct_sip_walk_headers Date: Mon, 26 Sep 2022 12:11:55 +0200 Message-Id: <20220926100742.797555771@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100741.430882406@linuxfoundation.org> References: <20220926100741.430882406@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 c8d2b6688a2a..046f118dea06 100644 --- a/net/netfilter/nf_conntrack_sip.c +++ b/net/netfilter/nf_conntrack_sip.c @@ -471,7 +471,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; } @@ -483,7 +483,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