From owner-freebsd-bugs@FreeBSD.ORG Fri Mar 8 19:40:03 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id CE54C3F3 for ; Fri, 8 Mar 2013 19:40:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id B5B0FD9F for ; Fri, 8 Mar 2013 19:40:03 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.6/8.14.6) with ESMTP id r28Je3Bc034133 for ; Fri, 8 Mar 2013 19:40:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.6/8.14.6/Submit) id r28Je3mZ034132; Fri, 8 Mar 2013 19:40:03 GMT (envelope-from gnats) Resent-Date: Fri, 8 Mar 2013 19:40:03 GMT Resent-Message-Id: <201303081940.r28Je3mZ034132@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Adrian Chadd Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id B3D1F9A6 for ; Fri, 8 Mar 2013 19:31:06 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 8B70DA67 for ; Fri, 8 Mar 2013 19:31:06 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r28JV5lK070806 for ; Fri, 8 Mar 2013 19:31:05 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.5/8.14.5/Submit) id r28JV5B9070805; Fri, 8 Mar 2013 19:31:05 GMT (envelope-from nobody) Message-Id: <201303081931.r28JV5B9070805@red.freebsd.org> Date: Fri, 8 Mar 2013 19:31:05 GMT From: Adrian Chadd To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: misc/176764: [net] [if_bridge] use-after-free in if_bridge X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Mar 2013 19:40:04 -0000 >Number: 176764 >Category: misc >Synopsis: [net] [if_bridge] use-after-free in if_bridge >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Mar 08 19:40:03 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Adrian Chadd >Release: >Organization: >Environment: >Description: Hi Adrian, There seems to be a potential use-after-free in `sys/net/if_bridge.c'. >From the following chunk of code: #define GRAB_OUR_PACKETS(iface) \ if ((iface)->if_type == IFT_GIF) \ continue; \ /* It is destined for us. */ \ if (memcmp(IF_LLADDR((iface)), eh->ether_dhost, ETHER_ADDR_LEN) == 0 \ OR_CARP_CHECK_WE_ARE_DST((iface)) \ ) { \ if ((iface)->if_type == IFT_BRIDGE) { \ ETHER_BPF_MTAP(iface, m); \ iface->if_ipackets++; \ /* Filter on the physical interface. */ \ if (pfil_local_phys && \ (PFIL_HOOKED(&V_inet_pfil_hook) \ OR_PFIL_HOOKED_INET6)) { \ if (bridge_pfil(&m, NULL, ifp, \ PFIL_IN) != 0 || m == NULL) { \ BRIDGE_UNLOCK(sc); \ return (NULL); \ } \ } \ } \ bridge_pfil() might end-up changing the mbuf pointer (and the underlying data), however, we still have a pending pointer to the data through `eh' which is about to be dereferenced in the following call to bridge_rtupdate(): if (bif->bif_flags & IFBIF_LEARNING) { \ error = bridge_rtupdate(sc, eh->ether_shost, \ vlan, bif, 0, IFBAF_DYNAMIC); \ The obvious patch to fix this is attached to this mail. >How-To-Repeat: n/a >Fix: see attachment Patch attached with submission follows: diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index 85ad9fb..73ee550 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -2313,6 +2313,7 @@ bridge_input(struct ifnet *ifp, struct mbuf *m) BRIDGE_UNLOCK(sc); \ return (NULL); \ } \ + eh = mtod(m, struct ether_header *); \ } \ } \ if (bif->bif_flags & IFBIF_LEARNING) { \ >Release-Note: >Audit-Trail: >Unformatted: