NetBSD Problem Report #51952
From brad.harder@gmail.com Sun Feb 5 20:50:17 2017
Return-Path: <brad.harder@gmail.com>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id A1C687A1AE
for <gnats-bugs@gnats.NetBSD.org>; Sun, 5 Feb 2017 20:50:17 +0000 (UTC)
Message-Id: <CABfrOT-NHSF003PUCKz=21_5QSEKbJzA6j+QnX92ztCiuMhEvQ@mail.gmail.com>
Date: Sun, 5 Feb 2017 12:50:14 -0800
From: bch <brad.harder@gmail.com>
Reply-To:
To: gnats-bugs@netbsd.org
Subject: libpcap fault applying filter to unactivated handle
>Number: 51952
>Category: lib
>Synopsis: libpcap will fault if an attempt to apply a filter on non-activated handle occurs.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Feb 05 20:55:00 +0000 2017
>Closed-Date: Tue Aug 15 15:51:02 +0000 2017
>Last-Modified: Tue Aug 15 15:51:02 +0000 2017
>Originator: bch <brad.harder@gmail.com>
>Release: NetBSD 7.99.59
>Organization:
method logic digital
>Environment:
System: NetBSD kamloops 7.99.59 NetBSD 7.99.59 (MODULAR) #51: Sun Feb
5 09:44:00 PST 2017
root@kamloops:/usr/src/sys/arch/amd64/compile/obj/MODULAR amd64
Architecture: x86_64
Machine: amd64
>Description:
libpcap faults if one tries to apply a filter to an unactivated pcap handle.
>How-To-Repeat:
...
char errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program fp;
pcap_t *handle = pcap_create("wm0", errbuf);
pcap_compile(handle, &fp, "port 80", 0, PCAP_NETMASK_UNKNOWN); /* not
yet activated... */
// segfault in freechunks()
>Fix:
The compiler state "chunks" initialization is short-circuited if
the handle is not activated, but the chunks cleanup is unconditional.
Unconditionally initializing allows cleanup in case of error-state
to happen fault-free.
nb: patch already submitted upstream to the-tcpdump-group.
FIX
===
--- ./external/bsd/libpcap/dist/gencode.old 2017-02-05
12:34:30.181700021 -0800
+++ ./external/bsd/libpcap/dist/gencode.c 2017-02-05
12:35:03.506099929 -0800
@@ -688,13 +688,13 @@
* If this pcap_t hasn't been activated, it doesn't have a
* link-layer type, so we can't use it.
*/
+ initchunks(&cstate);
if (!p->activated) {
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"not-yet-activated pcap_t passed to pcap_compile");
rc = -1;
goto quit;
}
- initchunks(&cstate);
cstate.no_optimize = 0;
cstate.ai = NULL;
cstate.ic.root = NULL;
>Release-Note:
>Audit-Trail:
From: bch <brad.harder@gmail.com>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: lib/51952: libpcap fault applying filter to unactivated handle
Date: Sun, 5 Feb 2017 13:24:43 -0800
This was fixed alternatively upstream by (roughly):
kamloops# diff -bu ./external/bsd/libpcap/dist/gencode.old
./external/bsd/libpcap/dist/gencode.c
kamloops# diff -bu ./external/bsd/libpcap/dist/gencode.old
./external/bsd/libpcap/dist/gencode.c
--- ./external/bsd/libpcap/dist/gencode.old 2017-02-05
12:34:30.181700021 -0800
+++ ./external/bsd/libpcap/dist/gencode.c 2017-02-05
13:13:35.332722415 -0800
@@ -691,8 +691,7 @@
if (!p->activated) {
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"not-yet-activated pcap_t passed to pcap_compile");
- rc = -1;
- goto quit;
+ return -1;
}
initchunks(&cstate);
cstate.no_optimize = 0;
ref: https://github.com/the-tcpdump-group/libpcap/commit/ada95c9321eab3793d485ca026cda54afca9d541
On 2/5/17, gnats-admin@netbsd.org <gnats-admin@netbsd.org> wrote:
> Thank you very much for your problem report.
> It has the internal identification `lib/51952'.
> The individual assigned to look at your
> report is: lib-bug-people.
>
>>Category: lib
>>Responsible: lib-bug-people
>>Synopsis: libpcap will fault if an attempt to apply a filter on
>> non-activated handle occurs.
>>Arrival-Date: Sun Feb 05 20:55:00 +0000 2017
>
>
From: "Brian Ginsbach" <ginsbach@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51952 CVS commit: src/external/bsd/libpcap/dist
Date: Sat, 12 Aug 2017 00:43:25 +0000
Module Name: src
Committed By: ginsbach
Date: Sat Aug 12 00:43:25 UTC 2017
Modified Files:
src/external/bsd/libpcap/dist: gencode.c
Log Message:
PR lib/51952: Brad Harder: Apply upstream ada959c9
[From upstream tcpdump]
In pcap_compile(), first check whether the pcap_t is activated.
Before we allocate or otherwise set up anything, check whether the
pcap_t is activated, and set the error message string and return -1 if
it's not.
That way, we don't go through the cleanup code in that code path -
there's nothing to clean up.
Fixes the issue in GitHub pull request #552.
XXX: pullup-8
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/external/bsd/libpcap/dist/gencode.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->pending-pullups
State-Changed-By: ginsbach@NetBSD.org
State-Changed-When: Sat, 12 Aug 2017 01:34:02 +0000
State-Changed-Why:
Pullup requested for NetBSD 8.
From: "Soren Jacobsen" <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51952 CVS commit: [netbsd-8] src/external/bsd/libpcap/dist
Date: Mon, 14 Aug 2017 23:56:35 +0000
Module Name: src
Committed By: snj
Date: Mon Aug 14 23:56:35 UTC 2017
Modified Files:
src/external/bsd/libpcap/dist [netbsd-8]: gencode.c
Log Message:
Pull up following revision(s) (requested by ginsbach in ticket #209):
external/bsd/libpcap/dist/gencode.c: revision 1.10
PR lib/51952: Brad Harder: Apply upstream ada959c9
[From upstream tcpdump]
In pcap_compile(), first check whether the pcap_t is activated.
Before we allocate or otherwise set up anything, check whether the
pcap_t is activated, and set the error message string and return -1 if
it's not.
That way, we don't go through the cleanup code in that code path -
there's nothing to clean up.
Fixes the issue in GitHub pull request #552.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.9.4.1 src/external/bsd/libpcap/dist/gencode.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: pending-pullups->closed
State-Changed-By: ginsbach@NetBSD.org
State-Changed-When: Tue, 15 Aug 2017 15:51:02 +0000
State-Changed-Why:
Fixed in current and pulled up to netbsd-8.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.