From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4AEFC47094 for ; Thu, 10 Jun 2021 08:56:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 902B6613FE for ; Thu, 10 Jun 2021 08:56:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbhFJI6U convert rfc822-to-8bit (ORCPT ); Thu, 10 Jun 2021 04:58:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbhFJI6U (ORCPT ); Thu, 10 Jun 2021 04:58:20 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E6B9C061574 for ; Thu, 10 Jun 2021 01:56:24 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1lrGTv-0007uR-Ab; Thu, 10 Jun 2021 10:56:07 +0200 Date: Thu, 10 Jun 2021 10:56:07 +0200 From: Florian Westphal To: Maxim Mikityanskiy Cc: Florian Westphal , Mat Martineau , Matthieu Baerts , Jakub Kicinski , "David S. Miller" , Pablo Neira Ayuso , Jozsef Kadlecsik , Toke =?iso-8859-15?Q?H=F8iland-J=F8rgensen?= , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Patrick McHardy , Jesper Dangaard Brouer , Paolo Abeni , Christoph Paasch , Peter Krystad , Young Xiao <92siuyang@gmail.com>, netdev@vger.kernel.org Subject: Re: [PATCH net 1/3] netfilter: synproxy: Fix out of bounds when parsing TCP options Message-ID: <20210610085607.GN20020@breakpoint.cc> References: <20210609142212.3096691-1-maximmi@nvidia.com> <20210609142212.3096691-2-maximmi@nvidia.com> <20210609145115.GL20020@breakpoint.cc> <4ec99ea3-6ab1-eee4-be60-992cf2f9cd45@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <4ec99ea3-6ab1-eee4-be60-992cf2f9cd45@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Maxim Mikityanskiy wrote: > On 2021-06-09 17:51, Florian Westphal wrote: > > Maxim Mikityanskiy wrote: > > > The TCP option parser in synproxy (synproxy_parse_options) 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."). > > > > > > Cc: Young Xiao <92siuyang@gmail.com> > > > Fixes: 48b1de4c110a ("netfilter: add SYNPROXY core/target") > > > Signed-off-by: Maxim Mikityanskiy > > > --- > > > net/netfilter/nf_synproxy_core.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c > > > index b100c04a0e43..621eb5ef9727 100644 > > > --- a/net/netfilter/nf_synproxy_core.c > > > +++ b/net/netfilter/nf_synproxy_core.c > > > @@ -47,6 +47,8 @@ synproxy_parse_options(const struct sk_buff *skb, unsigned int doff, > > > length--; > > > continue; > > > default: > > > + if (length < 2) > > > + return true; > > > > Would you mind a v2 that also rejects bogus th->doff value when > > computing the length? > > Could you elaborate? The length is a signed int calculated as `(th->doff * > 4) - sizeof(*th)`. Invalid doff values (0..4) lead to negative length, so we > never enter the loop. Or are you concerned of passing a negative length to > skb_header_pointer? Yes, negative length to skb_header_pointer. For other usage (mptcp for example) tcp stack validated th->doff already, but thats not the case for synproxy.