All of lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Andrey Konovalov <andreyknvl@google.com>
Cc: Evgenii Stepanov <eugenis@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	linux-arch@vger.kernel.org, Jacob Bramley <Jacob.Bramley@arm.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Ruben Ayrapetyan <Ruben.Ayrapetyan@arm.com>,
	Ramana Radhakrishnan <Ramana.Radhakrishnan@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Kostya Serebryany <kcc@google.com>,
	Dmitry Vyukov <dvyukov@google.com>, Lee Smith <Lee.Smith@arm.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [RFC PATCH 3/6] mm, arm64: untag user addresses in memory syscalls
Date: Wed, 14 Mar 2018 17:44:43 +0000	[thread overview]
Message-ID: <20180314174442.lclslnqc3egfjg4c@armageddon.cambridge.arm.com> (raw)
In-Reply-To: <CAAeHK+y3hJ4jAByvfGDYyNb_RZ3_As4r-FCyZL9u69Vv_HS2AA@mail.gmail.com>

On Wed, Mar 14, 2018 at 04:45:20PM +0100, Andrey Konovalov wrote:
> On Fri, Mar 9, 2018 at 6:42 PM, Evgenii Stepanov <eugenis@google.com> wrote:
> > On Fri, Mar 9, 2018 at 9:31 AM, Andrey Konovalov <andreyknvl@google.com> wrote:
> >> On Fri, Mar 9, 2018 at 4:53 PM, Catalin Marinas <catalin.marinas@arm.com> wrote:
> >>> I'm not yet convinced these functions need to allow tagged pointers.
> >>> They are not doing memory accesses but rather dealing with the memory
> >>> range, hence an untagged pointer is better suited. There is probably a
> >>> reason why the "start" argument is "unsigned long" vs "void __user *"
> >>> (in the kernel, not the man page).
> >>
> >> So that would make the user to untag pointers before passing to these syscalls.
> >>
> >> Evgeniy, would that be possible to untag pointers in HWASan before
> >> using memory subsystem syscalls? Is there a reason for untagging them
> >> in the kernel?
> >
> > Generally, no. It's possible to intercept a libc call using symbol
> > interposition, but I don't know how to rewrite arguments of a raw
> > system call other than through ptrace, and that creates more problems
> > than it solves.

With these patches, we are trying to relax the user/kernel ABI so that
tagged pointers can be passed into the kernel. Since this is a new ABI
(or an extension to the existing one), it might be ok to change the libc
so that the top byte is zeroed on specific syscalls before issuing the
SVC.

I agree that it is problematic for HWASan if it only relies on
overriding malloc/free.

> > AFAIU, it's valid for a program to pass an address obtained from
> > malloc or, better, posix_memalign to an mm syscall like mprotect().
> > These arguments are pointers from the userspace point of view.
> 
> Catalin, do you think this is a good reason to have the untagging done
> in the kernel?

malloc() or posix_memalign() are C library implementations and it's the
C library (or overridden functions) setting a tag on the returned
pointers. Since the TBI hardware feature allows memory accesses with a
non-zero tag, we could allow them in the kernel for syscalls performing
such accesses on behalf of the user (e.g. get_user/put_user would not
need to clear the tag).

madvise(), OTOH, does not perform a memory access on behalf of the user,
it's just advising the kernel about a range of virtual addresses. That's
where I think, from an ABI perspective, it doesn't make much sense to
allow tags into the kernel for these syscalls (even if it's simpler from
a user space perspective).

(but I don't have a very strong opinion on this ;))

-- 
Catalin

WARNING: multiple messages have this Message-ID (diff)
From: catalin.marinas@arm.com (Catalin Marinas)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 3/6] mm, arm64: untag user addresses in memory syscalls
Date: Wed, 14 Mar 2018 17:44:43 +0000	[thread overview]
Message-ID: <20180314174442.lclslnqc3egfjg4c@armageddon.cambridge.arm.com> (raw)
In-Reply-To: <CAAeHK+y3hJ4jAByvfGDYyNb_RZ3_As4r-FCyZL9u69Vv_HS2AA@mail.gmail.com>

