Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4024645ybl; Mon, 3 Feb 2020 11:04:44 -0800 (PST) X-Google-Smtp-Source: APXvYqwqH2L4EJz3aNX7t5/RpPYL6aylLRdG+m+z3K5XriCJ8sfODVeF2Kty4oUFrYdxbjC1DE92 X-Received: by 2002:aca:6742:: with SMTP id b2mr385908oiy.86.1580756684837; Mon, 03 Feb 2020 11:04:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580756684; cv=none; d=google.com; s=arc-20160816; b=ck1IW8aeGQ/iGfN9Q0LGyDMpwX3exRRVB1ja6d1DL/EM0uyIpkO/lwKRugSuI0ym37 tQ8VTcrSsOlJjNAj7bHmXFV70nOJ+FlcCguYlnhmjaFpYYqzu3rHK+TIlDHCV9jealKB 4YwBLwE6U0TblBvME3Q7vM2toUG0WxlLcRzew/d96Y3dh83ouxFO0f5xUMDjMb6q1IE1 LKy3noW/9xtqrmgCZYTded3tMhlYgoFaKPJkKj7aOueVxGOrn+h2NoTNGWvals52cYKi uuPMkjXK3Xm658dDE2Ry2WHsmcVUPtyDVog/d16TW6wrzD/UA1Lax8VbkBTo0f5auPs+ vXmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FwvbArdfqOLfbf4h2rvhSwJ/AL1QIM4EfQkY7V+veFs=; b=uol5qjV7hHnjOQibgr+q53kmNmA0jPdLey144nLycOYhTMrsWRKLK12/FTalgOPq78 tmiLw9AQKyQRxYOzfnf3fmLVzBPjX1OHyiwp76lY3KlcrrcmJkGiHI6xUN48NnmlTGDz DD+wsPcU63co6ZRrZDyohJs2W1uGvz9eHdhJy1aCRsYPTSYsQcH5CoklAYze/l2eN/qc kYa8HyUR342lM4mwB4llE5+ph+DKclhrKPqMRM6l8EUZa4BgjAutawCTAsWgqqW4VDsS sRegf+FpriOF9yocTPOMbfQsplDzR3A0aKkas1m4efb02qSz/Zqt3jWaVuUUEReC3s+3 GWsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jjpr7Xiq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u18si8842898oif.66.2020.02.03.11.04.32; Mon, 03 Feb 2020 11:04:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jjpr7Xiq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729380AbgBCQ1U (ORCPT + 99 others); Mon, 3 Feb 2020 11:27:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:38500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729370AbgBCQ1S (ORCPT ); Mon, 3 Feb 2020 11:27:18 -0500 Received: from localhost (unknown [104.132.45.99]) (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 7571B2087E; Mon, 3 Feb 2020 16:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580747236; bh=oUvURxr++AigzS0CRsO75l4QfqQyceb3NEWxxlijn4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jjpr7Xiqny5g0MaRFUZnKVZLj9LQZ2frwx9fHyproQvFzTjgmsMLlcRnUhhkcYgcm k1xdNVmbpe22GG2c256dUICt/DheZVHaMQuMzlHApPYi45AZ4cHxrX7TxheX8WThsa sDCYUIfJMNp5xboFcSCrIB0g1C64HtkOdYkhitUY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Praveen Chaudhary , Zhenggen Xu , Andy Stracner , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.9 68/68] net: Fix skb->csum update in inet_proto_csum_replace16(). Date: Mon, 3 Feb 2020 16:20:04 +0000 Message-Id: <20200203161915.928840315@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200203161904.705434837@linuxfoundation.org> References: <20200203161904.705434837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Praveen Chaudhary [ Upstream commit 189c9b1e94539b11c80636bc13e9cf47529e7bba ] skb->csum is updated incorrectly, when manipulation for NF_NAT_MANIP_SRC\DST is done on IPV6 packet. Fix: There is no need to update skb->csum in inet_proto_csum_replace16(), because update in two fields a.) IPv6 src/dst address and b.) L4 header checksum cancels each other for skb->csum calculation. Whereas inet_proto_csum_replace4 function needs to update skb->csum, because update in 3 fields a.) IPv4 src/dst address, b.) IPv4 Header checksum and c.) L4 header checksum results in same diff as L4 Header checksum for skb->csum calculation. [ pablo@netfilter.org: a few comestic documentation edits ] Signed-off-by: Praveen Chaudhary Signed-off-by: Zhenggen Xu Signed-off-by: Andy Stracner Reviewed-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/core/utils.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/net/core/utils.c b/net/core/utils.c index cf5622b9ccc44..3317f90b32eb0 100644 --- a/net/core/utils.c +++ b/net/core/utils.c @@ -316,6 +316,23 @@ void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb, } EXPORT_SYMBOL(inet_proto_csum_replace4); +/** + * inet_proto_csum_replace16 - update layer 4 header checksum field + * @sum: Layer 4 header checksum field + * @skb: sk_buff for the packet + * @from: old IPv6 address + * @to: new IPv6 address + * @pseudohdr: True if layer 4 header checksum includes pseudoheader + * + * Update layer 4 header as per the update in IPv6 src/dst address. + * + * There is no need to update skb->csum in this function, because update in two + * fields a.) IPv6 src/dst address and b.) L4 header checksum cancels each other + * for skb->csum calculation. Whereas inet_proto_csum_replace4 function needs to + * update skb->csum, because update in 3 fields a.) IPv4 src/dst address, + * b.) IPv4 Header checksum and c.) L4 header checksum results in same diff as + * L4 Header checksum for skb->csum calculation. + */ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb, const __be32 *from, const __be32 *to, bool pseudohdr) @@ -327,9 +344,6 @@ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb, if (skb->ip_summed != CHECKSUM_PARTIAL) { *sum = csum_fold(csum_partial(diff, sizeof(diff), ~csum_unfold(*sum))); - if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr) - skb->csum = ~csum_partial(diff, sizeof(diff), - ~skb->csum); } else if (pseudohdr) *sum = ~csum_fold(csum_partial(diff, sizeof(diff), csum_unfold(*sum))); -- 2.20.1