From patchwork Tue Mar 14 17:28:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 95305 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp360491qgd; Tue, 14 Mar 2017 10:28:28 -0700 (PDT) X-Received: by 10.99.102.71 with SMTP id a68mr44259693pgc.67.1489512508600; Tue, 14 Mar 2017 10:28:28 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id k126si15270156pgc.176.2017.03.14.10.28.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Mar 2017 10:28:28 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-77880-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-77880-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-77880-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=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=qjoHCbGRXN3d/8s0bkfdfK0vbwlEF7SlWuwAHdodu2XuDfpR5HYBS 4chLTrkdPGriaEtDkcgUTQFHVKl1QJPc7sD5QxekAuFn4hjgN+7cTHC7YdqZO2AL W3g2zUihPS8nABhLWvlQmjyDYZGrioFer+mNJhVEuY10cZO+mIF+pM= 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=BOMDDegnSvR3wicm13fk49UqGhg=; b=Gd+ba4kOTyXlQvZwKjOM/whvCDPs bkJtcekp1ruRiGyhbvGNVxr5sfqxhtUdJFbkKSPHbUnVD2pLXBuYTqqO4DUAslGD FN9s/6oImfTtAK0TbDrVuM8sBvLnZ9/s+AhMYk1HC1+EOXts7HBgGy9qKj5794Cw jQia2r3gZAbrHRA= Received: (qmail 11208 invoked by alias); 14 Mar 2017 17:28:17 -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 11190 invoked by uid 89); 14 Mar 2017 17:28:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f178.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=XzcQvHZ186jPnZX716pFmilGR6DtPUC5TEMqeCfKfic=; b=lWwfeMCVQNDeUQNw/IVd8a+CtwQMIwJH+gHdBPYLgn8Vr31bk0hK9XSwm1KjKcKoMh /AfM+z8L4RIhq8hwPslW0MDWmyHRT5Jo9yJc6HfYKN8tLomBPRjCtGy69WWnga6EOYEe PQtuU7hqWLdi52FsYUz+JRom+ghZZoTrtZoubJurvXiH8gn1NtEIdRhBT/ozcWJABGtp uZnFrmpZJlPhTFHzklVE5Gm1N3KOrkDcKKwXXFEHJxh4aeKn4ywiMzrHiyUM8qFmfQWX IM8H7zSAVnb5qa0Ei7q+qZ+b2j5T+B2u5jkqpS4HdwZ18dBgV40RaSB+POWr48N1DFMq Qonw== X-Gm-Message-State: AMke39msn6QPXytaaMzLIlBYUT4YlxDbPNxZ6pVFCCrORReF/4vx1q4YBTmLjg1+Cef2zNB+ X-Received: by 10.200.44.36 with SMTP id d33mr40939133qta.198.1489512493715; Tue, 14 Mar 2017 10:28:13 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] Fix i686 memchr overflow calculation (BZ#21182) Date: Tue, 14 Mar 2017 14:28:07 -0300 Message-Id: <1489512487-24860-1-git-send-email-adhemerval.zanella@linaro.org> This patch fixes the regression added by 23d2770 for final address overflow calculation. The subtraction of the considered size (16) at line 120 is at wrong place, for sizes less than 16 subsequent overflow check will not take in consideration an invalid size (since the subtraction will be negative). Also, the lea instruction also does not raise the carry flag (CF) that is used in subsequent jbe to check for overflow. The fix is to follow x86_64 logic from 3daef2c where the overflow is first check and a sub instruction is issued. In case of resulting negative size, CF will be set by the sub instruction and a NULL result will be returned. The patch also add similar tests reported in bug report. Checked on i686-linux-gnu and x86_64-linux-gnu. [BZ# 21182] * string/test-memchr.c (do_test): Add BZ#21182 checks for address near end of a page. * sysdeps/i386/i686/multiarch/memchr-sse2.S (__memchr): Fix overflow calculation. --- ChangeLog | 7 +++++++ string/test-memchr.c | 6 ++++++ sysdeps/i386/i686/multiarch/memchr-sse2.S | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/string/test-memchr.c b/string/test-memchr.c index d64d10c..87a077b 100644 --- a/string/test-memchr.c +++ b/string/test-memchr.c @@ -210,6 +210,12 @@ test_main (void) do_test (0, i, i + 1, i + 1, 0); } + /* BZ#21182 - wrong overflow calculation for i686 implementation + with address near end of the page. */ + for (i = 2; i < 16; ++i) + /* page_size is in fact getpagesize() * 2. */ + do_test (page_size/2 - i, i, i, 1, 0x9B); + do_random_tests (); return ret; } diff --git a/sysdeps/i386/i686/multiarch/memchr-sse2.S b/sysdeps/i386/i686/multiarch/memchr-sse2.S index 910679c..e41f324 100644 --- a/sysdeps/i386/i686/multiarch/memchr-sse2.S +++ b/sysdeps/i386/i686/multiarch/memchr-sse2.S @@ -117,7 +117,6 @@ L(crosscache): # ifndef USE_AS_RAWMEMCHR jnz L(match_case2_prolog1) - lea -16(%edx), %edx /* Calculate the last acceptable address and check for possible addition overflow by using satured math: edx = ecx + edx @@ -125,6 +124,7 @@ L(crosscache): add %ecx, %edx sbb %eax, %eax or %eax, %edx + sub $16, %edx jbe L(return_null) lea 16(%edi), %edi # else