On Wed, Mar 14, 2018 at 04:45:20PM +0100, Andrey Konovalov wrote:
> On Fri, Mar 9, 2018 at 6:42 PM, Evgenii Stepanov <eugenis@google.com> wrote:
> > On Fri, Mar 9, 2018 at 9:31 AM, Andrey Konovalov <andreyknvl@google.com> wrote:
> >> On Fri, Mar 9, 2018 at 4:53 PM, Catalin Marinas <catalin.marinas@arm.com> wrote:
> >>> I'm not yet convinced these functions need to allow tagged pointers.
> >>> They are not doing memory accesses but rather dealing with the memory
> >>> range, hence an untagged pointer is better suited. There is probably a
> >>> reason why the "start" argument is "unsigned long" vs "void __user *"
> >>> (in the kernel, not the man page).
> >>
> >> So that would make the user to untag pointers before passing to these syscalls.
> >>
> >> Evgeniy, would that be possible to untag pointers in HWASan before
> >> using memory subsystem syscalls? Is there a reason for untagging them
> >> in the kernel?
> >
> > Generally, no. It's possible to intercept a libc call using symbol
> > interposition, but I don't know how to rewrite arguments of a raw
> > system call other than through ptrace, and that creates more problems
> > than it solves.

With these patches, we are trying to relax the user/kernel ABI so that
tagged pointers can be passed into the kernel. Since this is a new ABI
(or an extension to the existing one), it might be ok to change the libc
so that the top byte is zeroed on specific syscalls before issuing the
SVC.

I agree that it is problematic for HWASan if it only relies on
overriding malloc/free.

> > AFAIU, it's valid for a program to pass an address obtained from
> > malloc or, better, posix_memalign to an mm syscall like mprotect().
> > These arguments are pointers from the userspace point of view.
> 
> Catalin, do you think this is a good reason to have the untagging done
> in the kernel?

malloc() or posix_memalign() are C library implementations and it's the
C library (or overridden functions) setting a tag on the returned
pointers. Since the TBI hardware feature allows memory accesses with a
non-zero tag, we could allow them in the kernel for syscalls performing
such accesses on behalf of the user (e.g. get_user/put_user would not
need to clear the tag).

madvise(), OTOH, does not perform a memory access on behalf of the user,
it's just advising the kernel about a range of virtual addresses. That's
where I think, from an ABI perspective, it doesn't make much sense to
allow tags into the kernel for these syscalls (even if it's simpler from
a user space perspective).

