From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mathieu Xhonneux Subject: [PATCH net] ipv6: sr: fix TLVs not being copied using setsockopt Date: Sun, 7 Jan 2018 17:12:04 +0000 Message-ID: <20180107171204.14443-1-m.xhonneux@gmail.com> Cc: dlebrun@google.com, m.xhonneux@gmail.com To: netdev@vger.kernel.org Return-path: Received: from mail-wm0-f68.google.com ([74.125.82.68]:39472 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753927AbeAGQMI (ORCPT ); Sun, 7 Jan 2018 11:12:08 -0500 Received: by mail-wm0-f68.google.com with SMTP id i11so10177096wmf.4 for ; Sun, 07 Jan 2018 08:12:08 -0800 (PST) Sender: netdev-owner@vger.kernel.org List-ID: Function ipv6_push_rthdr4 allows to add an IPv6 Segment Routing Header to a socket through setsockopt, but the current implementation doesn't copy possible TLVs at the end of the SRH (i.e., the following branch if (sr_has_hmac(sr_phdr)) will never be taken as no HMAC TLV is copied). This commit adds a memcpy in case TLVs have been appended to the SRH. Fixes: a149e7c7ce812561f0fdc7a86ddc42f294e5eb3e ("ipv6: sr: add support for SRH injection through setsockopt") Acked-by: David Lebrun Signed-off-by: Mathieu Xhonneux --- net/ipv6/exthdrs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 83bd75713535..bc68eb661970 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -925,6 +925,15 @@ static void ipv6_push_rthdr4(struct sk_buff *skb, u8 *proto, sr_phdr->segments[0] = **addr_p; *addr_p = &sr_ihdr->segments[sr_ihdr->segments_left]; + if (sr_ihdr->hdrlen > hops * 2) { + int tlvs_offset, tlvs_length; + + tlvs_offset = (1 + hops * 2) << 3; + tlvs_length = (sr_ihdr->hdrlen - hops * 2) << 3; + memcpy((char *)sr_phdr + tlvs_offset, + (char *)sr_ihdr + tlvs_offset, tlvs_length); + } + #ifdef CONFIG_IPV6_SEG6_HMAC if (sr_has_hmac(sr_phdr)) { struct net *net = NULL; -- 2.15.1