Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3922764pxj; Mon, 21 Jun 2021 09:26:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyRja4+UL0lHLIMHkCwh0+cUO3GkeQ+7Ocr5WG7Pl4KeqPAO980Y3OcR667WnU9RuDbX+z X-Received: by 2002:a05:6602:1546:: with SMTP id h6mr20875194iow.34.1624292807157; Mon, 21 Jun 2021 09:26:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292807; cv=none; d=google.com; s=arc-20160816; b=u/bT5C7Z9dzkbLHt7G08k1mspeGDDCzK3QAZkVv0hbnTprfTa2oA/Tc5GTIcOBjYQv k+c9Fpv2SVFOfKiL1ufV75ia1brGZiy4Fu28FSb+A5Yst6xmzmBkrdRBWVmMwAVLm/ru YewFrDu4E30mY1xDnP5Nao2H7FrsyJdN/rFvEm1Pz0DnVYeTjgy3DUepumSgH5jKxRSP MvSzADROIDd+tOUR3NAKGc1ABfGlLxsKuzJCBAlIMFCIt4TWZf7OIpC0OceTwQTwbag1 b/q52EpIBa3DzZ2OZa7Z6VFPyVMPW/dq/swOpQkTY0kBxzMPgJheJVArFnrNSgOOvYQl Z3iw== 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=pihJTDCDlo3KJeLepGXvgGQK9gIIeOjDhwxzG05S8TU=; b=csPp/1A3haGVIgjycaL0zlFiD43NbSkzfxf/5oL/3Q0kJKCQPqFXqehWm9dp8M6vKP h02sEVCy28QNHPajo1yoGBLYn0MzUZq3HY0YdYw/njcrnIL4tqARo5FpCXNNxU2vemJk VrMuU+HTLMr88fQA7P23a4T4jgE4fMgY1Z9vOwlcTKo7alNBuUJHayJPQSlKn3UTOVVb VOKbEUXXn8+XTjOssCoICMJLLXSsj8TK0sW/K9cmpiSRujK4pn95NQ9qrRmazi1FfiK0 TLUZXJXHhSjqsB8crsUa7m7difnpCWAnV/MBakGat0ccOGdpOuQls6NmOpV/MrsbWc5I fbTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hvw/bRgV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si15626018ils.62.2021.06.21.09.26.35; Mon, 21 Jun 2021 09:26:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hvw/bRgV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231791AbhFUQ2G (ORCPT + 99 others); Mon, 21 Jun 2021 12:28:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:48558 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231241AbhFUQ0X (ORCPT ); Mon, 21 Jun 2021 12:26:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 32D74613C2; Mon, 21 Jun 2021 16:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292537; bh=0mKJ3fkAyYjKKBmwW1OD3wt7IeExMJxJozSgLde2vJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hvw/bRgVLAOsZPRXNr/7psdlke4weznDTAeIVn2GvZccXHqL60DeVVjl0QRW93EZP 5iEHrkJc7zVj0EFWeoMWWx3BAXDAnF7qLkHx33D90CxVckVvwihYhvY2iroSixHYSn CXxaqxRGCJFqtaxnRHOzmsk0o18f4ezHV1l44eMI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Young Xiao <92siuyang@gmail.com>, Maxim Mikityanskiy , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 036/146] sch_cake: Fix out of bounds when parsing TCP options and header Date: Mon, 21 Jun 2021 18:14:26 +0200 Message-Id: <20210621154912.519889784@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maxim Mikityanskiy [ Upstream commit ba91c49dedbde758ba0b72f57ac90b06ddf8e548 ] The TCP option parser in cake qdisc (cake_get_tcpopt and cake_tcph_may_drop) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neither TCPOPT_EOL nor TCPOPT_NOP, it reads one more byte, which exceeds the length of 1. This fix is inspired by commit 9609dad263f8 ("ipv4: tcp_input: fix stack out of bounds when parsing TCP options."). v2 changes: Added doff validation in cake_get_tcphdr to avoid parsing garbage as TCP header. Although it wasn't strictly an out-of-bounds access (memory was allocated), garbage values could be read where CAKE expected the TCP header if doff was smaller than 5. Cc: Young Xiao <92siuyang@gmail.com> Fixes: 8b7138814f29 ("sch_cake: Add optional ACK filter") Signed-off-by: Maxim Mikityanskiy Acked-by: Toke Høiland-Jørgensen Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sched/sch_cake.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 7d37638ee1c7..5c15968b5155 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -943,7 +943,7 @@ static struct tcphdr *cake_get_tcphdr(const struct sk_buff *skb, } tcph = skb_header_pointer(skb, offset, sizeof(_tcph), &_tcph); - if (!tcph) + if (!tcph || tcph->doff < 5) return NULL; return skb_header_pointer(skb, offset, @@ -967,6 +967,8 @@ static const void *cake_get_tcpopt(const struct tcphdr *tcph, length--; continue; } + if (length < 2) + break; opsize = *ptr++; if (opsize < 2 || opsize > length) break; @@ -1104,6 +1106,8 @@ static bool cake_tcph_may_drop(const struct tcphdr *tcph, length--; continue; } + if (length < 2) + break; opsize = *ptr++; if (opsize < 2 || opsize > length) break; -- 2.30.2