From owner-freebsd-net@freebsd.org Tue Nov 21 16:44:54 2017 Return-Path: Delivered-To: freebsd-net@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 68D43DF3C54 for ; Tue, 21 Nov 2017 16:44:54 +0000 (UTC) (envelope-from srs0=1gm5=ct=sigsegv.be=kristof@codepro.be) Received: from venus.codepro.be (venus.codepro.be [IPv6:2a01:4f8:162:1127::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.codepro.be", Issuer "Gandi Standard SSL CA 2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 26CFE758C2 for ; Tue, 21 Nov 2017 16:44:53 +0000 (UTC) (envelope-from srs0=1gm5=ct=sigsegv.be=kristof@codepro.be) Received: from [172.16.5.2] (vega.codepro.be [IPv6:2a01:4f8:162:1127::3]) (Authenticated sender: kp) by venus.codepro.be (Postfix) with ESMTPSA id 0CCC913D25; Tue, 21 Nov 2017 17:44:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sigsegv.be; s=mail; t=1511282692; bh=Tp7BG8N2QKyNoVqiHqdsMgVdKiPtAJBgSXZOJ++T3So=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RLlEOyEou2GaQzxaehPDGG3NGjDl4aCER5yNsiVnPbq/m5tdDmWbP1uvjBk6SVuRa xM+ysUBeorvtfrAnRC9EJLhOx77XBfcq1+p4zQwomK7iK9pnuJlkILjsGB+b0Z7fli PMSQ0CC/HTp7zpRXGyswRoAGNd8mH2PfSsOVWlSg= From: "Kristof Provost" To: "Catalin Salgau" Cc: freebsd-net@freebsd.org Subject: Re: BPF packet pagesize limit Date: Tue, 21 Nov 2017 17:44:59 +0100 Message-ID: <65E7BF88-EBEA-47DA-806B-5BFD6783F2B4@sigsegv.be> In-Reply-To: References: <966f384c-10b4-d018-efb1-68a7064c9521@users.sourceforge.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailer: MailMate (2.0BETAr6096) X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Nov 2017 16:44:54 -0000 On 21 Nov 2017, at 17:14, Catalin Salgau wrote: > Actually m_getm2() will always produce a chain for a size larger than > the page size, due to m_getjcl() being called with MJUMPAGESIZE every > time a large buffer is requested. The function could probably be > called > with MJUM9BYTES in this case, but this should be dependant on backing > interface configuration(?). I’d be tempted to just always allocate MJUM9BYTES, but that’s wasteful of memory. I believe the most common use case for this code is the DHCP client, where large packets are not a requirement. There doesn’t seem to be an obvious way to allocate a contiguous mbuf, other than allocating the memory yourself, and creating an M_EXT mbuf. Some care must be taken to ensure the memory is correctly freed, but at first glance that looks possible. > On the other hand, as you pointed out, bpf_filter really needs a > single > mbuf, and so does the call to uiomove(). The filter call, as it > stands, > will overread due to being passed the larger len value, instead of the > mbuf's len. > As a note, to avoid the overruns and related panics, I'd suggest > anyone > else trying this replace the assertion with an explicit > if (m->m_next != NULL) { > error = EIO; > goto bad; > } > Yes, that would be better. Regards, Kristof