NetBSD Problem Report #55599

From www@netbsd.org  Sun Aug 23 01:33:19 2020
Return-Path: <www@netbsd.org>
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 5548C1A923D
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 23 Aug 2020 01:33:19 +0000 (UTC)
Message-Id: <20200823013317.740571A9249@mollari.NetBSD.org>
Date: Sun, 23 Aug 2020 01:33:17 +0000 (UTC)
From: uwe@stderr.spb.ru
Reply-To: uwe@stderr.spb.ru
To: gnats-bugs@NetBSD.org
Subject: libpcap gets SIGBUS on strictly aligned CPUs
X-Send-Pr-Version: www-1.0

>Number:         55599
>Category:       lib
>Synopsis:       libpcap gets SIGBUS on strictly aligned CPUs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 23 01:35:00 +0000 2020
>Last-Modified:  Sat Aug 29 15:10:01 +0000 2020
>Originator:     Valery Ushakov
>Release:        NetBSD current
>Organization:
>Environment:
NetBSD felix 9.99.71 NetBSD 9.99.71 (FELIX) #0: Sun Aug 23 02:32:34 MSK 2020  uwe@majava:/home/uwe/work/netbsd/cvs/src/sys/arch/landisk/compile/FELIX landisk
>Description:
libpcap imported on 2019/10/01 gets SIGBUS trying to compile some
filter expressions.

In gencode.c in gen_bcmp():

-		bpf_int32 w = ((bpf_int32)p[0] << 24) |
-		    ((bpf_int32)p[1] << 16) | ((bpf_int32)p[2] << 8) | p[3];

-		tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W, w);
+		tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W,
+		    (bpf_int32)EXTRACT_32BITS(p));

where EXTRACT_32BITS is defined in extract.h and the definition
depends on LBL_ALIGN (defined "if unaligned access fails").
Unfortunately we ship pregenerated config.h that has

/* #undef LBL_ALIGN */

So when you try e.g.

    tcpdump ether host xx:...:xx

that code tries to access unaligned 32-bit value.  I see that on sh3
and macallan@ confirmed he sees that on sparc64.

In arm unaligned accesses don't necessarily SIGBUS but do weird
things, so there the bug will be less obvious.

I originally ran into this trying to run wpa_supplicant which uses a
filter expression with ether src/dst and crashes.


>How-To-Repeat:
# tcpdump ether host xx:...:xx

>Fix:
I'm not sure what a good fix might be.  We can either always define
LBL_ALIGN as we do e.g. for tcpdump.  We can provide -DLBL_ALIGN from
Makefile.inc .if the cpu is strictly aligned.  We can also do #ifdef
dance in the pregenerated config.h which is a bit more hassle during
the import but doesn't rely on magic in the makefiles and so is
preferrable, IMO.  The same fix probably need to be applied to tcpdump
then too.

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55599 CVS commit: src/external/bsd/libpcap
Date: Sat, 29 Aug 2020 11:05:34 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sat Aug 29 15:05:33 UTC 2020

 Modified Files:
 	src/external/bsd/libpcap: Makefile.inc

 Log Message:
 PR/55599: Valery Ushakov: libpcap gets SIGBUS on strictly aligned CPUs
 Define LBL_ALIGN as suggested


 To generate a diff of this commit:
 cvs rdiff -u -r1.1 -r1.2 src/external/bsd/libpcap/Makefile.inc

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(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.