Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp434005pxb; Mon, 25 Oct 2021 11:07:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXfTJyO6LnoC6O07xTUKu93GIDBs5sOJviDnA76Xql5s7iJeFejQxYzSdr+MoNN9tfH3Jq X-Received: by 2002:a17:906:13ce:: with SMTP id g14mr15238052ejc.203.1635185221908; Mon, 25 Oct 2021 11:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635185221; cv=none; d=google.com; s=arc-20160816; b=qj27w3fb364Bwit4lJfA8S/U0OLhfKIVoYdJvwmSZR/SCZxP54ziTOXj/ewT7TmA3j wJWd1iJK0TieUymo2sqOf1f+gj+WUep8+D2VX/Z6WP8X1wC7azyKB7XyGCKvKaMUFeAH iKpVfqE3DSrjRSJGClZIbcv4jkO6IQwUwu2GrRQw54VN1DjCB/3CeNqONY5LiAe8Zgpt cCpdtSy7vrbyNu0vjAUb42XDzoJpOdd5+o9ptpEYQWMoZqMUZWlOmTR4kSal8Sd5aplH viwNuGLtAmxZlowf+KT4takXdYbAFH564LHyhTaYzRfHrccHcPdr/rX+qD1d9i+A1G+r zImA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=acPLA71S1ep7pYBvutH8rAYXBSbDlehTnu3UD961M04=; b=jFd6gq91H01MAe9eAipwfAsMWCuq9NMCTolB5YfeN2irTh+5YsQeFhWw6spr1YY/ie ZSQ2poGaKarl1S9q5cPDy9oZCXvuXmBkGWW7VT44vvhLCNIjUgb9HhbgLy6+Gs3yz+TV 5jIh+EUNKutPlBY7QrYS0CPAeC7cmjMJRp0REzPmdhHF5upXf+/WEpAqnxmjMpmIPgc3 TSRhaI/MvauLqa+lSGuW5rA53KkpF2L/jGdlaJawFdE2EdoZLL4JpdihdLPo/uZLt0rR 5piYSEwD2nUwWIB0UO+La6g+u6OR8PZujR7J59E1VRypc7r1OeJenUEQsZ6dt3+i4HFb m+xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=FIjBlj52; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r20si29480797edd.587.2021.10.25.11.06.36; Mon, 25 Oct 2021 11:07:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=FIjBlj52; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232585AbhJYLCf (ORCPT + 99 others); Mon, 25 Oct 2021 07:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbhJYLCd (ORCPT ); Mon, 25 Oct 2021 07:02:33 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E8DC061745 for ; Mon, 25 Oct 2021 04:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=acPLA71S1ep7pYBvutH8rAYXBSbDlehTnu3UD961M04=; b=FIjBlj52Y8W6YmMnXMkuPpo4u3 aWPYKAZG3rmv1OW4UfS953EDP3UVSfXwLZJetgX2iGwm4pTvo0ftDFJE19juoV/GZgoosmTYQqYu+ M1I/MCKsgq3f3rj1hVb9VZ/of6kP3lNl6CxEsk8FXjIXpLo1tk+hssqJ0jdCfTBgxWsY5b6fulEHm n7wPW9/5TaDte5l5qbBbJZMaqztRueLYDn2E7kJqLtu0bqFmC9ZmRZm0yoUG3z4QbvU42JHgHH7bp jfAF7WdEkEotfpXKAlbtWcF9Nrx/82oGtZ+h26XqPzT7yBJYjN5nt/OCscg8nM4rpGNUqnkUtXTF5 wDSKMwQA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mexht-00C8Ba-PZ; Mon, 25 Oct 2021 10:59:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A6849300230; Mon, 25 Oct 2021 12:59:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8F67D20C6C14F; Mon, 25 Oct 2021 12:59:56 +0200 (CEST) Date: Mon, 25 Oct 2021 12:59:56 +0200 From: Peter Zijlstra To: Nadav Amit Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nadav Amit , Andrea Arcangeli , Andrew Cooper , Andrew Morton , Andy Lutomirski , Dave Hansen , Peter Xu , Thomas Gleixner , Will Deacon , Yu Zhao , Nick Piggin , x86@kernel.org Subject: Re: [PATCH v2 3/5] x86/mm: check exec permissions on fault Message-ID: References: <20211021122112.592634-1-namit@vmware.com> <20211021122112.592634-4-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211021122112.592634-4-namit@vmware.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 21, 2021 at 05:21:10AM -0700, Nadav Amit wrote: > From: Nadav Amit > Add a check to prevent access_error() from returning mistakenly that > page-faults due to instruction fetch are not allowed. Intel SDM does not > indicate whether "instruction fetch" and "write" in the hardware error > code are mutual exclusive, so check both before returning whether the > access is allowed. Dave, can we get that clarified? It seems a bit naf and leads to confusing code IMO. Other than that, the change looks ok to me. > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index b2eefdefc108..e776130473ce 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -1100,10 +1100,17 @@ access_error(unsigned long error_code, struct vm_area_struct *vma) > (error_code & X86_PF_INSTR), foreign)) > return 1; > > - if (error_code & X86_PF_WRITE) { > + if (error_code & (X86_PF_WRITE | X86_PF_INSTR)) { > /* write, present and write, not present: */ > - if (unlikely(!(vma->vm_flags & VM_WRITE))) > + if ((error_code & X86_PF_WRITE) && > + unlikely(!(vma->vm_flags & VM_WRITE))) > return 1; > + > + /* exec, present and exec, not present: */ > + if ((error_code & X86_PF_INSTR) && > + unlikely(!(vma->vm_flags & VM_EXEC))) > + return 1; > + > return 0; > }