Socket option NETLINK_GET_STRICT_CHK, quoting from commit 89d35528d17d ("netlink: Add new socket option to enable strict checking on dumps"), is used to "request strict checking of headers and attributes on dump requests".
If some attributes are set (including flags), setting this option causes dump functions to filter results according to these attributes, via the filter_set flag. However, if strict checking is requested, this should imply that we also filter results based on flags that are *not* set. This is currently not the case, at least for IPv6 FIB dumps: if the RTM_F_CLONED flag is not set, and strict checking is required, we should not return routes with the RTM_F_CLONED flag set. Set the filter_set flag whenever strict checking is requested, limiting the scope to IPv6 FIB dumps for the moment being, as other users of the flag might not present this inconsistency. Note that this partially duplicates the semantics of NLM_F_MATCH as described by RFC 3549, par. 3.1.1. Instead of setting a filter based on the size of the netlink message, properly support NLM_F_MATCH, by setting a filter via ip_filter_fib_dump_req() and setting the filter_set flag. Signed-off-by: Stefano Brivio <sbri...@redhat.com> --- v4: New patch, split from 6/8 net/ipv6/ip6_fib.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index bc5cb359c8a6..54bbc97beb6f 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -570,15 +570,18 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) if (cb->strict_check) { int err; - err = ip_filter_fib_dump_req(net, nlh, &arg.filter, cb, true); if (err < 0) return err; - } else if (nlmsg_len(nlh) >= sizeof(struct rtmsg)) { - struct rtmsg *rtm = nlmsg_data(nlh); - - if (rtm->rtm_flags & RTM_F_PREFIX) - arg.filter.flags = RTM_F_PREFIX; + arg.filter.filter_set = 1; + } else if (nlh->nlmsg_flags & NLM_F_MATCH) { + res = ip_filter_fib_dump_req(net, nlh, &arg.filter, cb, false); + if (res) { + if (res == -ENODEV) + res = 0; + goto out; + } + arg.filter.filter_set = 1; } w = (void *)cb->args[2]; -- 2.20.1