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 IPv4 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 IPv4 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 net/ipv4/fib_frontend.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 873fc5c4721c..32a04318d725 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -954,10 +954,14 @@ static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) err = ip_filter_fib_dump_req(net, nlh, &filter, cb, true); if (err < 0) return err; - } else if (nlmsg_len(nlh) >= sizeof(struct rtmsg)) { - struct rtmsg *rtm = nlmsg_data(nlh); - - filter.flags = rtm->rtm_flags & (RTM_F_PREFIX | RTM_F_CLONED); + filter.filter_set = 1; + } else if (nlh->nlmsg_flags & NLM_F_MATCH) { + err = ip_filter_fib_dump_req(net, nlh, &filter, cb, false); + if (err == -ENODEV) + return skb->len; + if (err) + return err; + filter.filter_set = 1; } /* fib entries are never clones and ipv4 does not use prefix flag */ -- 2.20.1