From owner-svn-src-all@freebsd.org Sun Aug 2 18:40:25 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6DDED9B1C51; Sun, 2 Aug 2015 18:40:25 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-pa0-x22d.google.com (mail-pa0-x22d.google.com [IPv6:2607:f8b0:400e:c03::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3F6F9B03; Sun, 2 Aug 2015 18:40:25 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by padck2 with SMTP id ck2so72176682pad.0; Sun, 02 Aug 2015 11:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=c5CtOLyfsJQ+Qm/zkvPU1Tncn8pO8ynFpxw4bO0YkAk=; b=uMQt+nY2/qfMiz+Cufl538jP4yBI40vI/+5F3vAVgBmr4Z96tQs4nMOx4rVjx7kfCW p5sz5faMSTyejKNx+O3rZIy9nmRlar77nK0+uxprkfF3usaJoBkVz+yRFXX4D9wPcAkl HgudoVHpFVVQk1TmXO82iTmTdTKrGwOV4ceb7nCiIbniZI53T/eIrP6U57eZID5ATlGY vSZinNNTJv2UrIMTgo/fiHgZroKr7jfFPTtcDWYmWuqHZbQ+djyC+fmgB+L56YcQ5mY+ Z1Ig5SBQ3s+0kb3dwaXoLQ4bIr1W/F/Dx6pP/OhumKoq4ifI+SBabFPlG0nCxvRPVlWm mwgg== X-Received: by 10.66.101.71 with SMTP id fe7mr28593683pab.89.1438540824763; Sun, 02 Aug 2015 11:40:24 -0700 (PDT) Received: from raichu ([104.232.114.184]) by smtp.gmail.com with ESMTPSA id v9sm14900116pdr.96.2015.08.02.11.40.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Aug 2015 11:40:23 -0700 (PDT) Sender: Mark Johnston Date: Sun, 2 Aug 2015 11:40:21 -0700 From: Mark Johnston To: Ermal =?iso-8859-1?Q?Lu=E7i?= Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r286028 - head/sys/netinet Message-ID: <20150802184021.GB59626@raichu> References: <201507291804.t6TI42iH065403@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <201507291804.t6TI42iH065403@repo.freebsd.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Aug 2015 18:40:25 -0000 On Wed, Jul 29, 2015 at 06:04:02PM +0000, Ermal Luçi wrote: > Author: eri > Date: Wed Jul 29 18:04:01 2015 > New Revision: 286028 > URL: https://svnweb.freebsd.org/changeset/base/286028 > > Log: > ip_output normalization and fixes > > ip_output has a big chunk of code used to handle special cases with pfil consumers which also forces a reloop on it. > Gather all this code together to make it readable and properly handle the reloop cases. > > Some of the issues identified: > > M_IP_NEXTHOP is not handled properly in existing code. > route reference leaking is possible with in FIB number change > route flags checking is not consistent in the function > > Differential Revision: https://reviews.freebsd.org/D3022 > Reviewed by: gnn > Approved by: gnn(mentor) > MFC after: 4 weeks > > Modified: > head/sys/netinet/ip_output.c > > Modified: head/sys/netinet/ip_output.c > ============================================================================== > --- head/sys/netinet/ip_output.c Wed Jul 29 17:59:13 2015 (r286027) > +++ head/sys/netinet/ip_output.c Wed Jul 29 18:04:01 2015 (r286028) > @@ -106,6 +106,94 @@ static void ip_mloopback > extern int in_mcast_loop; > extern struct protosw inetsw[]; > > +static inline int > +ip_output_pfil(struct mbuf *m, struct ifnet *ifp, struct inpcb *inp, > + struct sockaddr_in *dst, int *fibnum, int *error) > +{ > + struct m_tag *fwd_tag = NULL; > + struct in_addr odst; > + struct ip *ip; > + > + ip = mtod(m, struct ip *); > + > + /* Run through list of hooks for output packets. */ > + odst.s_addr = ip->ip_dst.s_addr; > + *error = pfil_run_hooks(&V_inet_pfil_hook, &m, ifp, PFIL_OUT, inp); > + if ((*error) != 0 || m == NULL) > + return 1; /* Finished */ > + This can result in a use-after-free in ip_output() if a pfil hook consumes the first mbuf in the chain. This happens for example when ipfw nat is in use: m_megapullup() copies the input packet into a single cluster, which is returned above. However, ip_output() will continue to reference the original mbuf chain. The patch below fixes the problem for me. Thanks, -Mark diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 0790777..086a8c9 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -107,18 +107,21 @@ extern int in_mcast_loop; extern struct protosw inetsw[]; static inline int -ip_output_pfil(struct mbuf *m, struct ifnet *ifp, struct inpcb *inp, - struct sockaddr_in *dst, int *fibnum, int *error) +ip_output_pfil(struct mbuf **mp, struct ifnet *ifp, struct inpcb *inp, + struct sockaddr_in *dst, int *fibnum, int *error) { struct m_tag *fwd_tag = NULL; + struct mbuf *m; struct in_addr odst; struct ip *ip; + m = *mp; ip = mtod(m, struct ip *); /* Run through list of hooks for output packets. */ odst.s_addr = ip->ip_dst.s_addr; - *error = pfil_run_hooks(&V_inet_pfil_hook, &m, ifp, PFIL_OUT, inp); + *error = pfil_run_hooks(&V_inet_pfil_hook, mp, ifp, PFIL_OUT, inp); + m = *mp; if ((*error) != 0 || m == NULL) return 1; /* Finished */ @@ -552,7 +555,7 @@ sendit: /* Jump over all PFIL processing if hooks are not active. */ if (PFIL_HOOKED(&V_inet_pfil_hook)) { - switch (ip_output_pfil(m, ifp, inp, dst, &fibnum, &error)) { + switch (ip_output_pfil(&m, ifp, inp, dst, &fibnum, &error)) { case 1: /* Finished */ goto done;