Re: [PATCH] net: ipmr: fix suspicious RCU warning

From: David Miller
Date: Tue Nov 19 2019 - 17:50:54 EST


From: Anders Roxell <anders.roxell@xxxxxxxxxx>
Date: Mon, 18 Nov 2019 10:09:25 +0100

> @@ -108,9 +108,18 @@ static void igmpmsg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt);
> static void mroute_clean_tables(struct mr_table *mrt, int flags);
> static void ipmr_expire_process(struct timer_list *t);
>
> +#ifdef CONFIG_PROVE_LOCKING
> +int ip_mr_initialized;
> +void ip_mr_now_initialized(void) { ip_mr_initialized = 1; }
> +#else
> +const int ip_mr_initialized = 1;
> +void ip_mr_now_initialized(void) { }
> +#endif

This seems excessive and a bit not so pretty.

> +
> #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
> #define ipmr_for_each_table(mrt, net) \
> - list_for_each_entry_rcu(mrt, &net->ipv4.mr_tables, list)
> + list_for_each_entry_rcu(mrt, &net->ipv4.mr_tables, list, \
> + (lockdep_rtnl_is_held() || !ip_mr_initialized))
>
> static struct mr_table *ipmr_mr_table_iter(struct net *net,
> struct mr_table *mrt)

The problematic code path is ipmr_rules_init() done during ipmr_net_init().

You can just wrap this call around RCU locking or take the RTNL mutex.

That way you don't need to rediculous ip_mr_initialized knob which frankly
doesn't even seem accurate to me. It's a centralized global variable
which is holding state about multiple network namespace objects which makes
absolutely no sense at all, it's wrong.