Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1582817

[PATCH 4.4 11/20] tun: read vnet_hdr_sz once

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.4 11/20] tun: read vnet_hdr_sz once
Date 2017-02-16 19:20 +0100
Message-ID <tbyOT-1GL-35@gated-at.bofh.it> (permalink)
References <tbyvw-1iO-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Willem de Bruijn <willemb@google.com>


[ Upstream commit e1edab87faf6ca30cd137e0795bc73aa9a9a22ec ]

When IFF_VNET_HDR is enabled, a virtio_net header must precede data.
Data length is verified to be greater than or equal to expected header
length tun->vnet_hdr_sz before copying.

Read this value once and cache locally, as it can be updated between
the test and use (TOCTOU).

Signed-off-by: Willem de Bruijn <willemb@google.com>
Reported-by: Dmitry Vyukov <dvyukov@google.com>
CC: Eric Dumazet <edumazet@google.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/net/tun.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1108,9 +1108,11 @@ static ssize_t tun_get_user(struct tun_s
 	}
 
 	if (tun->flags & IFF_VNET_HDR) {
-		if (len < tun->vnet_hdr_sz)
+		int vnet_hdr_sz = READ_ONCE(tun->vnet_hdr_sz);
+
+		if (len < vnet_hdr_sz)
 			return -EINVAL;
-		len -= tun->vnet_hdr_sz;
+		len -= vnet_hdr_sz;
 
 		n = copy_from_iter(&gso, sizeof(gso), from);
 		if (n != sizeof(gso))
@@ -1122,7 +1124,7 @@ static ssize_t tun_get_user(struct tun_s
 
 		if (tun16_to_cpu(tun, gso.hdr_len) > len)
 			return -EINVAL;
-		iov_iter_advance(from, tun->vnet_hdr_sz - sizeof(gso));
+		iov_iter_advance(from, vnet_hdr_sz - sizeof(gso));
 	}
 
 	if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP) {
@@ -1301,7 +1303,7 @@ static ssize_t tun_put_user(struct tun_s
 		vlan_hlen = VLAN_HLEN;
 
 	if (tun->flags & IFF_VNET_HDR)
-		vnet_hdr_sz = tun->vnet_hdr_sz;
+		vnet_hdr_sz = READ_ONCE(tun->vnet_hdr_sz);
 
 	total = skb->len + vlan_hlen + vnet_hdr_sz;
 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.4 00/20] 4.4.50-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:00 +0100
  [PATCH 4.4 07/20] netlabel: out of bound access in cipso_v4_validate() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 13/20] mlx4: Invoke softirqs after napi_reschedule Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 14/20] sctp: avoid BUG_ON on sctp_wait_for_sndbuf Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
    Re: [PATCH 4.4 14/20] sctp: avoid BUG_ON on sctp_wait_for_sndbuf Ben Hutchings <ben@decadent.org.uk> - 2017-02-21 17:10 +0100
      Re: [PATCH 4.4 14/20] sctp: avoid BUG_ON on sctp_wait_for_sndbuf Marcelo <marcelo.leitner@gmail.com> - 2017-02-21 18:00 +0100
        Re: [PATCH 4.4 14/20] sctp: avoid BUG_ON on sctp_wait_for_sndbuf Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> - 2017-02-21 21:00 +0100
  [PATCH 4.4 03/20] ipv6: pointer math error in ip6_tnl_parse_tlv_enc_lim() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 02/20] ipv6: fix ip6_tnl_parse_tlv_enc_lim() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 09/20] ipv6: tcp: add a missing tcp_v6_restore_cb() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 01/20] can: Fix kernel panic at security_sock_rcv_skb Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 04/20] tcp: fix 0 divide in __tcp_select_window() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 19/20] l2tp: do not use udp_ioctl() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 08/20] ip6_gre: fix ip6gre_err() invalid reads Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 20/20] tcp: fix mark propagation with fwmark_reflect enabled Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 17/20] packet: round up linear to header len Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:10 +0100
  [PATCH 4.4 11/20] tun: read vnet_hdr_sz once Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-16 19:20 +0100
  Re: [PATCH 4.4 00/20] 4.4.50-stable review Guenter Roeck <linux@roeck-us.net> - 2017-02-17 11:40 +0100
  Re: [PATCH 4.4 00/20] 4.4.50-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-18 00:50 +0100

csiph-web