From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: Re: [PATCH net-next 09/20] rtnetlink: Update rtnl_bridge_getlink for strict data checking Date: Sun, 7 Oct 2018 19:31:16 -0600 Message-ID: <7a8895a8-47b0-cfc5-7f8f-bc4f3143fd60@gmail.com> References: <20181004213355.14899-1-dsahern@kernel.org> <20181004213355.14899-10-dsahern@kernel.org> <20181007103618.a7eevutds23z2esc@brauner.io> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org, davem@davemloft.net, jbenc@redhat.com, stephen@networkplumber.org To: Christian Brauner , David Ahern Return-path: Received: from mail-pg1-f196.google.com ([209.85.215.196]:45685 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725760AbeJHIkb (ORCPT ); Mon, 8 Oct 2018 04:40:31 -0400 Received: by mail-pg1-f196.google.com with SMTP id t70-v6so7050205pgd.12 for ; Sun, 07 Oct 2018 18:31:19 -0700 (PDT) In-Reply-To: <20181007103618.a7eevutds23z2esc@brauner.io> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 10/7/18 4:36 AM, Christian Brauner wrote: >> + if (cb->strict_check) { >> + struct ifinfomsg *ifm; >> >> - extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct ifinfomsg), >> - IFLA_EXT_MASK); >> - if (extfilt) { >> - if (nla_len(extfilt) < sizeof(filter_mask)) >> - return -EINVAL; >> + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { >> + NL_SET_ERR_MSG(extack, "Invalid header"); >> + return -EINVAL; >> + } >> + >> + ifm = nlmsg_data(nlh); >> + if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || >> + ifm->ifi_change || ifm->ifi_index) { >> + NL_SET_ERR_MSG(extack, "Invalid values in header for dump request"); >> + return -EINVAL; >> + } >> + } >> >> - filter_mask = nla_get_u32(extfilt); >> + err = nlmsg_parse(nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX, >> + ifla_policy, extack); >> + if (err < 0) { >> + if (cb->strict_check) >> + return -EINVAL; >> + goto walk_entries; >> + } > > What's the point of moving this out of the > if (cb->strict_check) {} branch above? This looks like it would cause > the same parse warnings that we're trying to get rid of in inet{4,6} > dumps. Link messages don't have the problem in general because they use ifinfomsg as the header - which is the one abused for other message types. That said ... > Seems to make more sense to make the nlmsg_parse() itself conditional as > well unless I'm lacking context. ... I now have nlmsg_parse and nlmsg_parse_strict.