Received: by 10.223.185.116 with SMTP id b49csp824122wrg; Sat, 10 Feb 2018 21:15:18 -0800 (PST) X-Google-Smtp-Source: AH8x226umVDTcOa6RBk8fdHdcqMdbFi1XlsLO1oM5TYrDYZzcZfb37+KsVnNt290J041jfb+8oqQ X-Received: by 10.99.135.65 with SMTP id i62mr2751155pge.331.1518326117897; Sat, 10 Feb 2018 21:15:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518326117; cv=none; d=google.com; s=arc-20160816; b=by4wLATp8RvglPTjrfv1N9J2mJXKj5JDpJ8i3QzzZV14GnoNH7Uj7HKsO7potpawcw bUD47m4r/C6y8ZqOchLww2IXl91R1eUGzLEQk2GUbjqUSYBmrTp+4EAGWRRKzC4py1Qe xvpLQ+L/Lx+SXD7r9RY6I1O7sNOmZ5hfnQG14lQRCvj9yBHN8CCcCUE9RIm/q1h2M+bn 9hd2euvpJt00XOF/e86facNhTmdFtIGhgyV+TTx+AWH/z2Qxl0UHO2/9GakBSAEhI/Zt 0kKpTaDIa4spb/Z62DtwHz7iTtq4xXSvAT9disyEw3iTxe31fIF8mgBpSyKnen5j2Ydm SFIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=ETXYDrtvBE2DQ7YwYnwKZ/opPjeCWEfO0PAis5lzuPE=; b=Exe1Rkgmw7un7lmk2vrzkFYocGtzcEd56gIObJOH3YpRbsCG/XUrP8NOqOIa25Fbzp QSlcPFVJIP0jsyzdAp6YKV0xvlgxmKf89t/kGoNKRfEKdHfCZEmflx3kE9VYlB3i8KmB bWY6CMvoAGfZuEiRzklxZVhuiV7qkgCPRF//5A32mw6FWkvRezt7mgY85IxDUrF7BhuR itbmWMPjG6xUMHIgfEnWAYyl4R0a8MhO+AC9fM5iMjPQ5zQm7wcekGJS41Pp2e6eA2pQ avMhqcpSwuR1bGsFScx6IJW0S5t5SHfEN87q5VQ51CG14Os0xk5aO7X3ZO821piLhOfA 9Urg== ARC-Authentication-Results: i=1; mx.google.com; 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 d12si2179909pgt.729.2018.02.10.21.15.04; Sat, 10 Feb 2018 21:15:17 -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; 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 S932139AbeBKFOe (ORCPT + 99 others); Sun, 11 Feb 2018 00:14:34 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41364 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752586AbeBKEdl (ORCPT ); Sat, 10 Feb 2018 23:33:41 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKd-0002hN-6I; Sun, 11 Feb 2018 04:33:39 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKY-0004Wk-OS; Sun, 11 Feb 2018 04:33:34 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Eric Dumazet" , "Pablo Neira Ayuso" , "Denys Fedoryshchenko" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 66/79] netfilter: xt_TCPMSS: add more sanity tests on tcph->doff In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet commit 2638fd0f92d4397884fd991d8f4925cb3f081901 upstream. Denys provided an awesome KASAN report pointing to an use after free in xt_TCPMSS I have provided three patches to fix this issue, either in xt_TCPMSS or in xt_tcpudp.c. It seems xt_TCPMSS patch has the smallest possible impact. Signed-off-by: Eric Dumazet Reported-by: Denys Fedoryshchenko Signed-off-by: Pablo Neira Ayuso Signed-off-by: Ben Hutchings --- net/netfilter/xt_TCPMSS.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/net/netfilter/xt_TCPMSS.c +++ b/net/netfilter/xt_TCPMSS.c @@ -71,7 +71,7 @@ tcpmss_mangle_packet(struct sk_buff *skb tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff); tcp_hdrlen = tcph->doff * 4; - if (len < tcp_hdrlen) + if (len < tcp_hdrlen || tcp_hdrlen < sizeof(struct tcphdr)) return -1; if (info->mss == XT_TCPMSS_CLAMP_PMTU) { @@ -122,6 +122,10 @@ tcpmss_mangle_packet(struct sk_buff *skb if (len > tcp_hdrlen) return 0; + /* tcph->doff has 4 bits, do not wrap it to 0 */ + if (tcp_hdrlen >= 15 * 4) + return 0; + /* * MSS Option not found ?! add it.. */