From nobody@FreeBSD.org  Sat Feb 23 14:59:56 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A0A7016A406
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 23 Feb 2008 14:59:56 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 8770213C447
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 23 Feb 2008 14:59:56 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m1NEvHww040536
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 23 Feb 2008 14:57:17 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m1NEvHxh040535;
	Sat, 23 Feb 2008 14:57:17 GMT
	(envelope-from nobody)
Message-Id: <200802231457.m1NEvHxh040535@www.freebsd.org>
Date: Sat, 23 Feb 2008 14:57:17 GMT
From: Joerg Wallerich <joerg@net.t-labs.tu-berlin.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: alignment violation in chap module of ppp(8) causes bus error on ARM
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         120994
>Category:       bin
>Synopsis:       [patch] alignment violation in chap module of ppp(8) causes bus error on ARM
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 23 15:00:07 UTC 2008
>Closed-Date:    
>Last-Modified:  Sat Feb 23 23:28:50 UTC 2008
>Originator:     Joerg Wallerich
>Release:        RELENG_7
>Organization:
>Environment:
FreeBSD avila 7.0-PRERELEASE FreeBSD 7.0-PRERELEASE #12: Sat Feb 23 05:03:12 CET 2008     root@sulaco:/usr/obj/arm/usr/src/sys/AVILA.router  arm

>Description:
The chap code in ppp(8) provides a target buffer to MD5Final()
that is not word aligned. This leads to a bus error in libmd while
computing a response to the CHAP challenge string.
>How-To-Repeat:
Authenticate a ppp/pppoe session unsing CHAP
>Fix:
Provide a temporary word aligned buffer to store the MD5 hash
and copy the hash into the CHAP response string using memcpy().

Patch attached with submission follows:

Index: chap.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/ppp/chap.c,v
retrieving revision 1.86
diff -c -r1.86 chap.c
*** chap.c	5 Sep 2004 01:46:51 -0000	1.86
--- chap.c	23 Feb 2008 14:51:45 -0000
***************
*** 130,135 ****
--- 130,136 ----
                  )
  {
    char *result, *digest;
+   char *tmpbuf;
    size_t nlen, klen;
  
    nlen = strlen(name);
***************
*** 232,237 ****
--- 233,239 ----
      /* Normal MD5 stuff */
      MD5_CTX MD5context;
  
+     tmpbuf = malloc(nlen + 17);
      digest = result;
      *digest++ = 16;				/* value size */
  
***************
*** 239,247 ****
      MD5Update(&MD5context, &id, 1);
      MD5Update(&MD5context, key, klen);
      MD5Update(&MD5context, challenge + 1, *challenge);
!     MD5Final(digest, &MD5context);
  
      memcpy(digest + 16, name, nlen);
      /*
       *           ---- -------- ------
       * result = | 16 | digest | name |
--- 241,251 ----
      MD5Update(&MD5context, &id, 1);
      MD5Update(&MD5context, key, klen);
      MD5Update(&MD5context, challenge + 1, *challenge);
!     MD5Final(tmpbuf, &MD5context);
  
+     memcpy(digest, tmpbuf, 16);
      memcpy(digest + 16, name, nlen);
+     free(tmpbuf);
      /*
       *           ---- -------- ------
       * result = | 16 | digest | name |


>Release-Note:
>Audit-Trail:
>Unformatted:
