Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752221AbdCCUuw (ORCPT ); Fri, 3 Mar 2017 15:50:52 -0500 Received: from mail-ua0-f174.google.com ([209.85.217.174]:36421 "EHLO mail-ua0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751989AbdCCUuv (ORCPT ); Fri, 3 Mar 2017 15:50:51 -0500 MIME-Version: 1.0 In-Reply-To: <1488466831-13918-1-git-send-email-hoeun.ryu@gmail.com> References: <1488466831-13918-1-git-send-email-hoeun.ryu@gmail.com> From: Andy Lutomirski Date: Fri, 3 Mar 2017 12:50:28 -0800 Message-ID: Subject: Re: [RFC] arm64: support HAVE_ARCH_RARE_WRITE To: Hoeun Ryu Cc: "kernel-hardening@lists.openwall.com" , "linux-kernel@vger.kernel.org" , Kees Cook , Mark Rutland , Andy Lutomirski , Emese Revfy , Russell King , PaX Team , X86 ML Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1194 Lines: 39 On Thu, Mar 2, 2017 at 7:00 AM, Hoeun Ryu wrote: > +unsigned long __rare_write_rw_alias_start = TASK_SIZE_64 / 4; > + > +__always_inline unsigned long __arch_rare_write_map(void) > +{ > + struct mm_struct *mm = &rare_write_mm; > + > + preempt_disable(); > + > + __switch_mm(mm); ... > +__always_inline unsigned long __arch_rare_write_unmap(void) > +{ > + struct mm_struct *mm = current->active_mm; > + > + __switch_mm(mm); > + This reminds me: this code imposes constraints on the context in which it's called. I'd advise making it very explicit, asserting correctness, and putting the onus on the caller to set things up. For example: DEBUG_LOCKS_WARN_ON(preemptible() || in_interrupt() || in_nmi()); in both the map and unmap functions, along with getting rid of the preempt_disable(). I don't think we want the preempt-disabledness to depend on the arch. The generic non-arch rare_write helpers can do the preempt_disable(). This code also won't work if the mm is wacky when called. On x86, we could do: DEBUG_LOCKS_WARN_ON(read_cr3() != current->active_mm->pgd); or similar (since that surely doesn't compile as is). --Andy