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=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no 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 DA5E9C63697 for ; Wed, 18 Nov 2020 23:23:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E5FC221FE for ; Wed, 18 Nov 2020 23:23:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726163AbgKRXXI (ORCPT ); Wed, 18 Nov 2020 18:23:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725947AbgKRXXI (ORCPT ); Wed, 18 Nov 2020 18:23:08 -0500 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5FEFC0613D4; Wed, 18 Nov 2020 15:23:07 -0800 (PST) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1kfWmx-0006WW-AE; Thu, 19 Nov 2020 00:23:00 +0100 Date: Thu, 19 Nov 2020 00:22:59 +0100 From: Florian Westphal To: Pablo Neira Ayuso Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org, razor@blackwall.org, tobias@waldekranz.com, jeremy@azazel.net Subject: Re: [PATCH net-next,v4 3/9] net: resolve forwarding path from virtual netdevice and HW destination address Message-ID: <20201118232259.GC15137@breakpoint.cc> References: <20201118223011.3216-1-pablo@netfilter.org> <20201118223011.3216-4-pablo@netfilter.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201118223011.3216-4-pablo@netfilter.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Pablo Neira Ayuso wrote: > +#define NET_DEVICE_PATH_STACK_MAX 5 > + > +struct net_device_path_stack { > + int num_paths; > + struct net_device_path path[NET_DEVICE_PATH_STACK_MAX]; > +}; [..] > +int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr, > + struct net_device_path_stack *stack) > +{ > + const struct net_device *last_dev; > + struct net_device_path_ctx ctx = { > + .dev = dev, > + .daddr = daddr, > + }; > + struct net_device_path *path; > + int ret = 0, k; > + > + stack->num_paths = 0; > + while (ctx.dev && ctx.dev->netdev_ops->ndo_fill_forward_path) { > + last_dev = ctx.dev; > + k = stack->num_paths++; > + if (WARN_ON_ONCE(k >= NET_DEVICE_PATH_STACK_MAX)) > + return -1; This guarantees k < NET_DEVICE_PATH_STACK_MAX, so we can fill entire path[]. > + path = &stack->path[k]; > + memset(path, 0, sizeof(struct net_device_path)); > + > + ret = ctx.dev->netdev_ops->ndo_fill_forward_path(&ctx, path); > + if (ret < 0) > + return -1; > + > + if (WARN_ON_ONCE(last_dev == ctx.dev)) > + return -1; > + } ... but this means that stack->num_paths == NET_DEVICE_PATH_STACK_MAX is possible, with k being last element. > + path = &stack->path[stack->num_paths++]; ... so this may result in a off by one?