From: Christian Brauner Subject: Re: [PATCH v2 net-next 23/23] rtnetlink: Update rtnl_fdb_dump for strict data checking Date: Mon, 8 Oct 2018 13:02:21 +0200 Message-ID: <20181008110220.wklr45ihsrhtheff@brauner.io> References: <20181008031644.15989-1-dsahern@kernel.org> <20181008031644.15989-24-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]:54026 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726656AbeJHSNj (ORCPT ); Mon, 8 Oct 2018 14:13:39 -0400 Received: by mail-wm1-f67.google.com with SMTP id y11-v6so4734084wma.3 for ; Mon, 08 Oct 2018 04:02:28 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20181008031644.15989-24-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org List-ID: On Sun, Oct 07, 2018 at 08:16:44PM -0700, David Ahern wrote: > From: David Ahern > > Update rtnl_fdb_dump for strict data checking. If the flag is set, > the dump request is expected to have an ndmsg struct as the header > potentially followed by one or more attributes. Any data passed in the > header or as an attribute is taken as a request to influence the data > returned. Only values supported by the dump handler are allowed to be > non-0 or set in the request. At the moment only the NDA_IFINDEX and > NDA_MASTER attributes are supported. > > Signed-off-by: David Ahern Acked-by: Christian Brauner > --- > net/core/rtnetlink.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 60 insertions(+), 2 deletions(-) > > diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c > index c7509c789fb6..c894c4af8981 100644 > --- a/net/core/rtnetlink.c > +++ b/net/core/rtnetlink.c > @@ -3799,6 +3799,60 @@ int ndo_dflt_fdb_dump(struct sk_buff *skb, > } > EXPORT_SYMBOL(ndo_dflt_fdb_dump); > > +static int valid_fdb_dump_strict(const struct nlmsghdr *nlh, > + int *br_idx, int *brport_idx, > + struct netlink_ext_ack *extack) > +{ > + struct nlattr *tb[NDA_MAX + 1]; > + struct ndmsg *ndm; > + int err, i; > + > + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ndm))) { > + NL_SET_ERR_MSG(extack, "Invalid header for fdb dump request"); > + return -EINVAL; > + } > + > + ndm = nlmsg_data(nlh); > + if (ndm->ndm_pad1 || ndm->ndm_pad2 || ndm->ndm_state || > + ndm->ndm_flags || ndm->ndm_type) { > + NL_SET_ERR_MSG(extack, "Invalid values in header for fbd dump request"); > + return -EINVAL; > + } > + > + err = nlmsg_parse_strict(nlh, sizeof(struct ndmsg), tb, NDA_MAX, > + NULL, extack); > + if (err < 0) > + return err; > + > + *brport_idx = ndm->ndm_ifindex; > + for (i = 0; i <= NDA_MAX; ++i) { > + if (!tb[i]) > + continue; > + > + switch (i) { > + case NDA_IFINDEX: > + if (nla_len(tb[i]) != sizeof(u32)) { > + NL_SET_ERR_MSG(extack, "Invalid IFINDEX attribute in fdb dump request"); > + return -EINVAL; > + } > + *brport_idx = nla_get_u32(tb[NDA_IFINDEX]); > + break; > + case NDA_MASTER: > + if (nla_len(tb[i]) != sizeof(u32)) { > + NL_SET_ERR_MSG(extack, "Invalid MASTER attribute in fdb dump request"); > + return -EINVAL; > + } > + *br_idx = nla_get_u32(tb[NDA_MASTER]); > + break; > + default: > + NL_SET_ERR_MSG(extack, "Unsupported attribute in fdb dump request"); > + return -EINVAL; > + } > + } > + > + return 0; > +} > + > static int valid_fdb_dump_legacy(const struct nlmsghdr *nlh, > int *br_idx, int *brport_idx, > struct netlink_ext_ack *extack) > @@ -3846,8 +3900,12 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) > int err = 0; > int fidx = 0; > > - err = valid_fdb_dump_legacy(cb->nlh, &br_idx, &brport_idx, > - cb->extack); > + if (cb->strict_check) > + err = valid_fdb_dump_strict(cb->nlh, &br_idx, &brport_idx, > + cb->extack); > + else > + err = valid_fdb_dump_legacy(cb->nlh, &br_idx, &brport_idx, > + cb->extack); > if (err < 0) > return err; > > -- > 2.11.0 >