From patchwork Mon Jan 10 00:27:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 49774 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01915388A83D for ; Mon, 10 Jan 2022 00:28:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01915388A83D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1641774496; bh=blFMcocCHqjg5JQO/hETJlvqtynNeeNKZdfvbjAhT7M=; 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=c6KL6rNKfzhxpkxZcysWxnxxs7Fl375ifYM+ytS10qfMp16Dq9wAggyBna+hLxf9l x2I3RHrS8UFv9ZvNPYw3RRYGX0rJhQlfTnABv73Y6jXR0Ea+M3S1MIRfYqvpWGEyf4 Gyx33wWQZDymaShTNbe/gobOS31p8jcBrHdGNDfk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 7EE3F3858424 for ; Mon, 10 Jan 2022 00:27:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7EE3F3858424 Received: by mail-pf1-x435.google.com with SMTP id p37so9259834pfh.4 for ; Sun, 09 Jan 2022 16:27:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=blFMcocCHqjg5JQO/hETJlvqtynNeeNKZdfvbjAhT7M=; b=NJ1j8JU1Sl8zRrhBmTpIEUKOHK+V6IAdSfml7VFYYArwGsStHgHbNGtT1RGRyNwyiK vsmmsmdPZQsmYNobOTPYXlQU/HwQJl4AH15sUkEbbiSkvH1XpZZI8ztt77SWK4HvHmGu +3jq210NlKgpxQ6h2G5Gkp50k3ue75j8lSSLqnEXDLC8HAjusJZQJm9CCtEyj94qBPEW kb/NSvbzh0NbLGDi6VPwQqyizZTYzpgIjzE5Mm7Pbip0qPZFk8tk/Zu/Vunov31SrSPQ 5461CB53w8HkJTG1i/HxjE6HSq4NESzrJ8yshLwjA9YpOUdrTjh3XPNfoMke5VvmwJ+l VmwA== X-Gm-Message-State: AOAM533wWmkcJxv8Nu7cvEA897mcaCDfcify52QYzVBX0eagQAXU4rmV GeTCqwmW02m3yzOB+4jWEBQ2+NLcZEQ= X-Google-Smtp-Source: ABdhPJxtTyPJNXlKV2jVVR8HnTaa0WVtDwtt1PsQP8rR4KsYlQTxjCwHUnwU99hXLgLC87OzbGf8AQ== X-Received: by 2002:a62:1c12:0:b0:4bc:6d81:b402 with SMTP id c18-20020a621c12000000b004bc6d81b402mr41973306pfc.40.1641774473319; Sun, 09 Jan 2022 16:27:53 -0800 (PST) Received: from localhost.localdomain (c-73-202-60-99.hsd1.ca.comcast.net. [73.202.60.99]) by smtp.googlemail.com with ESMTPSA id x12sm507257pjq.52.2022.01.09.16.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jan 2022 16:27:53 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 1/7] x86: Fix __wcsncmp_avx2 in strcmp-avx2.S [BZ# 28755] Date: Sun, 9 Jan 2022 18:27:40 -0600 Message-Id: <20220110002746.3653516-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220109122946.2754917-1-goldstein.w.n@gmail.com> References: <20220109122946.2754917-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Fixes [BZ# 28755] for wcsncmp by redirecting length >= 2^56 to __wcscmp_avx2. For x86_64 this covers the entire address range so any length larger could not possibly be used to bound `s1` or `s2`. test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass. Signed-off-by: Noah Goldstein Reviewed-by: H.J. Lu --- sysdeps/x86_64/multiarch/strcmp-avx2.S | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S index a45f9d2749..9c73b5899d 100644 --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S @@ -87,6 +87,16 @@ ENTRY (STRCMP) je L(char0) jb L(zero) # ifdef USE_AS_WCSCMP +# ifndef __ILP32__ + movq %rdx, %rcx + /* Check if length could overflow when multiplied by + sizeof(wchar_t). Checking top 8 bits will cover all potential + overflow cases as well as redirect cases where its impossible to + length to bound a valid memory region. In these cases just use + 'wcscmp'. */ + shrq $56, %rcx + jnz __wcscmp_avx2 +# endif /* Convert units: from wide to byte char. */ shl $2, %RDX_LP # endif