Bug 185165 - [patch] net/mpd5 crashes in NgMkSockNode due to stack alignment on ARM EABI
Summary: [patch] net/mpd5 crashes in NgMkSockNode due to stack alignment on ARM EABI
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: John-Mark Gurney
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-24 19:10 UTC by guyyur
Modified: 2018-09-22 23:59 UTC (History)
1 user (show)

See Also:
bugmeister: mfc-stable10?
bugmeister: mfc-stable9?
bugmeister: mfc-stable8?


Attachments
sock-NgMkSockNode.patch (1016 bytes, patch)
2013-12-24 19:10 UTC, guyyur
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description guyyur 2013-12-24 19:10:00 UTC
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=<value optimized out>, 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=<value optimized out>, obj=<value optimized out>,
    cleanup=<value optimized out>) 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.
Comment 1 John-Mark Gurney freebsd_committer freebsd_triage 2013-12-24 19:21:25 UTC
Responsible Changed
From-To: freebsd-arm->jmg

I'll commit this patch shortly...
Comment 2 John-Mark Gurney freebsd_committer freebsd_triage 2014-01-07 23:01:12 UTC
State Changed
From-To: open->patched

patched in HEAD as r260418...  Will close once MFC'd...
Comment 3 dfilter service freebsd_committer freebsd_triage 2014-01-07 23:01:16 UTC
Author: jmg
Date: Tue Jan  7 23:01:05 2014
New Revision: 260418
URL: http://svnweb.freebsd.org/changeset/base/260418

Log:
  make sure that rbuf is aligned by making a union w/ the structure we
  need to access...  access the struct through the union too...
  
  PR:		185165
  Submitted by:	Guy Yur
  MFC after:	1 week

Modified:
  head/lib/libnetgraph/sock.c

Modified: head/lib/libnetgraph/sock.c
==============================================================================
--- head/lib/libnetgraph/sock.c	Tue Jan  7 23:00:58 2014	(r260417)
+++ head/lib/libnetgraph/sock.c	Tue Jan  7 23:01:05 2014	(r260418)
@@ -111,9 +111,12 @@ gotNode:
 		/* 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 @@ gotNode:
 				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");
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 4 Eugene Grosbein freebsd_committer freebsd_triage 2017-06-11 14:24:29 UTC
(In reply to John-Mark Gurney from comment #2)

The fix is present in head and stable/11 but was not MFC'd to stable/10. On the other hand, ARM is still Tier 2 platform for FreeBSD and need of MFC to older branches is questionable.

Please either perform MFC to stable/10 or just close this.
Comment 5 Eugene Grosbein freebsd_committer freebsd_triage 2018-09-22 23:59:37 UTC
Fixed long time ago.