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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF1F3C83F10 for ; Thu, 31 Aug 2023 14:51:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242562AbjHaOvA (ORCPT ); Thu, 31 Aug 2023 10:51:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231181AbjHaOvA (ORCPT ); Thu, 31 Aug 2023 10:51:00 -0400 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> 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) Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org 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.