From: Ruide Cao udpv6_sendmsg() looks up the flowlabel named by sin6_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. An unprivileged UDP socket can therefore name a label it owns in sin6_flowinfo, 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. A cmsg that keeps the same label, or a connected socket's default label overridden by an owned label, behaves as before. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Reported-by: Vega Signed-off-by: Ruide Cao Signed-off-by: Ren Wei --- net/ipv6/udp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index a6886a0432f9..f23e7ed2a47b 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1631,6 +1631,11 @@ int udpv6_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