Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp113011imm; Fri, 7 Sep 2018 17:39:21 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ3QHNn5K5SwrlItgZiKi0yB9Ikh3HiZ97MXrkVLNIBahN3/qFg5ZQE7ayzHKDEnXgE5JPm X-Received: by 2002:a17:902:6681:: with SMTP id e1-v6mr10641438plk.109.1536367161287; Fri, 07 Sep 2018 17:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536367161; cv=none; d=google.com; s=arc-20160816; b=1Lpun3ljqS+74yGg4lZiS65Scz5VjYZDRIG53IjLvbML5aQuHoQW8tLeYYsbxscJ8p vyiTLDRAKS5EnVoT6sNfoVip49uxdo3mVh/RMuGgkgPx/sTjrAYhwP/tTJahTK5MAmmF wu0c609R2wXVHRW0hrF8Z6ychVFnclG11bUjOlqQxAf9JWT95G2WXfGwaPL5xVJaV6Iy /ci7sZ9ufxkzaxQqKqss2nmoLge/VvOoJE7gIQqNIO7N+hZvmOujyhfeODZ25LCYZrQy DoLWwOLSc6mca0ETKvaNwrzPmC1Nep0Lkh4TcQccxqnbCBN6M3/+Hui/Q4nB8Fcn2Yji 7TEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=W1vxdDPtAmulUNUs2/T31hahMNL7ilVK5SxM02gAB1M=; b=zWu/czZWuIS1qASLjtmHcXAIPPXwMTaXya4xz79XZ9uZdfbXit+5IMm5+HU82IzPdu L8C6pb4daLMDbJJ+ZwcjUVYnOe7677PxWse6MQ00tcNur1y4ujswH/QAa4NBLaUhOT23 NGevs6gayYhiSvUwS4ao8U7pPL/80fHfp7DHTAU4S8oq0BiakYmckMALtd2zRecgf9Fc sBYpF/B+74sCPzV3roPumbcZUILQwLWaHms4R3B8xSEBUxulLoz6x5duJYnWPf5cMQyB y7XK+Agp7o39s7dlEIXsNEhjjrpdSIiH82fNmJILu6OYiGbbS7B74w1TARMLUKH9uRk+ 3z1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tD7ped4q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z66-v6si9985972pfl.209.2018.09.07.17.39.05; Fri, 07 Sep 2018 17:39:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tD7ped4q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726248AbeIHFV0 (ORCPT + 99 others); Sat, 8 Sep 2018 01:21:26 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:38233 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbeIHFVZ (ORCPT ); Sat, 8 Sep 2018 01:21:25 -0400 Received: by mail-oi0-f68.google.com with SMTP id x197-v6so30440093oix.5 for ; Fri, 07 Sep 2018 17:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=W1vxdDPtAmulUNUs2/T31hahMNL7ilVK5SxM02gAB1M=; b=tD7ped4qJm6Kj8WhTtwgII0mTJ+ATCQkedui6kAM619RQiXkOF9cw49RIq2gH8Mer8 MmFSPvfBbSYiAMf6B75wfEllvX3p2FTRjpzliofKsxsmv2/2u+v1ghLWbr4NlBsfZE48 OyOrdESEz7isKAaEUXUwHIIJ3sICNA3xnt9DGPgNXrLNnz2V0HRAc4rj2DZMjhmFyJss FHZ0etxWYvbLhZElTviS7P4ssTc5V1t+yMpqaZqPFpzs2sM0y4dEOcKPRNSqOWu9JL0b 0SbfzXLA87U2LIktxy52J1qrPNpKDQTgUHHW1sV0IbRCUY9VcHi3su6BCze+treYlFP/ zR/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W1vxdDPtAmulUNUs2/T31hahMNL7ilVK5SxM02gAB1M=; b=CiATqHCNy2oPHdaNMgKSvKyLuhM5rYTZKOfZCBBskTDXPJhei1NMJtx9dFU68McbNd Ce+z8Rtiq2HKawTA8Wr4fvqpKNb8goUJJSK2O1+oZvzx6bXYRd6wwPP7ocUUVm9YYRqD rcGl9I0syBsi35zSss0fewsmgOSbF7tlJCGKBrwbwAfNFo4/fV0JwDn6b7+UbVHaeUi5 VgBt0hRnFgiHH//xIKAkvvnF3crndAxcdQ5al+yVRtVsYG73yHHkRV+MyAzbOL3rKWT/ kB/tLtA53/F1TssK3fPrlYVZ+CnLp/TRH5aN2BCFAtl1kQKzEeJBpEYuLdozuo7mnhPT 9xOg== X-Gm-Message-State: APzg51AsO67xbo0ZxoXLEh8aRMpeqOI83yCyTPt5FjCOWIZuPLkdN/78 V/0T91VOvJFzUYKvsM9IRAgmfYCqSJnZmxargRMDiA== X-Received: by 2002:aca:e504:: with SMTP id c4-v6mr10144918oih.246.1536367074472; Fri, 07 Sep 2018 17:37:54 -0700 (PDT) MIME-Version: 1.0 References: <20180907194852.3C351B82@viggo.jf.intel.com> <20180907194900.DF3B41C0@viggo.jf.intel.com> In-Reply-To: <20180907194900.DF3B41C0@viggo.jf.intel.com> From: Jann Horn Date: Sat, 8 Sep 2018 02:37:27 +0200 Message-ID: Subject: Re: [RFC][PATCH 5/8] x86/mm: fix exception table comments To: Dave Hansen Cc: kernel list , sean.j.christopherson@intel.com, Peter Zijlstra , Thomas Gleixner , "the arch/x86 maintainers" , Andy Lutomirski Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 8, 2018 at 2:22 AM Dave Hansen wrote: > + * Kernel-mode access to the user address space should only occur > + * inside well-defined areas of code listed in the exception Actually, not areas, but single whitelisted instructions. It would probably be nice to say that more clearly. From arch/x86/include/asm/extable.h: /* * The exception table consists of triples of addresses relative to the * exception table entry itself. The first address is of an instruction * that is allowed to fault, the second is the target at which the program * should continue. The third is a handler function to deal with the fault * caused by the instruction in the first field. * * All the routines below use bits of fixup code that are out of line * with the main instruction path. This means when everything is well, * we don't even have to jump over them. Further, they do not intrude * on our cache or tlb entries. */ struct exception_table_entry { int insn, fixup, handler; }; > + * tables. But, an erroneous kernel fault occurring outside one of > + * those areas which also holds mmap_sem might deadlock attempting > + * to validate the fault against the address space. > * > - * As the vast majority of faults will be valid we will only perform > - * the source reference check when there is a possibility of a > - * deadlock. Attempt to lock the address space, if we cannot we then > - * validate the source. If this is invalid we can skip the address > - * space check, thus avoiding the deadlock: > + * Only do the expensive exception table search when we might be at > + * risk of a deadlock: > + * 1. We failed to acquire mmap_sem, and > + * 2. The access was an explicit kernel-mode access > + * (X86_PF_USER=0). > */ > if (unlikely(!down_read_trylock(&mm->mmap_sem))) { > if (!(sw_error_code & X86_PF_USER) && > !search_exception_tables(regs->ip)) { > + /* > + * Fault from code in kernel from > + * which we do not expect faults. > + */ > bad_area_nosemaphore(regs, sw_error_code, address, NULL); > return; > } > _ >