Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-24 Thread Stephen Röttger
> The problem you seem to have with fully locked mseal() in chrome seems > to be here: > > > about permission changes but sometimes we do need to mprotect data only > > pages. > > Does that data have to be in the same region? Can your allocator not > put the non-code pieces of the JIT elsewhere, w

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-23 Thread Jeff Xu
On Thu, Oct 19, 2023 at 4:06 PM Linus Torvalds wrote: > > On Thu, 19 Oct 2023 at 15:47, Pedro Falcato wrote: > > > > > > For mprotect()/mmap(), is Linux implementation limited by POSIX ? > > > > No. POSIX works merely as a baseline that UNIX systems aim towards. > > You can (and very frequently d

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-23 Thread Jeff Xu
On Thu, Oct 19, 2023 at 3:47 PM Pedro Falcato wrote: > > On Thu, Oct 19, 2023 at 6:30 PM Jeff Xu wrote: > > > > Hi Pedro > > > > Some followup on mmap() + mprotect(): > > > > On Wed, Oct 18, 2023 at 11:20 AM Jeff Xu wrote: > > > > > > On Tue, Oct 17, 2023 at 3:35 PM Pedro Falcato > > > wrote:

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-20 Thread Theo de Raadt
Stephen Röttger wrote: > > I do like us starting with just "mimmutable()", since it already > > exists. Particularly if chrome already knows how to use it. > > > > Maybe add a flag field (require it to be zero initially) just to allow > > any future expansion. Maybe the chrome team has *wanted* t

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-20 Thread Theo de Raadt
Stephen Röttger wrote: > > > IMO: The approaches mimmutable() and mseal() took are different, but > > > we all want to seal the memory from attackers and make the linux > > > application safer. > > > > I think you are building mseal for chrome, and chrome alone. > > > > I do not think this will w

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-19 Thread Linus Torvalds
On Thu, 19 Oct 2023 at 15:47, Pedro Falcato wrote: > > > > For mprotect()/mmap(), is Linux implementation limited by POSIX ? > > No. POSIX works merely as a baseline that UNIX systems aim towards. > You can (and very frequently do) extend POSIX interfaces (in fact, > it's how most of POSIX was wri

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-19 Thread Pedro Falcato
On Thu, Oct 19, 2023 at 6:30 PM Jeff Xu wrote: > > Hi Pedro > > Some followup on mmap() + mprotect(): > > On Wed, Oct 18, 2023 at 11:20 AM Jeff Xu wrote: > > > > On Tue, Oct 17, 2023 at 3:35 PM Pedro Falcato > > wrote: > > > > > > > > > > > > > I think it's worth pointing out that this suggesti

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-19 Thread Jeff Xu
Hi Pedro Some followup on mmap() + mprotect(): On Wed, Oct 18, 2023 at 11:20 AM Jeff Xu wrote: > > On Tue, Oct 17, 2023 at 3:35 PM Pedro Falcato wrote: > > > > > > > > > > I think it's worth pointing out that this suggestion (with PROT_*) > > > > could easily integrate with mmap() and as such a

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-19 Thread Stephen Röttger
> > IMO: The approaches mimmutable() and mseal() took are different, but > > we all want to seal the memory from attackers and make the linux > > application safer. > > I think you are building mseal for chrome, and chrome alone. > > I do not think this will work out for the rest of the application

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-19 Thread Stephen Röttger
> I do like us starting with just "mimmutable()", since it already > exists. Particularly if chrome already knows how to use it. > > Maybe add a flag field (require it to be zero initially) just to allow > any future expansion. Maybe the chrome team has *wanted* to have some > finer granularity thi

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-18 Thread Theo de Raadt
Jeff Xu wrote: > On Wed, Oct 18, 2023 at 8:17 AM Matthew Wilcox wrote: > > > > Let's start with the purpose. The point of mimmutable/mseal/whatever is > > to fix the mapping of an address range to its underlying object, be it > > a particular file mapping or anonymous memory. After the call su

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-18 Thread Jeff Xu
On Wed, Oct 18, 2023 at 8:17 AM Matthew Wilcox wrote: > > Let's start with the purpose. The point of mimmutable/mseal/whatever is > to fix the mapping of an address range to its underlying object, be it > a particular file mapping or anonymous memory. After the call succeeds, > it must not be po

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-18 Thread Jeff Xu
On Tue, Oct 17, 2023 at 3:35 PM Pedro Falcato wrote: > > > > > > > I think it's worth pointing out that this suggestion (with PROT_*) > > > could easily integrate with mmap() and as such allow for one-shot > > > mmap() + mseal(). > > > If we consider the common case as 'addr = mmap(...); mseal(add

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-18 Thread Matthew Wilcox
On Tue, Oct 17, 2023 at 08:18:47PM -0700, Jeff Xu wrote: > In practice: libc could do below: > #define MM_IMMUTABLE > (MM_SEAL_MPROTECT|MM_SEAL_MUNMAP|MM_SEAL_MREMAP|MM_SEAL_MMAP) > mseal(add,len, MM_IMMUTABLE) > it will be equivalent to BSD's immutable(). No, it wouldn't, because you've carefully

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Theo de Raadt
Jeff Xu wrote: > In linux cases, I think, eventually, mseal() will have a bigger scope than > BSD's mimmutable(). I don't believe that, considering noone needed this behaviour from the VM system in the last 4 decades. > VMA's metadata(vm_area_struct) contains a lot > of control info, depending

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Jeff Xu
On Tue, Oct 17, 2023 at 4:57 PM Theo de Raadt wrote: > > Jeff Xu wrote: > > > May I ask, for BSD's implementation of immutable(), do you cover > > things such as mlock(), > > madvice() ? or just the protection bit (WRX) + remap() + unmap(). > > It only prevents removal of the mapping, placement o

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Theo de Raadt
Jeff Xu wrote: > May I ask, for BSD's implementation of immutable(), do you cover > things such as mlock(), > madvice() ? or just the protection bit (WRX) + remap() + unmap(). It only prevents removal of the mapping, placement of a replacement mapping, or changing the existing permissions. If o

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Jeff Xu
On Tue, Oct 17, 2023 at 11:20 AM Theo de Raadt wrote: > > Linus Torvalds wrote: > > > On Tue, 17 Oct 2023 at 02:08, Jeff Xu wrote: > > > > > > It is probably worth noting that I choose to check one and only > > > one sealing type per syscall. i.e. munmap(2) checks > > > MM_SEAL_MUNMAP only. > >

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Pedro Falcato
On Tue, Oct 17, 2023 at 10:34 PM Jeff Xu wrote: > > On Tue, Oct 17, 2023 at 8:30 AM Pedro Falcato wrote: > > > > On Mon, Oct 16, 2023 at 4:18 PM Matthew Wilcox wrote: > > > > > > On Mon, Oct 16, 2023 at 02:38:19PM +, jef...@chromium.org wrote: > > > > Modern CPUs support memory permissions s

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Jeff Xu
On Tue, Oct 17, 2023 at 8:30 AM Pedro Falcato wrote: > > On Mon, Oct 16, 2023 at 4:18 PM Matthew Wilcox wrote: > > > > On Mon, Oct 16, 2023 at 02:38:19PM +, jef...@chromium.org wrote: > > > Modern CPUs support memory permissions such as RW and NX bits. Linux has > > > supported NX since the r

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Theo de Raadt
Linus Torvalds wrote: > On Tue, 17 Oct 2023 at 11:20, Theo de Raadt wrote: > > > > The only case where the immutable marker is ignored is during address space > > teardown as a result of process termination. > > .. and presumably also execve()? Ah yes of course that also. > I do like us start

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Linus Torvalds
On Tue, 17 Oct 2023 at 11:20, Theo de Raadt wrote: > > The only case where the immutable marker is ignored is during address space > teardown as a result of process termination. .. and presumably also execve()? I do like us starting with just "mimmutable()", since it already exists. Particularly

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Theo de Raadt
Linus Torvalds wrote: > On Tue, 17 Oct 2023 at 02:08, Jeff Xu wrote: > > > > It is probably worth noting that I choose to check one and only > > one sealing type per syscall. i.e. munmap(2) checks > > MM_SEAL_MUNMAP only. > > Yeah, this is wrong. > > It's wrong exactly because other system cal

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Linus Torvalds
On Tue, 17 Oct 2023 at 02:08, Jeff Xu wrote: > > It is probably worth noting that I choose to check one and only > one sealing type per syscall. i.e. munmap(2) checks > MM_SEAL_MUNMAP only. Yeah, this is wrong. It's wrong exactly because other system calls will unmap things too. Using mmap() to

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Pedro Falcato
On Mon, Oct 16, 2023 at 4:18 PM Matthew Wilcox wrote: > > On Mon, Oct 16, 2023 at 02:38:19PM +, jef...@chromium.org wrote: > > Modern CPUs support memory permissions such as RW and NX bits. Linux has > > supported NX since the release of kernel version 2.6.8 in August 2004 [1]. > > This seems

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Matthew Wilcox
On Tue, Oct 17, 2023 at 01:34:35AM -0700, Jeff Xu wrote: > > > types: bit mask to specify which syscall to seal, currently they are: > > > MM_SEAL_MSEAL 0x1 > > > MM_SEAL_MPROTECT 0x2 > > > MM_SEAL_MUNMAP 0x4 > > > MM_SEAL_MMAP 0x8 > > > MM_SEAL_MREMAP 0x10 > > > > I don't understand why we want th

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Jeff Xu
Hello Linus, Thank you for the time reviewing this patch set. On Mon, Oct 16, 2023 at 10:23 AM Linus Torvalds wrote: > > On Mon, 16 Oct 2023 at 07:38, wrote: > > > > This patchset proposes a new mseal() syscall for the Linux kernel. > > So I have no objections to adding some kind of "lock down

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Jeff Xu
Hi Jann, Thank you for reviewing the patch and comments. On Mon, Oct 16, 2023 at 10:35 AM Jann Horn wrote: > > On Mon, Oct 16, 2023 at 4:38 PM wrote: > > > > From: Jeff Xu > > > > This patchset proposes a new mseal() syscall for the Linux kernel. > > > > Modern CPUs support memory permissions

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-17 Thread Jeff Xu
Hi Matthew. Thanks for your comments and time to review the patchset. On Mon, Oct 16, 2023 at 8:18 AM Matthew Wilcox wrote: > > On Mon, Oct 16, 2023 at 02:38:19PM +, jef...@chromium.org wrote: > > Modern CPUs support memory permissions such as RW and NX bits. Linux has > > supported NX since

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-16 Thread Jann Horn
On Mon, Oct 16, 2023 at 4:38 PM wrote: > > From: Jeff Xu > > This patchset proposes a new mseal() syscall for the Linux kernel. > > Modern CPUs support memory permissions such as RW and NX bits. Linux has > supported NX since the release of kernel version 2.6.8 in August 2004 [1]. > The memory pe

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-16 Thread Linus Torvalds
On Mon, 16 Oct 2023 at 07:38, wrote: > > This patchset proposes a new mseal() syscall for the Linux kernel. So I have no objections to adding some kind of "lock down memory mappings" model, but this isn't it. First off, the simple stuff: the commit messages are worthless. Having check seal f

Re: [RFC PATCH v1 0/8] Introduce mseal() syscall

2023-10-16 Thread Matthew Wilcox
On Mon, Oct 16, 2023 at 02:38:19PM +, jef...@chromium.org wrote: > Modern CPUs support memory permissions such as RW and NX bits. Linux has > supported NX since the release of kernel version 2.6.8 in August 2004 [1]. This seems like a confusing way to introduce the subject. Here, you're talki