From patchwork Thu Dec 15 11:56:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 88136 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp748126qgi; Thu, 15 Dec 2016 03:56:50 -0800 (PST) X-Received: by 10.99.56.82 with SMTP id h18mr1469985pgn.55.1481803010594; Thu, 15 Dec 2016 03:56:50 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id f15si2171619plm.7.2016.12.15.03.56.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Dec 2016 03:56:50 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-75913-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-75913-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-75913-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=v2++j5yaMkpCuL8Z6R3iNzOZkOtRbtpipIolJpFFtgVkvMovT1Ypl QuJOkowBhgm3jDM7SXgzHl77qilecVrE1rcDnX95Ml7seNQ09AvXjgWfOIkG8Y7n Ro5zFJGTxOW2T2HtozcixggiWy3PSsGEmrYy3tmGTUeal9VtcTD4XA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=g0eGScm4IrzxoMGsIn9yeV5gL3w=; b=sQkF+agQGVmFa5LJPnhJHD+7kv+z Fg8xsfgAiD2ijX2QAxaktDVTuKH60bs3Gs/xEeOtPyI/Eoe2lGxVtnyJc/2T9B5S y7ke+CvPgrCUvq8osGOqvw23s9YNmQ571ucObpOqhgvjayaZ8ow+EYNoMmeOFLtW BFFw5Bro5EOhybw= Received: (qmail 12608 invoked by alias); 15 Dec 2016 11:56:41 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 12596 invoked by uid 89); 15 Dec 2016 11:56:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=Hx-languages-length:1521, r7, r7, r6, r6, r3, r7, cmpldi X-HELO: mail-vk0-f41.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Ej3Uo7G4ZA0AE6S01MbyxpTMO/ZRA+IhXb7LlOpN0GU=; b=i7gHVUO2yrxOZ5lcZllhR1Pk2o8bqhZseKa3tA4Luj7Cy7liPkH2zNXtZyKoMemygx UlqS/Uoad+6V+yyZgWNvvvusJ4saRQ3pZrUKl8X0F1w8bkFlwmDju3wD+wVTDfNg149m cKL3fDRzTZqGjO+VcndIoCPcnIb6InrvrgMqmHB5erBHW3aWfwMFyoJrWq5bGS6y1AJp G6x/4dSvazQ6Ga1JrtUO8dK8GYNwgDXO1u/4AxukAdMwhzDIIvU8O1fGeHZC9DC7aPjd U5gecBM8RbvgubgJe9vJYDjK0nZpfx3xCKYW5uO6VZMbqrvoWE+qkT0waEQBGKKXRvyH 65Cg== X-Gm-Message-State: AKaTC00eTJRCRVhitZu/jv8+xZ/B4ZEWAe62Oub8qmP/lQb45H59Og50XYuE2zfNrl6DLqkG X-Received: by 10.31.134.77 with SMTP id i74mr369998vkd.57.1481802988653; Thu, 15 Dec 2016 03:56:28 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] Fix powerpc64/power7 memchr for large input sizes Date: Thu, 15 Dec 2016 09:56:19 -0200 Message-Id: <1481802979-4302-1-git-send-email-adhemerval.zanella@linaro.org> Current optimized powercp64/power7 memchr uses a strategy to check for p versus align(p+n) (where 'p' is the input char pointer and n the maximum size to check for the byte) without taking care for possible overflow on the pointer addition in case of large 'n'. It was triggered by 3038145ca23 where default rawmemchr (used to created ppc64 rawmemchr in ifunc selection) now uses memchr (p, c, (size_t)-1) on its implementation. This patch fixes it by implement a satured addition where overflows sets the maximum pointer size to UINTPTR_MAX. Checked on powerpc64le-linux-gnu. [BZ# 20971] * sysdeps/powerpc/powerpc64/power7/memchr.S (__memchr): Avoid overflow in pointer addition. --- ChangeLog | 6 ++++++ sysdeps/powerpc/powerpc64/power7/memchr.S | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/sysdeps/powerpc/powerpc64/power7/memchr.S b/sysdeps/powerpc/powerpc64/power7/memchr.S index 03f0d7c..14059e2 100644 --- a/sysdeps/powerpc/powerpc64/power7/memchr.S +++ b/sysdeps/powerpc/powerpc64/power7/memchr.S @@ -26,7 +26,17 @@ ENTRY (__memchr) dcbt 0,r3 clrrdi r8,r3,3 insrdi r4,r4,8,48 - add r7,r3,r5 /* Calculate the last acceptable address. */ + + /* Calculate the last acceptable address and check for possible + addition overflow by using satured math: + r7 = r3 + r5 + r7 |= -(r7 < x) */ + add r7,r3,r5 + subfc r6,r3,r7 + subfe r9,r9,r9 + extsw r6,r9 + or r7,r7,r6 + insrdi r4,r4,16,32 cmpldi r5,32 li r9, -1