Re: tcpdump core's on the latest snapshot

2022-02-13 Thread Mikhail
On Sun, Feb 13, 2022 at 12:54:19PM +0100, Otto Moerbeek wrote:
> I can see two problems:
> 
> 1. setjump returning 1
> 2. freechunks() segfaulting.
> 
> Here I'll concentrate on 2), as I suspect 1) has a cause that is already in
> the process of being diagnosed/fixed elsewhere.

The patch works - no segfault and proper error message is printed, thank
you.



Re: tcpdump core's on the latest snapshot

2022-02-13 Thread Otto Moerbeek
On Sun, Feb 13, 2022 at 12:54:19PM +0100, Otto Moerbeek wrote:

> On Sun, Feb 13, 2022 at 01:12:34PM +0300, Mikhail wrote:
> 
> > Running this command on the latest snapshot produces core file for me:
> > 
> > doas tcpdump -i urtwn0 proto ip6

BTW, the proper way to filter ipv6 packets is either

doas tcpdump -i urtwn0 ip6

or 

doas tcpdump -i urtwn0 ether proto 0x86dd 

The ethernet protocol numbers are defined in /usr/include/net/ethertypes.h

-Otto



Re: tcpdump core's on the latest snapshot

2022-02-13 Thread Otto Moerbeek
On Sun, Feb 13, 2022 at 01:12:34PM +0300, Mikhail wrote:

> Running this command on the latest snapshot produces core file for me:
> 
> doas tcpdump -i urtwn0 proto ip6
> 
> Core details:
> 
> misha:/home/misha:3959$ doas lldb --core tcpdump.core tcpdump
> (lldb) target create "tcpdump" --core "tcpdump.core"
> Core file '/home/misha/tcpdump.core' (x86_64) was loaded.
> (lldb) bt
> * thread #1, stop reason = signal SIGSEGV
>   * frame #0: 0x07b299d82607 libpcap.so.9.0`pcap_compile [inlined] 
> freechunks at gencode.c:209:9
> frame #1: 0x07b299d825c2 libpcap.so.9.0`pcap_compile(p=, 
> program=, buf=, optimize=, 
> mask=) at gencode.c:287:3
> frame #2: 0x07aff4d7a74f tcpdump`___lldb_unnamed_symbol311 + 159
> frame #3: 0x07aff4d783a6 tcpdump`___lldb_unnamed_symbol286 + 3510
> frame #4: 0x07aff4d73f61 tcpdump`___lldb_unnamed_symbol259 + 97
> frame #5: 0x07aff4d73b32 tcpdump`___lldb_unnamed_symbol253 + 290
> 
> It looks like setjmp() call on gencode.c:286 returns "1", while the man
> page says it must return only "0".

I can see two problems:

1. setjump returning 1
2. freechunks() segfaulting.

Here I'll concentrate on 2), as I suspect 1) has a cause that is already in
the process of being diagnosed/fixed elsewhere.

The offensding statement is:

#0  0x002428da032c in freechunks () at /usr/src/lib/libpcap/gencode.c:209
209 free(membag[i].ptrs[j]);
(gdb) print membag
$1 = {{total = 0, slot = 0, ptrs = 0x0} }

It looks like this happens when no allocation has happened at all.

The diff below fixes the core dump for me.

-Otto

Index: gencode.c
===
RCS file: /cvs/src/lib/libpcap/gencode.c,v
retrieving revision 1.59
diff -u -p -r1.59 gencode.c
--- gencode.c   5 Dec 2021 16:40:24 -   1.59
+++ gencode.c   13 Feb 2022 11:52:55 -
@@ -205,6 +205,8 @@ freechunks(void)
int i, j;
 
for (i = 0; i <= cur_membag; i++) {
+   if (membag[i].ptrs == NULL)
+   continue;
for (j = 0; j <= membag[i].slot; j++)
free(membag[i].ptrs[j]);
free(membag[i].ptrs);



tcpdump core's on the latest snapshot

2022-02-13 Thread Mikhail
Running this command on the latest snapshot produces core file for me:

doas tcpdump -i urtwn0 proto ip6

Core details:

misha:/home/misha:3959$ doas lldb --core tcpdump.core tcpdump
(lldb) target create "tcpdump" --core "tcpdump.core"
Core file '/home/misha/tcpdump.core' (x86_64) was loaded.
(lldb) bt
* thread #1, stop reason = signal SIGSEGV
  * frame #0: 0x07b299d82607 libpcap.so.9.0`pcap_compile [inlined] 
freechunks at gencode.c:209:9
frame #1: 0x07b299d825c2 libpcap.so.9.0`pcap_compile(p=, 
program=, buf=, optimize=, 
mask=) at gencode.c:287:3
frame #2: 0x07aff4d7a74f tcpdump`___lldb_unnamed_symbol311 + 159
frame #3: 0x07aff4d783a6 tcpdump`___lldb_unnamed_symbol286 + 3510
frame #4: 0x07aff4d73f61 tcpdump`___lldb_unnamed_symbol259 + 97
frame #5: 0x07aff4d73b32 tcpdump`___lldb_unnamed_symbol253 + 290

It looks like setjmp() call on gencode.c:286 returns "1", while the man
page says it must return only "0".

Dmesg:

OpenBSD 7.0-current (GENERIC.MP) #298: Mon Jan 31 13:42:43 MST 2022
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 4117065728 (3926MB)
avail mem = 3975090176 (3790MB)
random: good seed from bootblocks
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xdae9d000 (65 entries)
bios0: vendor LENOVO version "H0ET96WW (2.56 )" date 06/12/2015
bios0: LENOVO 3259KNG
acpi0 at bios0: ACPI 5.0
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SSDT SSDT ASF! HPET APIC MCFG FPDT SSDT SSDT UEFI UEFI 
POAT UEFI DBG2
acpi0: wakeup devices P0P1(S4) EHC1(S3) EHC2(S3) XHC_(S3) HDEF(S3) RP01(S4) 
PXSX(S4) RP02(S4) PXSX(S4) RP03(S4) PXSX(S4) RP04(S4) PXSX(S5) RP05(S4) 
PXSX(S4) RP06(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz, 2494.70 MHz, 06-3a-09
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.1.2, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz, 2494.33 MHz, 06-3a-09
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: disabling user TSC (skew=116)
cpu1: smt 1, core 0, package 0
cpu2 at mainbus0: apid 2 (application processor)
cpu2: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz, 2494.34 MHz, 06-3a-09
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 1, package 0
cpu3 at mainbus0: apid 3 (application processor)
cpu3: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz, 2494.33 MHz, 06-3a-09
cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 1, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 24 pins
acpimcfg0 at acpi0
acpimcfg0: addr 0xf800, bus 0-63
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (P0P1)
acpiprt2 at acpi0: bus 2 (RP01)
acpiprt3 at acpi0: bus 3 (RP02)
acpiprt4 at acpi0: bus 4 (RP03)
acpiprt5 at acpi0: bus 12 (RP04)
acpiprt6 at acpi0: bus -1 (RP05)
acpiprt7 at acpi0: bus -1 (RP06)
acpiprt8 at acpi0: bus -1 (RP07)
acpiprt9 at acpi0: bus -1 (RP08)
acpiprt10 at acpi0: bus -1 (PEG0)
acpiprt11 at acpi0: bus -1 (PEG1)
acpiprt12 at acpi0: bus -1 (PEG2)
acpiprt13 at acpi0: bus -1 (PEG3)
acpiec0 at acpi0
acpipci0 at acpi0 PCI0: 0x0004 0x0011 0x0001
acpicmos0 at acpi0
acpithinkpad0 at acpi0: