stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Eyal Itkin <eyal.itkin@gmail.com>,
	Stefan Richter <stefanr@s5r6.in-berlin.de>
Subject: [PATCH 4.4 42/69] firewire: net: guard against rx buffer overflows
Date: Wed,  9 Nov 2016 11:44:20 +0100	[thread overview]
Message-ID: <20161109102902.883844809@linuxfoundation.org> (raw)
In-Reply-To: <20161109102901.127641653@linuxfoundation.org>

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

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

From: Stefan Richter <stefanr@s5r6.in-berlin.de>

commit 667121ace9dbafb368618dbabcf07901c962ddac upstream.

The IP-over-1394 driver firewire-net lacked input validation when
handling incoming fragmented datagrams.  A maliciously formed fragment
with a respectively large datagram_offset would cause a memcpy past the
datagram buffer.

So, drop any packets carrying a fragment with offset + length larger
than datagram_size.

In addition, ensure that
  - GASP header, unfragmented encapsulation header, or fragment
    encapsulation header actually exists before we access it,
  - the encapsulated datagram or fragment is of nonzero size.

Reported-by: Eyal Itkin <eyal.itkin@gmail.com>
Reviewed-by: Eyal Itkin <eyal.itkin@gmail.com>
Fixes: CVE 2016-8633
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/firewire/net.c |   51 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 16 deletions(-)

