Re: [PATCH v2 2/4] arm64: Define Documentation/arm64/elf_at_flags.txt

From: Catalin Marinas
Date: Fri Mar 22 2019 - 06:48:52 EST


On Fri, Mar 22, 2019 at 11:52:37AM +0530, Amit Daniel Kachhap wrote:
> On Mon, Mar 18, 2019 at 10:06 PM Vincenzo Frascino
> <vincenzo.frascino@xxxxxxx> wrote:
> > +Example of correct usage (pseudo-code) for a userspace application:
> > +
> > +bool arm64_syscall_tbi_is_present(void)
> > +{
> > + unsigned long at_flags = getauxval(AT_FLAGS);
> > + if (at_flags & ARM64_AT_FLAGS_SYSCALL_TBI)
> > + return true;
> > +
> > + return false;
> > +}
> > +
> > +void main(void)
> > +{
> > + char *addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
> > + MAP_ANONYMOUS, -1, 0);
> > +
> > + int fd = open("test.txt", O_WRONLY);
> > +
> > + /* Check if the relaxed ABI is supported */
> > + if (arm64_syscall_tbi_is_present()) {
> > + /* Add a tag to the pointer */
> > + addr = tag_pointer(addr);
> > + }
> > +
> > + strcpy("Hello World\n", addr);
>
> Nit: s/strcpy("Hello World\n", addr)/strcpy(addr, "Hello World\n")

Not exactly a nit ;).

> > +
> > + /* Write to a file */
> > + write(fd, addr, sizeof(addr));

I presume this was supposed to write "Hello World\n" to a file but
sizeof(addr) is 1.

Since we already support tagged pointers in user space (as long as they
are not passed into the kernel), the above example could tag the pointer
unconditionally and only clear it before write() if
!arm64_syscall_tbi_is_present().

--
Catalin