From: Christian Brauner Subject: Re: [PATCH v2 net-next 18/23] net/fib_rules: Update fib_nl_dumprule for strict data checking Date: Mon, 8 Oct 2018 12:48:54 +0200 Message-ID: <20181008104853.2ivuc5nbdbujpd2l@brauner.io> References: <20181008031644.15989-1-dsahern@kernel.org> <20181008031644.15989-19-dsahern@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: netdev@vger.kernel.org, davem@davemloft.net, jbenc@redhat.com, stephen@networkplumber.org, David Ahern To: David Ahern Return-path: Received: from mail-wm1-f67.google.com ([209.85.128.67]:53740 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbeJHSAI (ORCPT ); Mon, 8 Oct 2018 14:00:08 -0400 Received: by mail-wm1-f67.google.com with SMTP id y11-v6so4693779wma.3 for ; Mon, 08 Oct 2018 03:49:01 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20181008031644.15989-19-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org List-ID: On Sun, Oct 07, 2018 at 08:16:39PM -0700, David Ahern wrote: > From: David Ahern > > Update fib_nl_dumprule for strict data checking. If the flag is set, > the dump request is expected to have fib_rule_hdr struct as the header. > All elements of the struct are expected to be 0 and no attributes can > be appended. > > Signed-off-by: David Ahern Acked-by: Christian Brauner > --- > net/core/fib_rules.c | 36 +++++++++++++++++++++++++++++++++++- > 1 file changed, 35 insertions(+), 1 deletion(-) > > diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c > index 0ff3953f64aa..ffbb827723a2 100644 > --- a/net/core/fib_rules.c > +++ b/net/core/fib_rules.c > @@ -1063,13 +1063,47 @@ static int dump_rules(struct sk_buff *skb, struct netlink_callback *cb, > return err; > } > > +static int fib_valid_dumprule_req(const struct nlmsghdr *nlh, > + struct netlink_ext_ack *extack) > +{ > + struct fib_rule_hdr *frh; > + > + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh))) { > + NL_SET_ERR_MSG(extack, "Invalid header for fib rule dump request"); > + return -EINVAL; > + } > + > + frh = nlmsg_data(nlh); > + if (frh->dst_len || frh->src_len || frh->tos || frh->table || > + frh->res1 || frh->res2 || frh->action || frh->flags) { > + NL_SET_ERR_MSG(extack, > + "Invalid values in header for fib rule dump request"); > + return -EINVAL; > + } > + > + if (nlmsg_attrlen(nlh, sizeof(*frh))) { > + NL_SET_ERR_MSG(extack, "Invalid data after header in fib rule dump request"); > + return -EINVAL; > + } > + > + return 0; > +} > + > static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb) > { > + const struct nlmsghdr *nlh = cb->nlh; > struct net *net = sock_net(skb->sk); > struct fib_rules_ops *ops; > int idx = 0, family; > > - family = rtnl_msg_family(cb->nlh); > + if (cb->strict_check) { > + int err = fib_valid_dumprule_req(nlh, cb->extack); > + > + if (err < 0) > + return err; > + } > + > + family = rtnl_msg_family(nlh); > if (family != AF_UNSPEC) { > /* Protocol specific dump request */ > ops = lookup_rules_ops(net, family); > -- > 2.11.0 >