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.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 DCFFFC48BD1 for ; Wed, 9 Jun 2021 14:51:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7FE2613B6 for ; Wed, 9 Jun 2021 14:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238255AbhFIOxm (ORCPT ); Wed, 9 Jun 2021 10:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238322AbhFIOxg (ORCPT ); Wed, 9 Jun 2021 10:53:36 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECA96C061574 for ; Wed, 9 Jun 2021 07:51:37 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1lqzY3-0002Ls-RD; Wed, 09 Jun 2021 16:51:15 +0200 Date: Wed, 9 Jun 2021 16:51:15 +0200 From: Florian Westphal To: Maxim Mikityanskiy Cc: Mat Martineau , Matthieu Baerts , Jakub Kicinski , "David S. Miller" , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , 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: <20210609145115.GL20020@breakpoint.cc> References: <20210609142212.3096691-1-maximmi@nvidia.com> <20210609142212.3096691-2-maximmi@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210609142212.3096691-2-maximmi@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: > 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? Thanks.