From owner-svn-src-all@FreeBSD.ORG Thu Feb 27 02:36:10 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0164B6B; Thu, 27 Feb 2014 02:36:10 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (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 E153018FC; Thu, 27 Feb 2014 02:36:09 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s1R2a9Bp047043; Thu, 27 Feb 2014 02:36:09 GMT (envelope-from davidxu@svn.freebsd.org) Received: (from davidxu@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s1R2a9kN047042; Thu, 27 Feb 2014 02:36:09 GMT (envelope-from davidxu@svn.freebsd.org) Message-Id: <201402270236.s1R2a9kN047042@svn.freebsd.org> From: David Xu Date: Thu, 27 Feb 2014 02:36:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r262544 - stable/10/libexec/rtld-elf X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Feb 2014 02:36:10 -0000 Author: davidxu Date: Thu Feb 27 02:36:09 2014 New Revision: 262544 URL: http://svnweb.freebsd.org/changeset/base/262544 Log: MFC r262277: malloc_aligned() may not leave enough space for pointer to allocated memory, saving the pointer will overwrite bytes belongs to another memory block unexpectly, to fix the problem, use (allocated address + sizeof(void *)) as initial value, and slip to next aligned address, so maximum extra bytes is sizeof(void *) + align - 1. Tested by: Andre Albsmeier < mail at ma17 dot ata dot myota dot orgndre > MFC r262334: Increase alignment to size of pointer if the alignment is too small. Some modules do not align data at least to size of pointer, they uses a smaller alignment, but our pointer should be aligned to its native boundary, otherwise on some platforms, hardware alignment checking will cause bus error. Modified: stable/10/libexec/rtld-elf/xmalloc.c Directory Properties: stable/10/ (props changed) Modified: stable/10/libexec/rtld-elf/xmalloc.c ============================================================================== --- stable/10/libexec/rtld-elf/xmalloc.c Thu Feb 27 01:24:47 2014 (r262543) +++ stable/10/libexec/rtld-elf/xmalloc.c Thu Feb 27 02:36:09 2014 (r262544) @@ -72,14 +72,12 @@ void * malloc_aligned(size_t size, size_t align) { void *mem, *res; - uintptr_t x; - size_t asize, r; - r = round(sizeof(void *), align); - asize = round(size, align) + r; - mem = xmalloc(asize); - x = (uintptr_t)mem; - res = (void *)round(x, align); + if (align < sizeof(void *)) + align = sizeof(void *); + + mem = xmalloc(size + sizeof(void *) + align - 1); + res = (void *)round((uintptr_t)mem + sizeof(void *), align); *(void **)((uintptr_t)res - sizeof(void *)) = mem; return (res); }