From mboxrd@z Thu Jan 1 00:00:00 1970 From: Catalin Marinas Subject: Re: [PATCH v2 2/4] arm64: Define Documentation/arm64/elf_at_flags.txt Date: Fri, 22 Mar 2019 10:48:40 +0000 Message-ID: <20190322104839.GA13384@arrakis.emea.arm.com> References: <20190318163533.26838-1-vincenzo.frascino@arm.com> <20190318163533.26838-3-vincenzo.frascino@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Amit Daniel Kachhap Cc: Vincenzo Frascino , LAK , linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kate Stewart , Mark Rutland , Peter Zijlstra , Will Deacon , Alexei Starovoitov , Kostya Serebryany , Eric Dumazet , Chintan Pandya , Shuah Khan , Ingo Molnar , Jacob Bramley , Daniel Borkmann , Szabolcs Nagy , Steven Rostedt List-Id: linux-arch.vger.kernel.org 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 > 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com ([217.140.101.70]:41654 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727867AbfCVKsu (ORCPT ); Fri, 22 Mar 2019 06:48:50 -0400 Date: Fri, 22 Mar 2019 10:48:40 +0000 From: Catalin Marinas Subject: Re: [PATCH v2 2/4] arm64: Define Documentation/arm64/elf_at_flags.txt Message-ID: <20190322104839.GA13384@arrakis.emea.arm.com> References: <20190318163533.26838-1-vincenzo.frascino@arm.com> <20190318163533.26838-3-vincenzo.frascino@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-arch-owner@vger.kernel.org List-ID: To: Amit Daniel Kachhap Cc: Vincenzo Frascino , LAK , linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kate Stewart , Mark Rutland , Peter Zijlstra , Will Deacon , Alexei Starovoitov , Kostya Serebryany , Eric Dumazet , Chintan Pandya , Shuah Khan , Ingo Molnar , Jacob Bramley , Daniel Borkmann , Szabolcs Nagy , Steven Rostedt , Dave Martin , Evgeniy Stepanov , Kees Cook , Ruben Ayrapetyan , Andrey Konovalov , Kevin Brodsky , Arnaldo Carvalho de Melo , Graeme Barnes , Alexander Viro , Dmitry Vyukov , Branislav Rankov , Ramana Radhakrishnan , Greg Kroah-Hartman , Luc Van Oostenryck , Lee Smith , Andrew Morton , Robin Murphy , "David S. Miller" , "Kirill A . Shutemov" Message-ID: <20190322104840.rfrCiOwzIfJM8hb9Bkfz0fhyiB51dXwNl9BBdp496Ng@z> 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 > 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