public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug string/28895] New: Wrong result in strncmp-avx2 and strncmp-evex
@ 2022-02-15 13:37 goldstein.w.n at gmail dot com
  2022-02-15 13:56 ` [Bug string/28895] " fweimer at redhat dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: goldstein.w.n at gmail dot com @ 2022-02-15 13:37 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28895

            Bug ID: 28895
           Summary: Wrong result in strncmp-avx2 and strncmp-evex
           Product: glibc
           Version: 2.36
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: string
          Assignee: unassigned at sourceware dot org
          Reporter: goldstein.w.n at gmail dot com
  Target Milestone: ---

Wrong result for strncmp-avx2 and strncmp-evex when it hits the page cross case
followed by the loop page cross case immediately afterwards with a short
length.

See following test case:

```
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <wchar.h>

#define PAGE_SIZE 4096
static void *
make_buf(uint64_t sz) {
    void * p = mmap(NULL, 2 * PAGE_SIZE + sz, PROT_NONE,
                    MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
    assert(p != NULL);
    assert(!mprotect(p + PAGE_SIZE, sz, PROT_READ | PROT_WRITE));
    return p + PAGE_SIZE;
}

int
main(int argc, char ** argv) {
    char * s1 = make_buf(0xd000 + 0x4000);
    char * s2 = make_buf(0xd000 + 0x4000);

    s1 += 0xffa;
    s2 += 0xfed;

    strcpy(s1, "tst-tlsmod%");
    strcpy(s2, "tst-tls-manydynamic73mod");

    if (strncmp(s1, s2, 10) != 0) {
        printf("Error!\n");
    }
}
```


Issue (for both evex and avx2)

```
        .p2align 4,, 10
L(return_page_cross_end_check):
        tzcntl  %ecx, %ecx
```

`ecx` can have garbabe in it from before the start of the string.

Fix is to use the `r10` mask to and off these bad matches (strcmp was doing
so. It was an oversight not to to do so in strncmp).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug string/28895] Wrong result in strncmp-avx2 and strncmp-evex
  2022-02-15 13:37 [Bug string/28895] New: Wrong result in strncmp-avx2 and strncmp-evex goldstein.w.n at gmail dot com
@ 2022-02-15 13:56 ` fweimer at redhat dot com
  2022-02-15 15:43 ` hjl.tools at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fweimer at redhat dot com @ 2022-02-15 13:56 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28895

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug string/28895] Wrong result in strncmp-avx2 and strncmp-evex
  2022-02-15 13:37 [Bug string/28895] New: Wrong result in strncmp-avx2 and strncmp-evex goldstein.w.n at gmail dot com
  2022-02-15 13:56 ` [Bug string/28895] " fweimer at redhat dot com
@ 2022-02-15 15:43 ` hjl.tools at gmail dot com
  2022-02-15 15:43 ` hjl.tools at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2022-02-15 15:43 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28895

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 13979
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13979&action=edit
A patch to add a testcase

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug string/28895] Wrong result in strncmp-avx2 and strncmp-evex
  2022-02-15 13:37 [Bug string/28895] New: Wrong result in strncmp-avx2 and strncmp-evex goldstein.w.n at gmail dot com
  2022-02-15 13:56 ` [Bug string/28895] " fweimer at redhat dot com
  2022-02-15 15:43 ` hjl.tools at gmail dot com
@ 2022-02-15 15:43 ` hjl.tools at gmail dot com
  2022-02-15 15:57 ` goldstein.w.n at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2022-02-15 15:43 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28895

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hjl.tools at gmail dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug string/28895] Wrong result in strncmp-avx2 and strncmp-evex
  2022-02-15 13:37 [Bug string/28895] New: Wrong result in strncmp-avx2 and strncmp-evex goldstein.w.n at gmail dot com
                   ` (2 preceding siblings ...)
  2022-02-15 15:43 ` hjl.tools at gmail dot com
@ 2022-02-15 15:57 ` goldstein.w.n at gmail dot com
  2022-02-16 10:41 ` goldstein.w.n at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: goldstein.w.n at gmail dot com @ 2022-02-15 15:57 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28895

--- Comment #2 from Noah Goldstein <goldstein.w.n at gmail dot com> ---
I have patch with test + fix. Just testing on build-many which takes a bit.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug string/28895] Wrong result in strncmp-avx2 and strncmp-evex
  2022-02-15 13:37 [Bug string/28895] New: Wrong result in strncmp-avx2 and strncmp-evex goldstein.w.n at gmail dot com
                   ` (3 preceding siblings ...)
  2022-02-15 15:57 ` goldstein.w.n at gmail dot com
@ 2022-02-16 10:41 ` goldstein.w.n at gmail dot com
  2022-02-16 12:05 ` fweimer at redhat dot com
  2022-02-16 12:24 ` goldstein.w.n at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: goldstein.w.n at gmail dot com @ 2022-02-16 10:41 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28895

Noah Goldstein <goldstein.w.n at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Noah Goldstein <goldstein.w.n at gmail dot com> ---
Fix has been pushed:
https://sourceware.org/git/?p=glibc.git;a=commit;h=e108c02a5e23c8c88ce66d8705d4a24bb6b9a8bf

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug string/28895] Wrong result in strncmp-avx2 and strncmp-evex
  2022-02-15 13:37 [Bug string/28895] New: Wrong result in strncmp-avx2 and strncmp-evex goldstein.w.n at gmail dot com
                   ` (4 preceding siblings ...)
  2022-02-16 10:41 ` goldstein.w.n at gmail dot com
@ 2022-02-16 12:05 ` fweimer at redhat dot com
  2022-02-16 12:24 ` goldstein.w.n at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: fweimer at redhat dot com @ 2022-02-16 12:05 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28895

--- Comment #4 from Florian Weimer <fweimer at redhat dot com> ---
Thanks. Which commit introduced the problem? Do we need to backport this to
release branches?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug string/28895] Wrong result in strncmp-avx2 and strncmp-evex
  2022-02-15 13:37 [Bug string/28895] New: Wrong result in strncmp-avx2 and strncmp-evex goldstein.w.n at gmail dot com
                   ` (5 preceding siblings ...)
  2022-02-16 12:05 ` fweimer at redhat dot com
@ 2022-02-16 12:24 ` goldstein.w.n at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: goldstein.w.n at gmail dot com @ 2022-02-16 12:24 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28895

--- Comment #5 from Noah Goldstein <goldstein.w.n at gmail dot com> ---
Commits:
EVEX:
https://sourceware.org/git/?p=glibc.git;a=commit;h=8418eb3ff4b781d31c4ed5dc6c0bd7356bc45db9
AVX2:
https://sourceware.org/git/?p=glibc.git;a=commit;h=b77b06e0e296f1a2276c27a67e1d44f2cfa38d45


No need to backport. We waited until after 2.35 release to push.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-02-16 12:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 13:37 [Bug string/28895] New: Wrong result in strncmp-avx2 and strncmp-evex goldstein.w.n at gmail dot com
2022-02-15 13:56 ` [Bug string/28895] " fweimer at redhat dot com
2022-02-15 15:43 ` hjl.tools at gmail dot com
2022-02-15 15:43 ` hjl.tools at gmail dot com
2022-02-15 15:57 ` goldstein.w.n at gmail dot com
2022-02-16 10:41 ` goldstein.w.n at gmail dot com
2022-02-16 12:05 ` fweimer at redhat dot com
2022-02-16 12:24 ` goldstein.w.n at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).