Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1209849pxu; Sat, 24 Oct 2020 04:05:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznjyp6Ul0VRErB8KY25yXHGm7W307vdrPcTmAsenJ2Wu3AqenfM4F6iclD+ZiLwZfp/0yq X-Received: by 2002:a17:906:d78d:: with SMTP id pj13mr3210916ejb.36.1603537509425; Sat, 24 Oct 2020 04:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603537509; cv=none; d=google.com; s=arc-20160816; b=MgEADalaJkP7jXKnNpXmr4hXH5YKVQxvXr7OFXgSlBXG0/FRh6vtvjoupZUGq/rQ/m HPFd5eeVBSyYxavahHqohVzNvsD5GN/HMao8QNCzl188LvPjkOhLK+CFn+XfgZdwtxAG Pszdh+XGZhmktSCjhe4ADyyM4SGgaiXdbWyl/rrATyx7BWcFGYK2Y7bzJiESnacZ7j1Y D9ztwG4+ESSf4uxncxUb0mIAI3Og51f+tND96unhKosjMPRBrWYVVRI4pXliJ3XiuMCv bbezsMcg3ZLu/NfFgyBJOotrr4DLKTdaKMX5D599zq5MxTrOyNJG06I7L3ZfXCZLyLzo xCVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=dRtLwMVw9c4TiosDDsBOINIbNomLxGOZi2G9fpejdro=; b=zNznHKF7hSGOyNjhammzMGfk0VCfqkB/FXEKybL9pNhkT6HaS7+XYd+vvZ3xFMKNgb V27bdfUq4xPZAfD1y3JGSyHZRiphpm63vWWbY57xMUXm2K76hA1g5TsAcypE3qPDwZXC PyOKSQYCGBxaWm2L7he68faCvxvvhnWxzP9ckrLlaQfGIqxGe1QD98+A7nPuC0LuAS5t YRn/A2QpuyRU4vnslS/mPIHId021BtIxhdhjYHGXM5k6yiwQUY0CPqAOnc2w+2Poya4i s/sJC6Ejm8esnPvIEFR1Y82wWEkuP9hacQxwdtAoE4AJ77ayECXTywlSbK7JB5FKWyAo hOVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LcW1Dnre; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si2726090edq.317.2020.10.24.04.04.46; Sat, 24 Oct 2020 04:05:09 -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=@google.com header.s=20161025 header.b=LcW1Dnre; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759433AbgJXEIR (ORCPT + 99 others); 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-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 >