Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3919066pxj; Mon, 21 Jun 2021 09:21:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWImQAaXM9Iz79VrZ2Qh/CX2AjJ9dv8k4V4haeggGyTnAk4KVxqmlWgYnVHKD983KWuaM/ X-Received: by 2002:a17:906:b04d:: with SMTP id bj13mr24879206ejb.504.1624292517517; Mon, 21 Jun 2021 09:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292517; cv=none; d=google.com; s=arc-20160816; b=jnn2GN0qvHtGjNzykh9FuCFiHfyZ27J9oiPkhU0ICiTKVPbQ618JRDRBw/2mgSFYQ+ 6yJQUpSSD1aVas7+EyIdo28QRqMfAHt6kLQoWgrKpSWynP5ky0MEdN6KvY8whDKq6SKM iDhQW4Cdy5y8abOy4giAba5TwK4HLVF3++u8ZsyJHmNo8ijcRIK5Kg7Ov+o30JLhMuBQ A5o+putE8bUYQld2S0OJA7D7886vZIT5F2awgZPvvPr0XCJJPvPIHSoV/rZsFEaHJdLe OFR/ZGjCXk4+eRufP0l7CICpFGFCbj8e9Y34KPhgQPYrDxqJJNE4WnNaiR/c5O7nEl2Z 4LBg== 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=Ec6jVnNS15djpViBbsfM9jgo32iXUxtdic4ZXwBXcv8=; b=xa42ndOr8RVAyRXkp291yGbb7j5eICJflWZOIQtbxQd5tUju53wCGzQfwrjWc1RZU5 bYfUMki1nL9Fbx1J2RMrjr6zUINJMqbP22wy/QORxeD1G3y5raubvrR9KJqoHw6cgyc3 +0/o7/DJEhWcxsor0IsAX+nFRTAEPU20mwqoKsztOf4JoBPFaOnoxW+IVUpXF1VuJzHd Z3KE0nawY0Z9mX09WfA/CdQ0CkfDTAPZLoUgnG4vUpLYRLP7AYk2G5XHJeCzQMxlFy+j riOQT6S9ISRlD33h9v5cCYpxuF1Y6b6E58ifBKlFzI1Do6l1AlU2xeXwSba7nhX5Y5Ge jjuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JSusDufp; 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 bh4si12286286ejb.56.2021.06.21.09.21.34; Mon, 21 Jun 2021 09:21:57 -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=JSusDufp; 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 S231416AbhFUQUP (ORCPT + 99 others); Mon, 21 Jun 2021 12:20:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:39682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbhFUQTq (ORCPT ); Mon, 21 Jun 2021 12:19:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 69FF26120D; Mon, 21 Jun 2021 16:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292251; bh=4rUwe9UBI/E0zOkve8lj0v7KDxiiwvM2oCX7Sj+PMBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JSusDufpde9lOv7Fa7YGMcpOAmkDtAkOsTpHbA9zzcXYBftGB2ruk2Oz6Ue6HSFGo RxPDLfgSFmjU+c+zgN3xIVuDExawMjrsTJ5D169HhiLBT1TtXJJwXDmp/jcpk8lQZu 6wPzSD6WcE1Fm0jmIUNfcRRx/Y15Cv/FGeHp8BWw= 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.4 21/90] sch_cake: Fix out of bounds when parsing TCP options and header Date: Mon, 21 Jun 2021 18:14:56 +0200 Message-Id: <20210621154904.855708627@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154904.159672728@linuxfoundation.org> References: <20210621154904.159672728@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 896c0562cb42..e8eebe40e0ae 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -907,7 +907,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, @@ -931,6 +931,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; @@ -1068,6 +1070,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