From patchwork Wed Mar 11 23:21:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Brodkin X-Patchwork-Id: 449233 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id A416E140119 for ; Thu, 12 Mar 2015 10:21:24 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 720B292112; Wed, 11 Mar 2015 23:21:22 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3nd0oghuhoxN; Wed, 11 Mar 2015 23:21:21 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 0FF04920A7; Wed, 11 Mar 2015 23:21:21 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id E5FB71C1EF7 for ; Wed, 11 Mar 2015 23:21:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id DEA1933267 for ; Wed, 11 Mar 2015 23:21:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bZH0OkkAbhBA for ; Wed, 11 Mar 2015 23:21:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtprelay.synopsys.com (smtprelay.synopsys.com [198.182.47.9]) by silver.osuosl.org (Postfix) with ESMTPS id 730BD31C8B for ; Wed, 11 Mar 2015 23:21:18 +0000 (UTC) Received: from us02secmta1.synopsys.com (us02secmta1.synopsys.com [10.12.235.96]) by smtprelay.synopsys.com (Postfix) with ESMTP id AFE3224E095B; Wed, 11 Mar 2015 16:21:17 -0700 (PDT) Received: from us02secmta1.internal.synopsys.com (us02secmta1.internal.synopsys.com [127.0.0.1]) by us02secmta1.internal.synopsys.com (Service) with ESMTP id 75E514E216; Wed, 11 Mar 2015 16:21:17 -0700 (PDT) Received: from mailhost.synopsys.com (unknown [10.13.184.66]) by us02secmta1.internal.synopsys.com (Service) with ESMTP id 51EE54E214; Wed, 11 Mar 2015 16:21:17 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 44AFF95E; Wed, 11 Mar 2015 16:21:17 -0700 (PDT) Received: from abrodkin-e7440l.internal.synopsys.com (unknown [10.225.15.34]) by mailhost.synopsys.com (Postfix) with ESMTP id 70DBC94D; Wed, 11 Mar 2015 16:21:15 -0700 (PDT) From: Alexey Brodkin To: uclibc@uclibc.org Subject: [PATCH] resolv: fix unaligned tmp buffer corner-case Date: Thu, 12 Mar 2015 02:21:12 +0300 Message-Id: <1426116072-8003-1-git-send-email-abrodkin@synopsys.com> X-Mailer: git-send-email 2.1.0 Cc: Vineet Gupta , Alexey Brodkin X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: uclibc-bounces@uclibc.org Sender: "uClibc" On execution of "inet/gethost_r-align" test I noticed failure due to unaligned access (instaed of 4-byte aligned 1-byte aligned address was attempted to be accessed). Further investigation confirmed this nice and helpful test failure. Following commit removed usage of ALIGN_BUFFER_OFFSET on entry to __read_etc_hosts_r(): http://git.uclibc.org/uClibc/commit/?id=f65e66078b9f4d2d7f0fc336dee36e78fc467c0f So indeed if target architecture doesn't allow unaligned access and provided tmp buffer is not word aligned (and we will deal with pointers which means word-sized data units), then CPU will fail during execution. In case of ARC we'll see "Unaligned access" exception like this: --->8--- # potentially unexpected fatal signal 7. Path: /root/uClibc/test/inet/gethost_r-align CPU: 0 PID: 5514 Comm: gethost_r-align Not tainted 3.13.11 #2 task: 8f42a580 ti: 8f40e000 task.ti: 8f40e000 [ECR ]: 0x00230400 => Misaligned r/w from 0x5fdab341 [EFA ]: 0x5fdab341 [BLINK ]: 0x20032a18 [ERET ]: 0x20032a3c @off 0x12a3c in [/lib/libuClibc-0.9.34-git.so] VMA: 0x20020000 to 0x20062000 [STAT32]: 0x00000086 : U E2 E1 BTA: 0x20046014 SP: 0x5fdab260 FP: 0x00000000 LPS: 0x20046064 LPE: 0x20046068 LPC: 0x00000000 r00: 0x5fdab341 r01: 0x00000005 r02: 0x00000015 r03: 0x00000000 r04: 0x5fdab358 r05: 0x00000000 r06: 0x0a0a0a00 r07: 0x00000000 r08: 0x0000003f r09: 0x20067050 r10: 0x00000000 r11: 0x00000014 r12: 0x00000001 r13: 0x00000000 r14: 0x20060660 r15: 0x20060661 r16: 0x00000006 r17: 0x5fdab371 r18: 0x00000018 r19: 0x5fdab2b4 r20: 0x00020000 r21: 0x00000000 r22: 0x00029068 r23: 0x5fdab371 r24: 0x00010000 r25: 0x00000000 --->8--- To fix this problem we'll re-introduce tmp buffer force alignment before config parser invocation. Signed-off-by: Alexey Brodkin Cc: Vineet Gupta Cc: Waldemar Brodkorb --- libc/inet/resolv.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index cfc1eee..7c678ce 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -1614,7 +1614,7 @@ int __read_etc_hosts_r( sizeof(struct in_addr) #endif ; - int ret = HOST_NOT_FOUND; + int i, ret = HOST_NOT_FOUND; *h_errnop = NETDB_INTERNAL; if (buflen < aliaslen @@ -1626,6 +1626,12 @@ int __read_etc_hosts_r( *result = NULL; return errno; } + + /* make sure pointer is aligned */ + i = ALIGN_BUFFER_OFFSET(buf); + buf += i; + buflen -= i; + /* Layout in buf: * char *alias[MAXTOKENS] = {address, name, aliases...} * char **h_addr_list[1] = {*in[6]_addr, NULL}