(but I don't have a very strong opinion on this ;))

-- 
Catalin

  reply	other threads:[~2018-03-14 17:44 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 14:01 [RFC PATCH 0/6] arm64: untag user pointers passed to the kernel Andrey Konovalov
2018-03-09 14:01 ` [OpenRISC] " Andrey Konovalov
2018-03-09 14:01 ` Andrey Konovalov
2018-03-09 14:01 ` Andrey Konovalov
2018-03-09 14:01 ` [RFC PATCH 1/6] arm64: add type casts to untagged_addr macro Andrey Konovalov
2018-03-09 14:01   ` [OpenRISC] " Andrey Konovalov
2018-03-09 14:01   ` Andrey Konovalov
2018-03-09 14:01   ` Andrey Konovalov
2018-03-09 14:02 ` [RFC PATCH 2/6] arm64: untag user addresses in copy_from_user and others Andrey Konovalov
2018-03-09 14:02   ` [OpenRISC] " Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 15:03   ` Mark Rutland
2018-03-09 15:03     ` Mark Rutland
2018-03-09 15:58     ` Catalin Marinas
2018-03-09 15:58       ` Catalin Marinas
2018-03-09 15:58       ` Catalin Marinas
2018-03-09 15:58       ` Catalin Marinas
2018-03-09 17:57       ` Andrey Konovalov
2018-03-09 17:57         ` Andrey Konovalov
2018-03-09 14:02 ` [RFC PATCH 3/6] mm, arm64: untag user addresses in memory syscalls Andrey Konovalov
2018-03-09 14:02   ` [OpenRISC] " Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 15:53   ` Catalin Marinas
2018-03-09 15:53     ` Catalin Marinas
2018-03-09 17:31     ` Andrey Konovalov
2018-03-09 17:31       ` Andrey Konovalov
2018-03-09 17:42       ` Evgenii Stepanov
2018-03-09 17:42         ` Evgenii Stepanov
2018-03-14 15:45         ` Andrey Konovalov
2018-03-14 15:45           ` Andrey Konovalov
2018-03-14 17:44           ` Catalin Marinas [this message]
2018-03-14 17:44             ` Catalin Marinas
2018-03-16  1:11             ` Evgenii Stepanov
2018-03-16  1:11               ` Evgenii Stepanov
2018-03-09 14:02 ` [RFC PATCH 4/6] mm, arm64: untag user addresses in mm/gup.c Andrey Konovalov
2018-03-09 14:02   ` [OpenRISC] " Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 14:02 ` [RFC PATCH 5/6] lib, arm64: untag addrs passed to strncpy_from_user and strnlen_user Andrey Konovalov
2018-03-09 14:02   ` [OpenRISC] " Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 14:02 ` [RFC PATCH 6/6] arch: add untagged_addr definition for other arches Andrey Konovalov
2018-03-09 14:02   ` [OpenRISC] " Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 14:02   ` Andrey Konovalov
2018-03-09 14:11   ` Arnd Bergmann
2018-03-09 14:11     ` [OpenRISC] " Arnd Bergmann
2018-03-09 14:11     ` Arnd Bergmann
2018-03-09 14:11     ` Arnd Bergmann
2018-03-09 14:11     ` Arnd Bergmann
2018-03-09 14:11     ` Arnd Bergmann
2018-03-09 14:16   ` Robin Murphy
2018-03-09 14:16     ` [OpenRISC] " Robin Murphy
2018-03-09 14:16     ` Robin Murphy
2018-03-09 14:16     ` Robin Murphy
2018-03-09 15:47     ` Andrey Konovalov
2018-03-09 15:47       ` [OpenRISC] " Andrey Konovalov
2018-03-09 15:47       ` Andrey Konovalov
2018-03-09 15:47       ` Andrey Konovalov
2018-03-09 15:47       ` Andrey Konovalov
2018-03-09 15:47       ` Andrey Konovalov
2018-03-09 14:15 ` [RFC PATCH 0/6] arm64: untag user pointers passed to the kernel Robin Murphy
2018-03-09 14:15   ` [OpenRISC] " Robin Murphy
2018-03-09 14:15   ` Robin Murphy
2018-03-09 14:15   ` Robin Murphy
2018-03-09 17:58   ` Andrey Konovalov
2018-03-09 17:58     ` [OpenRISC] " Andrey Konovalov
2018-03-09 17:58     ` Andrey Konovalov
2018-03-09 17:58     ` Andrey Konovalov
2018-03-09 17:58     ` Andrey Konovalov
2018-03-09 17:58     ` Andrey Konovalov
2018-03-09 14:55 ` Mark Rutland
2018-03-09 14:55   ` Mark Rutland
2018-03-09 15:16   ` Geert Uytterhoeven
2018-03-09 15:16     ` Geert Uytterhoeven
2018-03-09 17:58   ` Andrey Konovalov
2018-03-09 17:58     ` Andrey Konovalov

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=20180314174442.lclslnqc3egfjg4c@armageddon.cambridge.arm.com \
    --to=catalin.marinas@arm.com \
    --cc=Jacob.Bramley@arm.com \
    --cc=Lee.Smith@arm.com \
    --cc=Ramana.Radhakrishnan@arm.com \
    --cc=Ruben.Ayrapetyan@arm.com \
    --cc=andreyknvl@google.com \
    --cc=arnd@arndb.de \
    --cc=dvyukov@google.com \
    --cc=eugenis@google.com \
    --cc=kcc@google.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robin.murphy@arm.com \
    --cc=will.deacon@arm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.