From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03C0AC56201 for ; Sat, 24 Oct 2020 04:08:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6BE622201 for ; Sat, 24 Oct 2020 04:08:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LcW1Dnre" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759461AbgJXEIR (ORCPT ); Sat, 24 Oct 2020 00:08:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726998AbgJXEIR (ORCPT ); Sat, 24 Oct 2020 00:08:17 -0400 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2EFBC0613D4 for ; Fri, 23 Oct 2020 21:08:15 -0700 (PDT) Received: by mail-il1-x141.google.com with SMTP id k1so3323599ilc.10 for ; Fri, 23 Oct 2020 21:08:15 -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=dRtLwMVw9c4TiosDDsBOINIbNomLxGOZi2G9fpejdro=; b=LcW1DnreOANwAWcycXCj7JMSwdmvQnMjHZjq+r5vMqne5c5pqkAwSg8nlJO7kVT8In 1yypDtDKS+KkVAgj83KgqDQ6/3A40wVCl+wkfL8aWxDgeqrpL373XrgcNf/S0I0HblaZ hf4p1vBLtvLfA3JVE/b2AJAD/cEJY4TlKHK9p+81entvc5/GX4GL1vChHbVPG1CxNfSE JEpNkgIRHW3ITfES5Ynrhlu+km4qbDbn+dMe7oytNQIEtyfvd7aSyx5UV7NSxoqNv7Qg NEbTcgr1ozs8zn9gvWnJUl1Ji+xcFxvNTlDZ+nGxPPgrTAQ514Ldkzjoz8nNZ1X4md2S PKPw== 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=dRtLwMVw9c4TiosDDsBOINIbNomLxGOZi2G9fpejdro=; b=glzEC37VSQO6HrCYLsDNczWjdro/OOZsU+6ltI4cCQu4P0G9nWsvyNLbry/frXOGnr ofTqD7/XugOBNEgTOP1Sm6WCntrN56PjTW7HEcFntRrtrcd6H6rmG9dFYc4Mym055k1W WwmB3bDaQQI+iu01fAsrpPBBOprxFhW5ZsOzyonzhw+GVFEZk3NwHm487AOy4EwXeemw VxCUszpvWa0LWOeR87GW4G6ZolERcsVfGSHd6//xvitcNSCdoIRyp24g/lSj6xVdoWz8 DTMuR66ZnFTDPW8i+exy7Wgp3eP1C6mPniEE/57a3zT5HM3nmi6Geztjisb/yGA/LBXR 83hQ== X-Gm-Message-State: AOAM531oxBSQwt0Ehk14j+XB75zBq3cljcEooBcBXBF2Kqx0iKEnB8yI ahHyIQhm6aYaPTBRE2vQBElVUSyC5O87AhL0TWFVcA== X-Google-Smtp-Source: ABdhPJwYJ4cjiyenZUUzWqjwd6gBGW90EGk9W0ItKjzOqVrTj+T5PIcn1mVzrMSn5pP+aJPfFqW53AlUxNSMhJvF5YY= X-Received: by 2002:a92:494c:: with SMTP id w73mr4286150ila.104.1603512494532; Fri, 23 Oct 2020 21:08:14 -0700 (PDT) MIME-Version: 1.0 References: <20201011062456.4065576-1-lokeshgidra@google.com> <20201011062456.4065576-3-lokeshgidra@google.com> <20201024024835.GC19707@redhat.com> In-Reply-To: <20201024024835.GC19707@redhat.com> From: Lokesh Gidra Date: Fri, 23 Oct 2020 21:08:03 -0700 Message-ID: Subject: Re: [PATCH v5 2/2] Add user-mode only option to unprivileged_userfaultfd sysctl knob To: Andrea Arcangeli Cc: Kees Cook , Jonathan Corbet , Peter Xu , Sebastian Andrzej Siewior , Andrew Morton , Alexander Viro , Stephen Smalley , Eric Biggers , Daniel Colascione , "Joel Fernandes (Google)" , Linux FS Devel , linux-kernel , linux-doc@vger.kernel.org, Kalesh Singh , Calin Juravle , Suren Baghdasaryan , Nick Kralevich , Jeffrey Vander Stoep , "Cc: Android Kernel" , Mike Rapoport , Shaohua Li , Jerome Glisse , Mauro Carvalho Chehab , Johannes Weiner , Mel Gorman , Nitin Gupta , Vlastimil Babka , Iurii Zaikin , Luis Chamberlain Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 23, 2020 at 7:48 PM Andrea Arcangeli wrote: > > Hello everyone, > > On Sat, Oct 10, 2020 at 11:24:56PM -0700, Lokesh Gidra wrote: > > With this change, when the knob is set to 0, it allows unprivileged > > users to call userfaultfd, like when it is set to 1, but with the > > restriction that page faults from only user-mode can be handled. > > In this mode, an unprivileged user (without SYS_CAP_PTRACE capability) > > must pass UFFD_USER_MODE_ONLY to userfaultd or the API will fail with > > EPERM. > > > > This enables administrators to reduce the likelihood that > > an attacker with access to userfaultfd can delay faulting kernel > > code to widen timing windows for other exploits. > > > > The default value of this knob is changed to 0. This is required for > > correct functioning of pipe mutex. However, this will fail postcopy > > live migration, which will be unnoticeable to the VM guests. To avoid > > this, set 'vm.userfault = 1' in /sys/sysctl.conf. For more details, > > refer to Andrea's reply [1]. > > > > [1] https://lore.kernel.org/lkml/20200904033438.GI9411@redhat.com/ > > > > Signed-off-by: Lokesh Gidra > > Nobody commented so it seems everyone is on board with this change to > synchronize the kernel default with the post-boot Android default. > > The email in the link above was pretty long, so the below would be a > summary that could be added to the commit header: > > == > > The main reason this change is desirable as in the short term is that > the Android userland will behave as with the sysctl set to zero. So > without this commit, any Linux binary using userfaultfd to manage its > memory would behave differently if run within the Android userland. > > == Sure. I'll add it in the next revision. > > Reviewed-by: Andrea Arcangeli > Thanks so much for the review. I hope it's ok to add your 'reviewed-by' in the next revision? > > BTW, this is still a minor nitpick, but a printk_once of the 1/2 could > be added before the return -EPERM too, that's actually what I meant > when I suggested to add a printk_once :), however the printk_once you > added can turn out to be useful too for devs converting code to use > bounce buffers, so it's fine too, just it could go under DEBUG_VM and > to be ratelimited (similarly to the "FAULT_FLAG_ALLOW_RETRY missing > %x\n" printk). I'll move the printk_once from 1/2 to this patch, as you suggested. > > Thanks, > Andrea >