NetBSD Problem Report #55143
From martin@aprisoft.de Sun Apr 5 06:20:46 2020
Return-Path: <martin@aprisoft.de>
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 "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 30F671A9213
for <gnats-bugs@gnats.NetBSD.org>; Sun, 5 Apr 2020 06:20:46 +0000 (UTC)
Message-Id: <20200405062036.47F6C5CC803@emmas.aprisoft.de>
Date: Sun, 5 Apr 2020 08:20:36 +0200 (CEST)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: pflogd uses internal libpcap state
X-Send-Pr-Version: 3.95
>Number: 55143
>Category: lib
>Synopsis: pflogd uses internal libpcap state
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: lib-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Apr 05 06:25:00 +0000 2020
>Closed-Date: Sun Apr 05 06:29:57 +0000 2020
>Last-Modified: Sun Apr 05 06:29:57 +0000 2020
>Originator: Martin Husemann
>Release: NetBSD 9.99.52
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD seven-days-to-the-wolves.aprisoft.de 9.99.52 NetBSD 9.99.52 (GENERIC) #378: Tue Mar 31 11:09:27 CEST 2020 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
Pflogd is compiled against libpcap:
/sbin/pflogd:
-lpcap.8 => /lib/libpcap.so.8
-lc.12 => /lib/libc.so.12
-lutil.7 => /lib/libutil.so.7
and it abuses internal state from it, noticable if you remove the include of
(the not publically installed header) pcap-int.h from the source:
/work/src/dist/pf/sbin/pflogd/privsep.c: In function 'set_snaplen':
/work/src/dist/pf/sbin/pflogd/privsep.c:200:7: error: dereferencing pointer to incomplete type 'pcap_t' {aka 'struct pcap'}
hpcap->snapshot = snap;
^~
Now unfortunately libpcap has an #ifdef ENABLE_REMOTE in that struct, and
it is not defined when compiling pflogd, but is compiled when compiling
our in-tree libpcap.
This means the pcap_t seen by pflogd differs from the pcap_t actually created
and populated by libpcap. And even more unfortunate, the "snapshot" member
is later in the structure than the #ifdef'd part, so pflogd will actually
set hpcap->linktype_ext instead of hpcap->snapshot.
>How-To-Repeat:
Code inspection (actually found by a #else #error added to pcap-int.h and
the #ifdef ENABLE_REMOTE clause)
>Fix:
One of:
1) avoid using pcap internal state in pflogd (unfortunately there seems to
be only a query function for snapshot, not a set function)
2) add -DENABLE_REMOTE to the pflogd compilation
3) remove the #ifdef from pcap-int.h
4) remove pflogd
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Sun, 05 Apr 2020 06:29:57 +0000
State-Changed-Why:
Christos applied suggestion #3 already
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.