From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 151B9186A for ; Thu, 31 Aug 2023 14:50:58 +0000 (UTC) Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:237:300::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5B0D1B1; Thu, 31 Aug 2023 07:50:57 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1qbj0S-0000qg-Ea; Thu, 31 Aug 2023 16:50:48 +0200 Date: Thu, 31 Aug 2023 16:50:48 +0200 From: Florian Westphal To: Wander Lairson Costa Cc: Florian Westphal , Pablo Neira Ayuso , Jozsef Kadlecsik , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Fernando Fernandez Mancera , "open list:NETFILTER" , "open list:NETFILTER" , "open list:NETWORKING [GENERAL]" , open list , stable@kernel.org Subject: Re: [PATCH nf v2] netfilter/osf: avoid OOB read Message-ID: <20230831145048.GC15759@breakpoint.cc> References: <20230831123931.60606-1-wander@redhat.com> <20230831133750.GB15759@breakpoint.cc> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Wander Lairson Costa wrote: > On Thu, Aug 31, 2023 at 10:37 AM Florian Westphal wrote: > > > > Wander Lairson Costa wrote: > > > > > > diff --git a/net/netfilter/nfnetlink_osf.c b/net/netfilter/nfnetlink_osf.c > > > index 8f1bfa6ccc2d..13fedf2aaa0f 100644 > > > --- a/net/netfilter/nfnetlink_osf.c > > > +++ b/net/netfilter/nfnetlink_osf.c > > > @@ -315,6 +315,9 @@ static int nfnl_osf_add_callback(struct sk_buff *skb, > > > > > > f = nla_data(osf_attrs[OSF_ATTR_FINGER]); > > > > > > + if (f->opt_num > ARRAY_SIZE(f->opt)) > > > + return -EINVAL; > > > + > > > > Hmm, this isn't enough; as far as I can see there is no validation > > whatsoever. > > > > I didn't get it. It guarantees there is no OOB read of the opt array. Sorry. This is enough to validate opt_num. But other members need validation too. > > This should also check that all of: > > > > char genre[MAXGENRELEN]; > > char version[MAXGENRELEN]; > > char subtype[MAXGENRELEN]; > > > > ... have a NUL byte. You could use strnlen() == ARRAY_SIZE() -> EINVAL > > for those. > > > > I think the correct way would be memchr(genre/version/subtype, 0, MAXGENRELEN). I don't really care how it looks like, just that its clear that it is supposed to catch and reject non-null terminated c strings :-) > > Maybe there is more to be validated. I did not followup with all the > > > > I focused on the reported issue mainly because I am unfamiliar with > the Netfilter layer. Let me take a deeper look. I don't think there is anyone really familiar with OSF infra, it was added quite a while back.