Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3645480ioo; Wed, 25 May 2022 05:18:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzITDzlRandKev6iS8R+UoOz+VKKd+GkiJqTEq/Ou+9Dfkm4/NL3837vj9LZg5oSWwrwr3L X-Received: by 2002:a17:902:ca81:b0:163:60de:ac15 with SMTP id v1-20020a170902ca8100b0016360deac15mr1629991pld.172.1653481110807; Wed, 25 May 2022 05:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653481110; cv=none; d=google.com; s=arc-20160816; b=tDqNCH5lGo8PFxZRfZY4cmjmDi4YEUX8DixIIYhy+BjX826avf+Q/ZqTrd58GC5FE/ pwzcKAHHqraOz2YWsLKJNVouKTOupq5KnUO7vBEhfOpz2UvPDznVSict1/IPN+evE/Lz jMJ3pkxXVYkNp39B5LW7pDApMbu3+tCi4MIz48fRgpv6UjdDF0f5Y3G9UZ3NtdkHb2wG o7bDmMxyQhdNCcWHtxBBdrre55ZffXqo4IJuzBegTpe9fvjRBuCz5EW+O1aWrixlA06V mPm/3LJwG69CcOu+5zvHS621Vb3jKLkGzp0IPvMxqXs+F8O44r0TDRF7NolCjQi2EHVh K3Sg== 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=YUnVxa5pnWd8D3oQLkMmXCsz6an77MCtCR1yPtv/LsQ=; b=t3g+jpFuVvPpivoCJrpC/MaYg5N07QTCMGAEhoxPActSaqKLjWY3A5L0iujfWt2ohb YCzx3Guinq7GULFDT69SCQkUY1dW7AJpcMe93br9LXdyEuFAQYDsmAL3S7qHpjK35E1j cihE5O/Os+TfN1zHB4OBskCflSD6e8+GTrsfZxy7qtap2i5hf2KcfSIrdmYae7v2d8CH iSoQYBevJjhaq9gY/XWXrYStxu0ehiseZnnJptr7TiiRcafsJhAdjZk0XBsZvATiU20c lPmiT1y3qGJQnPE1aI7IDyruekcTz4GSuJ6b6QNkKrWfBxUg9awQ9EM+2klnFmKzIwV9 AhZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="VSYu/Wzf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020a17090311cc00b00161d3902fcfsi22456483plh.453.2022.05.25.05.18.13; Wed, 25 May 2022 05:18:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="VSYu/Wzf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S241034AbiEXUWj (ORCPT + 99 others); Tue, 24 May 2022 16:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234228AbiEXUWg (ORCPT ); Tue, 24 May 2022 16:22:36 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCA5F54BC3 for ; Tue, 24 May 2022 13:22:34 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id z25so4706978pfr.1 for ; Tue, 24 May 2022 13:22:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YUnVxa5pnWd8D3oQLkMmXCsz6an77MCtCR1yPtv/LsQ=; b=VSYu/WzfHyNKrcVPPaxgRUerwl88cq5BG0EKH4DrtupwYUlU8DEcGjsDzAizLKW2Qt Le6afW2RDgD/ZQ2H87iYUqm7AjSq0acsYfxJ3NwWSWp5/B8TkjNrubmA6StzF2yl2c30 gLeLi4cktX2vCJGBi3ZXJC8vVhiakpEeT3Q0O4dX1EsczAPYVxcMz0JZANKldm284Ndj wi8HRuAzvK0C3BqyFhMdsXlblK9pb/TzDvFopEHEWz50TrWSIq2o06x5lB3fbgPHArgI 8rmfpApZ1rz+nMfUBzLSUXlTf4HLS7SHuw+b191b/2mmWeMJSHpPUMjVAoT0u44Rb29M cO+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YUnVxa5pnWd8D3oQLkMmXCsz6an77MCtCR1yPtv/LsQ=; b=LLcar6m1a1INbcUrqngNhGXFc6pdhpXjWhhOnN9fiams4nlas/ZbJCI6x8b9XbDmNj mr1ifloTKZPSJRXoG4kaD3PpW/lPw7rk5zZA2Tn3CNQpguzLAS0FWKYa6AJ4r8Khdsd8 i2G0c3nZlG3uEmld+pGG/kxnvCvq6aBhDpLvlS4ZDOxwkyZfdrcmbILRPMknbJCzUISs 51NVs9W1J1WyKdLw46ydTdgICB8d0PVaUs4jMr1zPsXBEOFj+CLuv7YQgJ4mScGCH9KP 0GgfkPO+UTYdhwfXb8tGSBCpo59lL5oI1mRqsMoCRoFLMNthLGQ1/wGnv+TBuh2Xq3h5 uceQ== X-Gm-Message-State: AOAM532ParoDpGibBcmvU1SEPVihFHAuyhh6Mt3qLvFJPbeLSTOGfuRY DsBeC3ZO880fYxcb+wOT/N4pbQ== X-Received: by 2002:a63:4387:0:b0:3c6:9490:4e4b with SMTP id q129-20020a634387000000b003c694904e4bmr25290534pga.438.1653423754123; Tue, 24 May 2022 13:22:34 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id h186-20020a62dec3000000b0050dc7628191sm9847289pfg.107.2022.05.24.13.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 13:22:33 -0700 (PDT) Date: Tue, 24 May 2022 20:22:30 +0000 From: Sean Christopherson To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Dave Hansen , Mel Gorman , Tom Lendacky , Rick Edgecombe , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Kirill A. Shutemov" , Tianyu Lan , "Aneesh Kumar K.V" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, vbabka@suse.cz, akpm@linux-foundation.org, willy@infradead.org Subject: Re: Is _PAGE_PROTNONE set only for user mappings? Message-ID: References: <20220506051940.156952-1-42.hyeyoo@gmail.com> <56f89895-601e-44c9-bda4-5fae6782e27e@amd.com> <5fe161cb-6c55-6c4d-c208-16c77e115d3f@amd.com> <8c2735ac-0335-6e2a-8341-8266d5d13c30@intel.com> <20220512103748.GH3441@techsingularity.net> <3f2f7c09-ddf3-6052-9860-8554a4ff2798@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 22, 2022, Hyeonggon Yoo wrote: > On Mon, May 16, 2022 at 07:04:32AM -0700, Dave Hansen wrote: > > I was thinking of something more along the lines of taking the > > set_memory.c code and ensuring that it never sets (or even observes) > > _PAGE_BIT_GLOBAL on a _PAGE_USER mapping. > > Yeah that would be a bit more explicit solution. > > > There was also a question of > > if set_memory.c is ever used on userspace mappings. It would be good to > > validate whether it's possible in-tree today and if not, enforce that > > _PAGE_USER PTEs should never even be observed with set_memory.c. > > Simply adding dump_stack() tells me my kernel on my machine does not use > set_memory.c for userspace mappings but Hmm I'll take a look. vc_slow_virt_to_phys() uses lookup_address_in_pgd() with user mappings, but that code is all but guaranteed to be buggy, e.g. doesn't guard against concurrent modifications to user mappings. show_fault_oops() can also call into lookup_address_in_pgd() with a user mapping, though at that point the kernel has bigger problems since it's executing from user memory. And up until commits 44187235cbcc ("KVM: x86/mmu: fix potential races when walking host page table") and 643d95aac59a ("Revert "x86/mm: Introduce lookup_address_in_mm()""), KVM had a similar bug. Generally speaking, set_memory.c is not equipped to play nice with user mappings. It mostly "works", but there are races galore. IMO, hardening set_memory.c to scream if it's handed a user address or encounters _PAGE_USER PTEs would be a very good thing.