From patchwork Mon Jun 7 07:10:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1488434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=SBbNyWZl; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fz4N871Kdz9sSn for ; Mon, 7 Jun 2021 17:13:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E01EE383D01F for ; Mon, 7 Jun 2021 07:13:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E01EE383D01F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623050006; bh=z5VERdukxg0/eK+Dv82g2SBcpKf1NuSU7E7CbarELyE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=SBbNyWZlrDI+2G1w8nk4S3obT3JVJ9ig5w3QCquWwzxZ6j1lfAPB6JcIF67r8dk0h 2VeUPhlkWAeJ1FgGYRKTiRgZaPb3NhQF7mBcVjF8jzaY8Vhcr8T8OdU4bm2vrKGYZN P/nUhHvxMfBTDhHn10cgzJqsPKDaWSrKRM27hrNw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 7B998385BF99 for ; Mon, 7 Jun 2021 07:11:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B998385BF99 Received: by mail-qk1-x730.google.com with SMTP id c18so638457qkc.11 for ; Mon, 07 Jun 2021 00:11:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z5VERdukxg0/eK+Dv82g2SBcpKf1NuSU7E7CbarELyE=; b=h2w0OwBk1SGwSy1BxPH8eNUvyEnKpNGv7cqfyuTicw2PC6iypNUBBxWYrNjv/cDCAA B+g5prZEXGOLHwxunVWzS4JUIjefd3vfronK9XUDJRZPdXNSp13ZPg5F6qzlAa4ZNoq6 lymkSombQHKVDPgtrCyJeYyuvbBc/5IEGsIiXBf4btAnEARRwAXswPMu3uJZJng21v08 a35QhdKS03YkKlwgg4tMZu36aax/5uSoiJpHlOuoFCGFNr412KYddzM4YxMfcwwp66Cp dnCV5JNbagn5mhPaNLngKTzoK8vf7V6bNyIQaJ6UynqpBdyrmTo7frPXooU399G0SE0C 9aGQ== X-Gm-Message-State: AOAM531ZvGUvpknndhYsyXtQOWyW6Oe/vFWO47lQydg6/BxrhuT4gJmD 2BK6nqMnmW/b24SI3Jk35/JPkHrnDA0= X-Google-Smtp-Source: ABdhPJyJO37QYQE2RwJ28TiP2l+xFAHPO4nNefcxiVC9E64Dc8e2rJvmZXMX9cXb6x1I/9afz5g9yA== X-Received: by 2002:a05:620a:704:: with SMTP id 4mr15136224qkc.66.1623049902808; Mon, 07 Jun 2021 00:11:42 -0700 (PDT) Received: from localhost.localdomain (pool-71-245-178-39.pitbpa.fios.verizon.net. [71.245.178.39]) by smtp.googlemail.com with ESMTPSA id 97sm8173094qte.20.2021.06.07.00.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 00:11:42 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1 1/3] String: tst-memset-overflow.c Add test for overflow case. Date: Mon, 7 Jun 2021 03:10:24 -0400 Message-Id: <20210607071025.449866-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The following commit: author Noah Goldstein Thu, 20 May 2021 17:13:51 +0000 (13:13 -0400) commit 6abf27980a947f9b6e514d6b33b83059d39566ae added a bug to memset so that if destination + length overflowed memset would return early rather than throw a Segmentation Fault as is expected behavior: This commit adds a new test file: tst-memset-overflow.c that is expected to Segmentation Fault if that bug is not present Signed-off-by: Noah Goldstein --- Currently the test will "FAIL" which is expected. I am unsure, however, how to get the test to "PASS" while also inducing Segmentation Faults. string/Makefile | 2 +- string/tst-memset-overflow.c | 156 +++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 string/tst-memset-overflow.c diff --git a/string/Makefile b/string/Makefile index f0fce2a0b8..fd701a76e5 100644 --- a/string/Makefile +++ b/string/Makefile @@ -63,7 +63,7 @@ tests := tester inl-tester noinl-tester testcopy test-ffs \ tst-strtok_r bug-strcoll2 tst-cmp tst-xbzero-opt \ test-endian-types test-endian-file-scope \ test-endian-sign-conversion tst-memmove-overflow \ - test-sig_np + tst-memset-overflow test-sig_np # Both tests require the .mo translation files generated by msgfmt. tests-translation := tst-strsignal \ diff --git a/string/tst-memset-overflow.c b/string/tst-memset-overflow.c new file mode 100644 index 0000000000..5a2d49407b --- /dev/null +++ b/string/tst-memset-overflow.c @@ -0,0 +1,156 @@ +/* Test memset functions. + Copyright (C) 1999-2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Jakub Jelinek , 1999. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define TEST_MAIN +#ifdef TEST_BZERO +# ifdef TEST_EXPLICIT_BZERO +# define TEST_NAME "explicit_bzero" +# else +# define TEST_NAME "bzero" +# endif +#else +# ifndef WIDE +# define TEST_NAME "memset" +# else +# define TEST_NAME "wmemset" +# endif /* WIDE */ +#endif /* !TEST_BZERO */ +#define MIN_PAGE_SIZE 131072 +#include "test-string.h" + +#ifndef WIDE +# define MEMSET memset +# define CHAR char +# define UCHAR unsigned char +# define SIMPLE_MEMSET simple_memset +# define MEMCMP memcmp +# define BIG_CHAR CHAR_MAX +#else +# include +# define MEMSET wmemset +# define CHAR wchar_t +# define UCHAR wchar_t +# define SIMPLE_MEMSET simple_wmemset +# define MEMCMP wmemcmp +# define BIG_CHAR WCHAR_MAX +#endif /* WIDE */ + +CHAR *SIMPLE_MEMSET (CHAR *, int, size_t); + +#ifdef TEST_BZERO +typedef void (*proto_t) (char *, size_t); +void simple_bzero (char *, size_t); +void builtin_bzero (char *, size_t); + +IMPL (simple_bzero, 0) +IMPL (builtin_bzero, 0) +#ifdef TEST_EXPLICIT_BZERO +IMPL (explicit_bzero, 1) +#else +IMPL (bzero, 1) +#endif + +void +simple_bzero (char *s, size_t n) +{ + SIMPLE_MEMSET (s, 0, n); +} + +void +builtin_bzero (char *s, size_t n) +{ + __builtin_bzero (s, n); +} +#else +typedef CHAR *(*proto_t) (CHAR *, int, size_t); + +IMPL (SIMPLE_MEMSET, 0) +# ifndef WIDE +char *builtin_memset (char *, int, size_t); +IMPL (builtin_memset, 0) +# endif /* !WIDE */ +IMPL (MEMSET, 1) + +# ifndef WIDE +char * +builtin_memset (char *s, int c, size_t n) +{ + return __builtin_memset (s, c, n); +} +# endif /* !WIDE */ +#endif /* !TEST_BZERO */ + +CHAR * +inhibit_loop_to_libcall +SIMPLE_MEMSET (CHAR *s, int c, size_t n) +{ + CHAR *r = s, *end = s + n; + while (r != end) + *r++ = c; + return s; +} + +int +test_main (void) +{ + size_t i, len; + const size_t one = 1; + + test_init (); + + printf ("%24s", ""); + FOR_EACH_IMPL (impl, 0) + printf ("\t%s", impl->name); + putchar ('\n'); + + for (i = 1; i <= 2; ++i) + { + len = one << (8 * sizeof(size_t) - i); + FOR_EACH_IMPL (impl, 0) + { +#ifdef TEST_BZERO + CALL (impl, (CHAR *) (buf1), len); +#else + CALL (impl, (CHAR *) (buf1), 0, len); +#endif + printf ("Should have thrown Segmentation Fault For (%p, %zu) %s", + buf1, len, impl->name); + ret = 1; + } + } + len = 0; + for (i = 8 * sizeof(size_t); i != 0; --i) + { + len |= (one << i); + FOR_EACH_IMPL (impl, 0) + { +#ifdef TEST_BZERO + CALL (impl, (CHAR *) (buf1), len); +#else + CALL (impl, (CHAR *) (buf1), 0, len); +#endif + printf ("Should have thrown Segmentation Fault For (%p, %zu) %s", + buf1, len, impl->name); + ret = 1; + } + } + return ret; +} + +#include From patchwork Mon Jun 7 07:10:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1488432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=L2JChgos; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fz4LT3FRgz9sSn for ; Mon, 7 Jun 2021 17:12:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D18AD383F87C for ; Mon, 7 Jun 2021 07:11:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D18AD383F87C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623049918; bh=uX6QcQqqbmUv73KYHgrMczk+hOEw9hNdTb59gv14X8E=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=L2JChgos0hsLYuetJq+wfYNfP4RU4K7Kz1/49/015uDpUyl1TreHvMYa+yVRqXEfT Fz/QRZRKHbVVHw6WbelmXCCYPss26bt4flzsfPDoaG6NT8v5ll5649EqDOh4R2WzmY AJMg5BM4VKeaE5r4WOqgvH/7jd/7ruzGZqJ+v2D8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by sourceware.org (Postfix) with ESMTPS id 361343853818 for ; Mon, 7 Jun 2021 07:11:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 361343853818 Received: by mail-qt1-x82d.google.com with SMTP id m13so11881939qtk.13 for ; Mon, 07 Jun 2021 00:11:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uX6QcQqqbmUv73KYHgrMczk+hOEw9hNdTb59gv14X8E=; b=DMGkjRAPF2zDoEVXQGS7skhPs1rfyUbn/dkVCak/8WzMEvZCpvzAjh0lzzJXH+nvkS 0bLlbpTFasI9GSPRNOEWPAIHxSjREtXdjSMWjT77D35JcYSqVkM9jZHBij8xkBsql1yC 8ltMm35WIrewF8e18cO+YOalMlHFeNJ/HquuyvJ4QFkb01Gd8T7j2m3UAyjz+Gc6ir26 TmDjA5Hnou+RgsKUYsWXqsAPBdLi/wUQ2DS7db8QGpTkcWhO/EeYulLnsNTGbOGYH1/C 1zxel1F4HfeGtgk7/ANo0vZRtiJv7rCdOXOV/UUOxY33MQ/JaRZTQCIlIPMIjnYxzIHI uxrw== X-Gm-Message-State: AOAM532zwbRFVC7LMmIebA3CA2SCJuzbZvNwh8CP5o8ilpo1dgMwFblk Flcm9FGN3evdGQHp1JvBwpPl2SDcwcs= X-Google-Smtp-Source: ABdhPJyQG8wRx4mHxtZFaolt9TPnRo9XX99lfCUaE2I4QM8Y29YlFgs+BymbrBUXogtJ4fy5FKwTJQ== X-Received: by 2002:a05:622a:309:: with SMTP id q9mr14959511qtw.320.1623049904688; Mon, 07 Jun 2021 00:11:44 -0700 (PDT) Received: from localhost.localdomain (pool-71-245-178-39.pitbpa.fios.verizon.net. [71.245.178.39]) by smtp.googlemail.com with ESMTPSA id 97sm8173094qte.20.2021.06.07.00.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 00:11:44 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1 2/3] String: test-memset.c strenthen test coverage Date: Mon, 7 Jun 2021 03:10:25 -0400 Message-Id: <20210607071025.449866-2-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210607071025.449866-1-goldstein.w.n@gmail.com> References: <20210607071025.449866-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This commit adds some additional tests cases that seemed lacking. Signed-off-by: Noah Goldstein --- string/test-memset.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/string/test-memset.c b/string/test-memset.c index 82bfcd6ad4..473bf1d1f5 100644 --- a/string/test-memset.c +++ b/string/test-memset.c @@ -101,7 +101,7 @@ inhibit_loop_to_libcall SIMPLE_MEMSET (CHAR *s, int c, size_t n) { CHAR *r = s, *end = s + n; - while (r < end) + while (r != end) *r++ = c; return s; } @@ -237,7 +237,7 @@ do_random_tests (void) int test_main (void) { - size_t i; + size_t i, j; int c = 0; test_init (); @@ -252,15 +252,29 @@ test_main (void) #endif { for (i = 0; i < 18; ++i) - do_test (0, c, 1 << i); - for (i = 1; i < 64; ++i) + { + do_test (0, c, 1 << i); + do_test (i, c, 1 << i); + do_test (0, c, (1 << i) + 1); + do_test (i, c, (1 << i) + 1); + do_test (0, c, (1 << i) - 1); + do_test (i, c, (1 << i) - 1); + } + for (i = 1; i < 128; ++i) { - do_test (i, c, i); - do_test (4096 - i, c, i); - do_test (4095, c, i); + for (j = i; j <= 2500; j += 15) + { + do_test (i, c, j); + do_test (4096 - i, c, j); + do_test (4095, c, j); + } if (i & (i - 1)) do_test (0, c, i); } + do_test (0, c, 257); + do_test (0, c, 383); + do_test (0, c, 384); + do_test (0, c, 385); do_test (1, c, 14); do_test (3, c, 1024); do_test (4, c, 64); From patchwork Mon Jun 7 07:10:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1488433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=j5erdEyR; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fz4MK30Bwz9sSn for ; Mon, 7 Jun 2021 17:12:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3556383B824 for ; Mon, 7 Jun 2021 07:12:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3556383B824 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623049962; bh=Cil+9ElyCdkrVgLb9uSxY3BoHI/7oJMfCfWV4qicFGI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=j5erdEyRj2vtg/bJdJJ21Z/o0fHwxsoLe8wCslxFsS8CPWnRJ3sT4Ird4WtKSKCSV 7OeaHyo6aPtDjwoso7rXQ0xpiU7rvfpkmecfaksJx4ykIHewkPQQ2Eivp1Ubx74umd 3trCC4v9+so1upmyJlEF1o8sTR8C4QanzcK8bHYs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by sourceware.org (Postfix) with ESMTPS id B80D53853818 for ; Mon, 7 Jun 2021 07:11:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B80D53853818 Received: by mail-qt1-x82c.google.com with SMTP id v6so2997630qta.9 for ; Mon, 07 Jun 2021 00:11:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Cil+9ElyCdkrVgLb9uSxY3BoHI/7oJMfCfWV4qicFGI=; b=HqtFW4siy2Uo1xX1edNrVw6sXWYsEXbGWorbghlA9tlGh1k3dXOY6VnxRniVFjvFld /HRFMxewMt5+zlEcmDB4jPIhRqnloJV4ilE8UO+94xSwcBSSKa6c3JLeE/xJVjDKrLHa Fk4CvsPMk9qGDabLxhvNYVVc4O5tvxMihpnpuyFAOEX0tEdq8o4dlIJZb07GbOLD+DvA purCRB3Nr8XVhga5oDfPlGMRKBsjmuRLt7F0S2vfV5hLHTfxbu2P67RLC65+gZe1JCY7 OtoH0huhUMqvy4kGP88bicdF5Pku4BjkqOvJCt6WIKuUmSSTHCMHr5kmp+L7PQlF0KR0 iCTQ== X-Gm-Message-State: AOAM533pkJMZNDPqUP5UjJZS+8ngZkHUFZla1mmw8bjUfAfeb4og8k5D lEZbA76qb5ruo7SIl7TfPDRTPdv0rbM= X-Google-Smtp-Source: ABdhPJytSNvwS6x5u3cySIrIomvp7FYStt9lLe+N7Ejr+22rsgGkj1zfqdxr0vx8wbPSE7ctAUns6Q== X-Received: by 2002:ac8:7d0b:: with SMTP id g11mr489366qtb.276.1623049906196; Mon, 07 Jun 2021 00:11:46 -0700 (PDT) Received: from localhost.localdomain (pool-71-245-178-39.pitbpa.fios.verizon.net. [71.245.178.39]) by smtp.googlemail.com with ESMTPSA id 97sm8173094qte.20.2021.06.07.00.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 00:11:45 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1 3/3] x86: memset-vec-unaligned-erms.S fix bug with overflow. Date: Mon, 7 Jun 2021 03:10:26 -0400 Message-Id: <20210607071025.449866-3-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210607071025.449866-1-goldstein.w.n@gmail.com> References: <20210607071025.449866-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The following commit: author Noah Goldstein Thu, 20 May 2021 17:13:51 +0000 (13:13 -0400) commit 6abf27980a947f9b6e514d6b33b83059d39566ae added a bug to memset so that if destination + length overflowed memset would return early rather than throw a Segmentation Fault as is expected behavior: This commit fixes that bug. Signed-off-by: Noah Goldstein --- .../multiarch/memset-vec-unaligned-erms.S | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S index ff196844a0..3399a2bf1e 100644 --- a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S +++ b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S @@ -63,6 +63,16 @@ # endif #endif +# if VEC_SIZE == 16 +# define LOG_VEC_SIZE 4 +# elif VEC_SIZE == 32 +# define LOG_VEC_SIZE 5 +# elif VEC_SIZE == 64 +# define LOG_VEC_SIZE 6 +# else +# error Unsupported VEC_SIZE +#endif + #define PAGE_SIZE 4096 #ifndef SECTION @@ -196,14 +206,17 @@ L(return): ret #endif + .p2align 4 L(loop_start): VMOVU %VEC(0), (VEC_SIZE * 2)(%rdi) VMOVU %VEC(0), (VEC_SIZE * 3)(%rdi) cmpq $(VEC_SIZE * 8), %rdx jbe L(loop_end) + leaq -(VEC_SIZE * 4 + 1)(%rdi, %rdx), %rcx andq $-(VEC_SIZE * 2), %rdi + subq %rdi, %rcx subq $-(VEC_SIZE * 4), %rdi - leaq -(VEC_SIZE * 4)(%rax, %rdx), %rcx + sarq $(LOG_VEC_SIZE + 2), %rcx .p2align 4 L(loop): VMOVA %VEC(0), (%rdi) @@ -211,8 +224,8 @@ L(loop): VMOVA %VEC(0), (VEC_SIZE * 2)(%rdi) VMOVA %VEC(0), (VEC_SIZE * 3)(%rdi) subq $-(VEC_SIZE * 4), %rdi - cmpq %rcx, %rdi - jb L(loop) + decq %rcx + jne L(loop) L(loop_end): /* NB: rax is set as ptr in MEMSET_VDUP_TO_VEC0_AND_SET_RETURN. rdx as length is also unchanged. */