--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -578,6 +578,9 @@ static int fwnet_incoming_packet(struct
 	int retval;
 	u16 ether_type;
 
+	if (len <= RFC2374_UNFRAG_HDR_SIZE)
+		return 0;
+
 	hdr.w0 = be32_to_cpu(buf[0]);
 	lf = fwnet_get_hdr_lf(&hdr);
 	if (lf == RFC2374_HDR_UNFRAG) {
@@ -602,7 +605,12 @@ static int fwnet_incoming_packet(struct
 		return fwnet_finish_incoming_packet(net, skb, source_node_id,
 						    is_broadcast, ether_type);
 	}
+
 	/* A datagram fragment has been received, now the fun begins. */
+
+	if (len <= RFC2374_FRAG_HDR_SIZE)
+		return 0;
+
 	hdr.w1 = ntohl(buf[1]);
 	buf += 2;
 	len -= RFC2374_FRAG_HDR_SIZE;
@@ -616,6 +624,9 @@ static int fwnet_incoming_packet(struct
 	datagram_label = fwnet_get_hdr_dgl(&hdr);
 	dg_size = fwnet_get_hdr_dg_size(&hdr); /* ??? + 1 */
 
+	if (fg_off + len > dg_size)
+		return 0;
+
 	spin_lock_irqsave(&dev->lock, flags);
 
 	peer = fwnet_peer_find_by_node_id(dev, source_node_id, generation);
@@ -722,6 +733,22 @@ static void fwnet_receive_packet(struct
 	fw_send_response(card, r, rcode);
 }
 
+static int gasp_source_id(__be32 *p)
+{
+	return be32_to_cpu(p[0]) >> 16;
+}
+
+static u32 gasp_specifier_id(__be32 *p)
+{
+	return (be32_to_cpu(p[0]) & 0xffff) << 8 |
+	       (be32_to_cpu(p[1]) & 0xff000000) >> 24;
+}
+
+static u32 gasp_version(__be32 *p)
+{
+	return be32_to_cpu(p[1]) & 0xffffff;
+}
+
 static void fwnet_receive_broadcast(struct fw_iso_context *context,
 		u32 cycle, size_t header_length, void *header, void *data)
 {
@@ -731,9 +758,6 @@ static void fwnet_receive_broadcast(stru
 	__be32 *buf_ptr;
 	int retval;
 	u32 length;
-	u16 source_node_id;
-	u32 specifier_id;
-	u32 ver;
 	unsigned long offset;
 	unsigned long flags;
 
@@ -750,22 +774,17 @@ static void fwnet_receive_broadcast(stru
 
 	spin_unlock_irqrestore(&dev->lock, flags);
 
-	specifier_id =    (be32_to_cpu(buf_ptr[0]) & 0xffff) << 8
-			| (be32_to_cpu(buf_ptr[1]) & 0xff000000) >> 24;
-	ver = be32_to_cpu(buf_ptr[1]) & 0xffffff;
-	source_node_id = be32_to_cpu(buf_ptr[0]) >> 16;
-
-	if (specifier_id == IANA_SPECIFIER_ID &&
-	    (ver == RFC2734_SW_VERSION
+	if (length > IEEE1394_GASP_HDR_SIZE &&
+	    gasp_specifier_id(buf_ptr) == IANA_SPECIFIER_ID &&
+	    (gasp_version(buf_ptr) == RFC2734_SW_VERSION
 #if IS_ENABLED(CONFIG_IPV6)
-	     || ver == RFC3146_SW_VERSION
+	     || gasp_version(buf_ptr) == RFC3146_SW_VERSION
 #endif
-	    )) {
-		buf_ptr += 2;
-		length -= IEEE1394_GASP_HDR_SIZE;
-		fwnet_incoming_packet(dev, buf_ptr, length, source_node_id,
+	    ))
+		fwnet_incoming_packet(dev, buf_ptr + 2,
+				      length - IEEE1394_GASP_HDR_SIZE,
+				      gasp_source_id(buf_ptr),
 				      context->card->generation, true);
-	}
 
 	packet.payload_length = dev->rcv_buffer_size;
 	packet.interrupt = 1;



  parent reply	other threads:[~2016-11-09 11:04 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161109104447epcas2p2800d2cee304b181b04018da2ac18030c@epcas2p2.samsung.com>
2016-11-09 10:43 ` [PATCH 4.4 00/69] 4.4.31-stable review Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 01/69] i2c: xgene: Avoid dma_buffer overrun Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 02/69] i2c: core: fix NULL pointer dereference under race condition Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 04/69] h8300: fix syscall restarting Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 05/69] libxfs: clean up _calc_dquots_per_chunk Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 06/69] mm/list_lru.c: avoid error-path NULL pointer deref Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 07/69] mm: memcontrol: do not recurse in direct reclaim Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 08/69] KEYS: Fix short sprintf buffer in /proc/keys show function Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 09/69] ALSA: usb-audio: Add quirk for Syntek STK1160 Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 10/69] ALSA: hda - Merge RIRB_PRE_DELAY into CTX_WORKAROUND caps Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 11/69] ALSA: hda - Raise AZX_DCAPS_RIRB_DELAY handling into top drivers Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 12/69] ALSA: hda - allow 40 bit DMA mask for NVidia devices Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 13/69] ALSA: hda - Adding a new group of pin cfg into ALC295 pin quirk table Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 14/69] ALSA: hda - Fix headset mic detection problem for two Dell laptops Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 17/69] btrfs: fix races on root_log_ctx lists Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 18/69] ubifs: Abort readdir upon error Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 19/69] ubifs: Fix regression in ubifs_readdir() Greg Kroah-Hartman
2016-11-09 10:43   ` [PATCH 4.4 20/69] mei: txe: dont clean an unprocessed interrupt cause Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 22/69] USB: serial: fix potential NULL-dereference at probe Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 23/69] USB: serial: ftdi_sio: add support for Infineon TriBoard TC2X7 Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 24/69] xhci: use default USB_RESUME_TIMEOUT when resuming ports Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 25/69] usb: increase ohci watchdog delay to 275 msec Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 26/69] GenWQE: Fix bad page access during abort of resource allocation Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 27/69] Fix potential infoleak in older kernels Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 28/69] vt: clear selection before resizing Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 29/69] hv: do not lose pending heartbeat vmbus packets Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 30/69] xhci: add restart quirk for Intel Wildcatpoint PCH Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 31/69] tty: limit terminal size to 4M chars Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 32/69] USB: serial: cp210x: fix tiocmget error handling Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 33/69] dm: free io_barrier after blk_cleanup_queue call Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 36/69] ovl: fsync after copy-up Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 37/69] parisc: Ensure consistent state when switching to kernel stack at syscall entry Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 38/69] virtio_ring: Make interrupt suppression spec compliant Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 39/69] virtio: console: Unlock vqs while freeing buffers Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 40/69] dm mirror: fix read error on recovery after default leg failure Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 41/69] Input: i8042 - add XMG C504 to keyboard reset table Greg Kroah-Hartman
2016-11-09 10:44   ` Greg Kroah-Hartman [this message]
2016-11-09 10:44   ` [PATCH 4.4 43/69] firewire: net: fix fragmented datagram_size off-by-one Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 44/69] mac80211: discard multicast and 4-addr A-MSDUs Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 45/69] scsi: megaraid_sas: Fix data integrity failure for JBOD (passthrough) devices Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 46/69] scsi: scsi_debug: Fix memory leak if LBP enabled and module is unloaded Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 47/69] scsi: arcmsr: Send SYNCHRONIZE_CACHE command to firmware Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 48/69] mmc: dw_mmc-pltfm: fix the potential NULL pointer dereference Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 50/69] drm/radeon/si_dpm: Limit clocks on HD86xx part Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 51/69] drm/radeon/si_dpm: workaround for SI kickers Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 54/69] perf build: Fix traceevent plugins build race Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 55/69] x86/xen: fix upper bound of pmd loop in xen_cleanhighmap() Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 56/69] powerpc/ptrace: Fix out of bounds array access warning Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 57/69] ARM: 8584/1: floppy: avoid gcc-6 warning Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 58/69] mm/cma: silence warnings due to max() usage Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 59/69] drm/exynos: fix error handling in exynos_drm_subdrv_open Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 60/69] cgroup: avoid false positive gcc-6 warning Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 61/69] smc91x: avoid self-comparison warning Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 63/69] UBI: fastmap: scrub PEB when bitflips are detected in a free PEB EC header Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 64/69] pwm: Unexport children before chip removal Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 65/69] usb: dwc3: Fix size used in dma_free_coherent() Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 67/69] kvm: x86: Check memopp before dereference (CVE-2016-8630) Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 68/69] ubi: fastmap: Fix add_vol() return value test in ubi_attach_fastmap() Greg Kroah-Hartman
2016-11-09 10:44   ` [PATCH 4.4 69/69] HID: usbhid: add ATEN CS962 to list of quirky devices Greg Kroah-Hartman
2016-11-09 18:21   ` [PATCH 4.4 00/69] 4.4.31-stable review Shuah Khan
2016-11-09 19:34   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161109102902.883844809@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=eyal.itkin@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stefanr@s5r6.in-berlin.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).