From owner-svn-src-head@freebsd.org Thu Feb 25 07:41:41 2016 Return-Path: Delivered-To: svn-src-head@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 0C7D1AB2B64; Thu, 25 Feb 2016 07:41:41 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: from mail-ig0-x230.google.com (mail-ig0-x230.google.com [IPv6:2607:f8b0:4001:c05::230]) (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 D3908192; Thu, 25 Feb 2016 07:41:40 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: by mail-ig0-x230.google.com with SMTP id y8so8215687igp.1; Wed, 24 Feb 2016 23:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=c8YCSTrWmAHgk+yXX9oW52yfQemsiUAqRK4JjbQmMU4=; b=xE86Svx2Gr8COlNy/4t9F/R1xOyPfSbKgYLSqrXoNi6okQtiIgD/QtlUeaQIGaL+aU win9+dcdnNDsDMdx2zfQx0fEvqRoiczOIYAv0b2CWiKckY9Mwgkz0DsxqKD2sOUJKJZ0 AHKZCHCKs/ZgEmOsFBsJBe/9wkXUumwJmqX41IpZdgoN3XBCy6RrW62APeO0CSjGzELd iu7Yy5DVVOd1qVGuYLMEG2B+Hq0DVYbTq5YTmkJicDrh+UWAKmTXcZ8NS1MeDFRX6w4P VW2HicUNyxO4Y7ZoNU2RK9qCuJU2by8uo4f6i9jQnRuyiDgvVkMVRaonXHWYeDdflZzL FrDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=c8YCSTrWmAHgk+yXX9oW52yfQemsiUAqRK4JjbQmMU4=; b=D5SdpXAraoUHSG0oJi/Cw81qil9TmWOcfAM9p0z4oJJ+jMwajvtlkNCQ+EHatTObz6 AyllRxQuyXOoY8EFS8wuDgl6pigbD47LHuS7UzcNVI3+vcOw4wd07+z/HBjpgoLAnJfd lKNDdjc//Lv68DKdjRyhELMdZXArkNjvRP8Jl0w/d+aoxUuhFr25yAeI9tEpw+UIWoOY nHwYY5rhtBKwu8XPPLdOFv0SZIgp0R4Pah5I0r25INvCDe7wCBIHTG5p2JCqO4jDOtIT A8q0a+onJ4DSaOw1ZQqqpfvPRKzm4lhArDYo/o+R7FYz2jdqMUueK7BjUSgUfK3unmv0 1lBA== X-Gm-Message-State: AG10YOQHegqzwFPei68AtZb0BX8V4gAsoq7IzXVoQgIdoMaO5Nc9zde1UJB3k1HOKpKjxEzpVGWh8s1XeJWECg== MIME-Version: 1.0 X-Received: by 10.50.171.225 with SMTP id ax1mr864107igc.61.1456386100201; Wed, 24 Feb 2016 23:41:40 -0800 (PST) Received: by 10.36.14.19 with HTTP; Wed, 24 Feb 2016 23:41:40 -0800 (PST) In-Reply-To: <201602250733.u1P7Xxoh041746@repo.freebsd.org> References: <201602250733.u1P7Xxoh041746@repo.freebsd.org> Date: Wed, 24 Feb 2016 23:41:40 -0800 Message-ID: Subject: Re: svn commit: r296025 - head/sys/netpfil/pf From: Adrian Chadd To: Kristof Provost Cc: "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2016 07:41:41 -0000 .. what's capping totlen so one doesn't run out of memory? -a On 24 February 2016 at 23:33, Kristof Provost wrote: > Author: kp > Date: Thu Feb 25 07:33:59 2016 > New Revision: 296025 > URL: https://svnweb.freebsd.org/changeset/base/296025 > > Log: > pf: Fix possible out-of-bounds write > > In the DIOCRSETADDRS ioctl() handler we allocate a table for struct pfr_addrs, > which is processed in pfr_set_addrs(). At the users request we also provide > feedback on the deleted addresses, by storing them after the new list > ('bcopy(&ad, addr + size + i, sizeof(ad));' in pfr_set_addrs()). > > This means we write outside the bounds of the buffer we've just allocated. > We need to look at pfrio_size2 instead (i.e. the size the user reserved for our > feedback). That'd allow a malicious user to specify a smaller pfrio_size2 than > pfrio_size though, in which case we'd still read outside of the allocated > buffer. Instead we allocate the largest of the two values. > > Reported By: Paul J Murphy > PR: 207463 > MFC after: 5 days > Differential Revision: https://reviews.freebsd.org/D5426 > > Modified: > head/sys/netpfil/pf/pf_ioctl.c > > Modified: head/sys/netpfil/pf/pf_ioctl.c > ============================================================================== > --- head/sys/netpfil/pf/pf_ioctl.c Thu Feb 25 07:03:10 2016 (r296024) > +++ head/sys/netpfil/pf/pf_ioctl.c Thu Feb 25 07:33:59 2016 (r296025) > @@ -2718,13 +2718,14 @@ DIOCCHANGEADDR_error: > case DIOCRSETADDRS: { > struct pfioc_table *io = (struct pfioc_table *)addr; > struct pfr_addr *pfras; > - size_t totlen; > + size_t totlen, count; > > if (io->pfrio_esize != sizeof(struct pfr_addr)) { > error = ENODEV; > break; > } > - totlen = io->pfrio_size * sizeof(struct pfr_addr); > + count = max(io->pfrio_size, io->pfrio_size2); > + totlen = count * sizeof(struct pfr_addr); > pfras = malloc(totlen, M_TEMP, M_WAITOK); > error = copyin(io->pfrio_buffer, pfras, totlen); > if (error) { >