ipvs: fix crash if scheduler is changed
Subsystems (3)
Julian Anastasov
maintainerPATCH v2 1/1 ipvs: fix crash if scheduler is changed
I overlooked the svc->sched_data usage from schedulers when the services were converted to RCU in 3.10. Now the rare ipvsadm -E command can change the scheduler but due to the reverse order of ip_vs_bind_scheduler and ip_vs_unbind_scheduler we provide new sched_data to the old scheduler resulting in a crash.
To fix it without changing the scheduler methods we have to use synchronize_rcu() only for the editing case. It means all svc->scheduler readers should expect a NULL value. To avoid breakage for the service listing and ipvsadm -R we can use the "none" name to indicate that scheduler is not assigned, a state when we drop new connections.
Reported-by Alexander Vasiliev <[email protected]>
Fixes ceec4c381681 ("ipvs: convert services to rcu")
Signed-off-by Julian Anastasov <[email protected]>
--- net/netfilter/ipvs/ip_vs_core.c | 16 +++++++-- net/netfilter/ipvs/ip_vs_ctl.c | 78 +++++++++++++++++++++++++--------------- net/netfilter/ipvs/ip_vs_sched.c | 12 +++---- 3 files changed, 69 insertions(+), 37 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +14 -2
@@ -305,7 +305,13 @@ ip_vs_sched_persist(struct ip_vs_service *svc,* return *ignored=0 i.e. ICMP and NF_DROP */ sched =rcu_dereference (svc->scheduler); - dest = sched->schedule (svc, skb); +if (sched) { +/* read svc->sched_data after svc->scheduler */ +smp_rmb (); + dest = sched->schedule (svc, skb); + }else { + dest =NULL ; + }if (!dest) {IP_VS_DBG (1 ,"p-schedule: no dest found.\n" );kfree (param.pe_data);
@@ -452,7 +458,13 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb, } sched =rcu_dereference (svc->scheduler); - dest = sched->schedule (svc, skb); +if (sched) { +/* read svc->sched_data after svc->scheduler */ +smp_rmb (); + dest = sched->schedule (svc, skb); + }else { + dest =NULL ; + }if (dest ==NULL ) {IP_VS_DBG (1 ,"Schedule: no dest found.\n" );return NULL ;
net/netfilter/ipvs/ip_vs_ctl.c +49 -29
174 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_sched.c +6 -6
@@ -74,7 +74,7 @@ void ip_vs_unbind_scheduler(struct ip_vs_service *svc,if (sched->done_service) sched->done_service (svc); -/* svc->scheduler can not be set to NULL */ +/* svc->scheduler can be set to NULL only by caller */ }
@@ -148,21 +148,21 @@ void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler)void ip_vs_scheduler_err (struct ip_vs_service *svc,const char *msg) { -struct ip_vs_scheduler *sched; +struct ip_vs_scheduler *sched =rcu_dereference (svc->scheduler); +char *sched_name = sched ? sched->name :"none" ; - sched =rcu_dereference (svc->scheduler);if (svc->fwmark) {IP_VS_ERR_RL ("%s: FWM %u 0x%08X - %s\n" , - sched->name, svc->fwmark, svc->fwmark, msg); + sched_name, svc->fwmark, svc->fwmark, msg); #ifdef CONFIG_IP_VS_IPV6 }else if (svc->af ==AF_INET6 ) {IP_VS_ERR_RL ("%s: %s [%pI6c]:%d - %s\n" , - sched->name,ip_vs_proto_name (svc->protocol), + sched_name,ip_vs_proto_name (svc->protocol), &svc->addr.in6,ntohs (svc->port), msg);#endif }else {IP_VS_ERR_RL ("%s: %s %pI4:%d - %s\n" , - sched->name,ip_vs_proto_name (svc->protocol), + sched_name,ip_vs_proto_name (svc->protocol), &svc->addr.ip,ntohs (svc->port), msg); } }
Signature · 1 line
1.9.3