From: Ruide Cao l2tp_ip6_sendmsg() looks up the flowlabel named by sockaddr_l2tpip6.l2tp_flowinfo before parsing ancillary data. An IPV6_FLOWINFO cmsg can then replace fl6.flowlabel, but the ownership lookup after ip6_datagram_send_ctl() is skipped when a flowlabel reference is already held. A socket can therefore name a label it owns in the sockaddr, override it with another socket's exclusive label in the cmsg, and transmit the exclusive label, while fl6_merge_options() still uses the options of the stale label. Release the old reference when the final label differs from the one already held, and look up the final label before transmission. Fixes: a32e0eec7042 ("l2tp: introduce L2TPv3 IP encapsulation support for IPv6") Cc: stable@vger.kernel.org Reported-by: Vega Signed-off-by: Ruide Cao Signed-off-by: Ren Wei --- net/l2tp/l2tp_ip6.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c index bdaae1b64d25..be1fd51581bc 100644 --- a/net/l2tp/l2tp_ip6.c +++ b/net/l2tp/l2tp_ip6.c @@ -600,6 +600,11 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6_sock_release(flowlabel); return err; } + if (flowlabel && + flowlabel->label != (fl6.flowlabel & IPV6_FLOWLABEL_MASK)) { + fl6_sock_release(flowlabel); + flowlabel = NULL; + } if ((fl6.flowlabel & IPV6_FLOWLABEL_MASK) && !flowlabel) { flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); if (IS_ERR(flowlabel)) -- 2.47.3