public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "zsojka at seznam dot cz" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug string/29197] New: __strncpy_power9() uses uninitialised register vs18 value for filling after \0
Date: Sun, 29 May 2022 19:39:12 +0000	[thread overview]
Message-ID: <bug-29197-131@http.sourceware.org/bugzilla/> (raw)

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

            Bug ID: 29197
           Summary: __strncpy_power9() uses uninitialised register vs18
                    value for filling after \0
           Product: glibc
           Version: 2.35
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: string
          Assignee: unassigned at sourceware dot org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
            Target: powerpc64le-unknown-linux-gnu

Hello,

originally reported as a gcc bug at https://gcc.gnu.org/PR105744 , but it was
analysed by Kewen Lin to be an issue in the glibc implementation.

The following program:
$ cat test_strncpy.c
#include <string.h>
#include <stdlib.h>

#define N 3
char a[N];
char c[N];

int
main (void)
{
  __asm__ volatile ("xxspltib 18, 0xf":::"vs18");
  strncpy (c, a, N);
  for (unsigned i = 0; i < N; i++)
    if (c[i])
      abort ();
  return 0;
}
$ powerpc64le-unknown-linux-gnu-gcc test_strncpy.c -static
$ qemu-ppc64le -- ./a.out 
qemu: uncaught target signal 6 (Aborted) - core dumped
Aborted

fails, with the value of c[] being:
(gdb) p c
$1 = "\000\015\015"


Quoting Kewen Lin:
---------------------
In
https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=sysdeps/powerpc/powerpc64/le/power9/strncpy.S

        lbz     r0,0(r4)
        stb     r0,0(r3)
        addi    r11,r3,1
        addi    r5,r5,-1
        vspltisb v18,0          /* Zeroes in v18  */

...

L(zero_padding_end):
        sldi    r10,r5,56       /* stxvl wants size in top 8 bits  */
        stxvl   v18,r11,r10     /* Partial store  */
        blr


The code at label "zero_padding_end" is supposed to use v18, but the stxvl will
take the 18 as vsx No. instead of vr No, so it ends up to use the wrong
register vs18 instead of v18 for the store.
---------------------

Disassembling the object code shows the registers used (v18 / vs18):

...
   0x0000000010022f10 <+16>:      lbz     r0,0(r4)
   0x0000000010022f14 <+20>:      stb     r0,0(r3)
   0x0000000010022f18 <+24>:      addi    r11,r3,1
   0x0000000010022f1c <+28>:      addi    r5,r5,-1
   0x0000000010022f20 <+32>:      vspltisb v18,0
...
   0x000000001002319c <+668>:     rldicr  r10,r5,56,7
   0x00000000100231a0 <+672>:     stxvl   vs18,r11,r10
   0x00000000100231a4 <+676>:     blr

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

             reply	other threads:[~2022-05-29 19:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-29 19:39 zsojka at seznam dot cz [this message]
2022-05-30  9:35 ` [Bug string/29197] " fweimer at redhat dot com
2022-05-30 10:07 ` fweimer at redhat dot com
2022-05-30 10:07 ` fweimer at redhat dot com
2022-05-30 11:56 ` tuliom at ascii dot art.br
2022-05-30 14:05 ` carlos at redhat dot com
2022-06-01  8:04 ` linkw at linux dot ibm.com
2022-06-06 18:57 ` msc at linux dot ibm.com
2022-06-07  3:04 ` linkw at gcc dot gnu.org
2022-06-07 14:32 ` msc at linux dot ibm.com
2022-06-07 14:32 ` msc at linux dot ibm.com
2022-06-07 19:03 ` msc at linux dot ibm.com
2022-06-07 20:00 ` msc at linux dot ibm.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-29197-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).