From owner-freebsd-arm@FreeBSD.ORG Tue Dec 24 19:10:00 2013 Return-Path: Delivered-To: freebsd-arm@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9E7DB7A1 for ; Tue, 24 Dec 2013 19:10:00 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 76DF5188E for ; Tue, 24 Dec 2013 19:10:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id rBOJA0aS077077 for ; Tue, 24 Dec 2013 19:10:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id rBOJA0FO077076; Tue, 24 Dec 2013 19:10:00 GMT (envelope-from gnats) Resent-Date: Tue, 24 Dec 2013 19:10:00 GMT Resent-Message-Id: <201312241910.rBOJA0FO077076@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-arm@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Guy Yur Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0E85F780 for ; Tue, 24 Dec 2013 19:05:54 +0000 (UTC) Received: from mail-ee0-x22d.google.com (mail-ee0-x22d.google.com [IPv6:2a00:1450:4013:c00::22d]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9A6D0187D for ; Tue, 24 Dec 2013 19:05:53 +0000 (UTC) Received: by mail-ee0-f45.google.com with SMTP id d49so3024098eek.4 for ; Tue, 24 Dec 2013 11:05:52 -0800 (PST) Received: from vm8.localdomain ([37.46.46.133]) by mx.google.com with ESMTPSA id j46sm57381005eew.18.2013.12.24.11.05.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 24 Dec 2013 11:05:51 -0800 (PST) Received: by vm8.localdomain (sSMTP sendmail emulation); Tue, 24 Dec 2013 21:05:38 +0200 Message-Id: <52b9db0f.c6310f0a.32b1.ffffd436@mx.google.com> Date: Tue, 24 Dec 2013 21:05:38 +0200 From: Guy Yur To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.114 Subject: arm/185165: net/mpd5 crashes in NgMkSockNode due to stack alignment on ARM EABI X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: Guy Yur List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Dec 2013 19:10:00 -0000 >Number: 185165 >Category: arm >Synopsis: net/mpd5 crashes in NgMkSockNode due to stack alignment on ARM EABI >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-arm >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Dec 24 19:10:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Guy Yur >Release: FreeBSD 10.0-RC1 arm >Organization: >Environment: System: FreeBSD bbb.localdomain 10.0-RC1 FreeBSD 10.0-RC1 #1 r259250M: Thu Dec 12 22:54:08 IST 2013 root@vm8.localdomain:/usr/obj/arm.armv6/usr/src/sys/BBB arm >Description: I am running 10.0-RC1 on the BeagleBone Black and the net/mpd5 port is crashing in libnetgraph NgMkSockNode due to stack alignment. 10.0-RC1 World and kernel were compiled in a VirtualBox VM running 9.2-RELEASE-p2 i386. clang and ARM_EABI used as the default make options. Added prints in NgMkSockNode show rbuf is aligned on 2-byte and not 4-byte which is needed to access ni->id (a uint32_t). ni = 0xbfffe87a rbuf = 0xbfffe842 sizeof(resp->header) = 56 (gdb) bt #0 0x201529a0 in NgMkSockNode (name=, csp=0xbfffe95c, dsp=0xbfffe958) at /usr/src/lib/libnetgraph/sock.c:134 #1 0x00037b9c in MppcTestCap () at ccp_mppc.c:754 #2 0x0007c1f4 in main (ac=4, av=0xbfffeb90) at main.c:248 #3 0x0000d1b0 in __start (argc=4, argv=0xbfffeb90, env=0xbfffeba4, ps_strings=, obj=, cleanup=) at /usr/src/lib/csu/arm/crt1.c:115 #4 0x203e9dc0 in _thr_ast (curthread=0x200fd000) at /usr/src/lib/libthr/thread/thr_sig.c:265 Putting rbuf in a union with struct ng_mesg sorted the alignment to 4-byte and mpd5 didn't crash. I attached the changes I used to test mpd5 doesn't crash with correct alignment. >How-To-Repeat: Install and run the net/mpd5 port on arm using ARM EABI. >Fix: --- sock-NgMkSockNode.patch begins here --- Index: lib/libnetgraph/sock.c =================================================================== --- lib/libnetgraph/sock.c (revision 259250) +++ lib/libnetgraph/sock.c (working copy) @@ -111,9 +111,12 @@ /* Save node name */ strlcpy(namebuf, name, sizeof(namebuf)); } else if (dsp != NULL) { - u_char rbuf[sizeof(struct ng_mesg) + sizeof(struct nodeinfo)]; - struct ng_mesg *const resp = (struct ng_mesg *) rbuf; - struct nodeinfo *const ni = (struct nodeinfo *) resp->data; + union { + u_char rbuf[sizeof(struct ng_mesg) + + sizeof(struct nodeinfo)]; + struct ng_mesg res; + } res; + struct nodeinfo *const ni = (struct nodeinfo *) res.res.data; /* Find out the node ID */ if (NgSendMsg(cs, ".", NGM_GENERIC_COOKIE, @@ -123,7 +126,7 @@ NGLOG("send nodeinfo"); goto errout; } - if (NgRecvMsg(cs, resp, sizeof(rbuf), NULL) < 0) { + if (NgRecvMsg(cs, &res.res, sizeof(res.rbuf), NULL) < 0) { errnosv = errno; if (_gNgDebugLevel >= 1) NGLOG("recv nodeinfo"); --- sock-NgMkSockNode.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: