From: Christian Brauner Subject: Re: [PATCH net-next 08/20] rtnetlink: Update rtnl_dump_ifinfo for strict data checking Date: Sun, 7 Oct 2018 12:29:09 +0200 Message-ID: <20181007102908.4gdbr7d74untlo7k@brauner.io> References: <20181004213355.14899-1-dsahern@kernel.org> <20181004213355.14899-9-dsahern@kernel.org> <20181005175922.4oiwihofhsvcu4ok@brauner.io> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: David Ahern , netdev@vger.kernel.org, davem@davemloft.net, jbenc@redhat.com, stephen@networkplumber.org To: David Ahern Return-path: Received: from mail-wm1-f68.google.com ([209.85.128.68]:33845 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbeJGRgG (ORCPT ); Sun, 7 Oct 2018 13:36:06 -0400 Received: by mail-wm1-f68.google.com with SMTP id z25-v6so6687600wmf.1 for ; Sun, 07 Oct 2018 03:29:16 -0700 (PDT) Content-Disposition: inline In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: On Fri, Oct 05, 2018 at 01:22:24PM -0600, David Ahern wrote: > On 10/5/18 11:59 AM, Christian Brauner wrote: > >> + err = nlmsg_parse(nlh, hdrlen, tb, IFLA_MAX, ifla_policy, extack); > >> + if (err < 0) { > >> + if (cb->strict_check) > >> + return -EINVAL; > >> + goto walk_entries; > >> + } > >> > >> - if (master_idx || kind_ops) > >> - flags |= NLM_F_DUMP_FILTERED; > >> + for (i = 0; i <= IFLA_MAX; ++i) { > >> + if (!tb[i]) > >> + continue; > >> + switch (i) { > >> + case IFLA_TARGET_NETNSID: > >> + netnsid = nla_get_s32(tb[i]); > >> + tgt_net = rtnl_get_net_ns_capable(skb->sk, netnsid); > >> + if (IS_ERR(tgt_net)) { > >> + NL_SET_ERR_MSG(extack, "Invalid target namespace id"); > >> + return PTR_ERR(tgt_net); > >> + } > >> + break; > >> + case IFLA_EXT_MASK: > >> + ext_filter_mask = nla_get_u32(tb[i]); > >> + break; > >> + case IFLA_MASTER: > >> + master_idx = nla_get_u32(tb[i]); > >> + break; > >> + case IFLA_LINKINFO: > >> + kind_ops = linkinfo_to_kind_ops(tb[i]); > >> + break; > >> + default: > >> + if (cb->strict_check) { > >> + NL_SET_ERR_MSG(extack, "Unsupported attribute in dump request"); > >> + return -EINVAL; > >> + } > >> + } > > > > This might make sense to be split into two helpers for parsing: > > _strict() and _lenient(). :) > > I thought about that, but there is so much overlap - they are mostly > common. Besides, ifinfomsg is the header for link dumps, and ifinfomsg > is the one that has been (ab)used for other message types, so strict > versus lenient does not really have a differentiator for this message > type - other than checking the elements of the struct. It's mostly about the function being extremely long and convoluted. Having parts moved out into (a) descriptive helper(s) with whatever name might make this way more readable than it is now especially with the new handling we need for strict checking.