Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp483961rdb; Thu, 31 Aug 2023 15:43:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGX/n1dkcC243TVyRr9fzAu7fJ1iXVeSVHGAWHvNMpKwtO8CPEIoxVAD2CEh/zj7qwTgpB5 X-Received: by 2002:a17:902:6bc7:b0:1bb:bc6d:457 with SMTP id m7-20020a1709026bc700b001bbbc6d0457mr972029plt.36.1693521785760; Thu, 31 Aug 2023 15:43:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693521785; cv=none; d=google.com; s=arc-20160816; b=LPBAXGccasPY8kNlujMcM34ATgR548U3wiCvdDzP1Fd/o38lkHmKpfOZ65eT6UHg7a t7c3WR0tOH4giHl2gJ0wd/lQgCsIyhn/FkSqSQ6MXi0ftt5u5yNV57QQ9/25PCcNmTfB DWLVEdaKt4eh53DpkLCJsXfblJhDCF7FGagGz1Qct4EUT1l1M7xyrVhgiZpqYg4xv8as Qek6PCceqbog6UOUxNmu3gSU2copqaQOw7wvZU949jrtO1AA4qntmhA018SvXAoufpFt fmh/sXrtYSpbXC80C3G1V/I9tXnEs4eeKdmDGz/IPTOd5lZoTZXLNtP3oxbBRfL9O1ZS iDog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/77cC3augyUfVOl2EnyKSGbS02/154Q4K7cLIEGotGQ=; fh=N3XqhobggSbFG1NtEhel8PsgfSJMdNe1mzvJi9wx9P4=; b=e0eQugD1sLcpHHwvvzkeWzO4et2lbqLZW+llngIqOhu2Gh9+ja8Qq0AFhBOTeOz9gK TWHnCZ6RItXgXYufANZFW8YS8OMz0VILFhgC1rMQX9XthdC5x4NkOTVCWuLsrIBtNjHN 9UnDUdMfFYnPJCjH2cpMF4gq/pbV7Rp2QCvtiHyexwX+PD8E8IAh5+Jaa26AOnBAKyjT ztN19Jn3TOwjmwwl8nauLdEz5N+1WkeBVodDa+s+HRgFcPkwzBu1N+94IziqYq048Zug O2Gc8Aw+c2SYpkjXlEGOs4nkJdd/Ltl2BgDmVVTjPDjdIWknuU+PkgTOxTrgd/N5Ew6o 0iDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w11-20020a17090a4f4b00b0026d4415b926si4604152pjl.83.2023.08.31.15.43.01; Thu, 31 Aug 2023 15:43:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346404AbjHaOvA (ORCPT + 28 others); 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) 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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.