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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4095FC32773 for ; Fri, 19 Aug 2022 20:12:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A1B18D0003; Fri, 19 Aug 2022 16:12:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 750248D0001; Fri, 19 Aug 2022 16:12:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EFFE8D0003; Fri, 19 Aug 2022 16:12:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4D8658D0001 for ; Fri, 19 Aug 2022 16:12:49 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2840D1A0E20 for ; Fri, 19 Aug 2022 20:12:49 +0000 (UTC) X-FDA: 79817440458.23.8412DE3 Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) by imf07.hostedemail.com (Postfix) with ESMTP id A0EBD40144 for ; Fri, 19 Aug 2022 20:12:48 +0000 (UTC) Received: by mail-io1-f52.google.com with SMTP id b142so4111885iof.10 for ; Fri, 19 Aug 2022 13:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=TWnGx0tsPzDsYWN5IvwyG0/F4n3/lHDuvrydVsnCdTg=; b=FamF99POPr6PtKGcfiAFaDyK/px9/QEUZ9jAWq0VuRMjBQuH/SIEycINUXdEisf8wJ GB5Fp0sV/9jsr8SHRoKkycJAodjombPVpppk1giNuh7jurYysChORzMPgyHKQdBRx6Yi bMQ8CZykRl92tAcPu+aCfb2R1BHuyiGBmYyICNbj6NOdCbqR0y056zBRI5sucULdSXWP iBSs6go4YjTUccStqlOuQrHTd0ys3ntGBcGxqR0SgI4W+Fz4sL7vOXN4324d30h8iu/T k8P9H+ggVIlKLOTUU3V6HrleaFRS/uGb9Vw8lQ57cl7kluTFPaNsmbjckIsP6sE3O2xR GObw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=TWnGx0tsPzDsYWN5IvwyG0/F4n3/lHDuvrydVsnCdTg=; b=K14cd23v5D2catZSVerbU1SnQsYyhMcgZcExjZSgnfP9rqaTmq6VvUgBrhVY+m53Qr FYYyPDGuPRsqcHcrxmwUeH98YsYgqv5t9UbvNkR2pMmos6am2PLVUlSPa2am0FtyG9eP 9QO6qOTTQB2iO2nVQgdooDWs79+kmfILJOQa5SKwT3ejz2fKsgtB8NwJan1yQDENkvrK T3FiITg+rNJLx6L6RslvI5qVP9OGssq/6FSbduf3OwewwOUE6F2bnSs3+DjZJU7bPsZl 7+WsVvQTEceFhxbWkoVw76NDbDQsQzi+lNnXl14ITZ+fMjt4xQpYrboT8eFyeJZFRbyh Yf8w== X-Gm-Message-State: ACgBeo0sk0UdXdmO7c5vkaA6JLDK1Tv6eMioH7erJVDhDFlI2LpoTaYu f3Bp3sCFm7LD4386EndvvMz0i+vDsFy2IMUi8y93Lg== X-Google-Smtp-Source: AA6agR7vH6bU/CcMRlqauAdte2pei9jmt+xQRqGJlV8ch8ekID2WY8/GjnEURxqW3LnsWWhfJJAGPXkSfSDz0FeaHIw= X-Received: by 2002:a05:6638:34a8:b0:343:4d0a:5984 with SMTP id t40-20020a05663834a800b003434d0a5984mr4292780jal.167.1660939967732; Fri, 19 Aug 2022 13:12:47 -0700 (PDT) MIME-Version: 1.0 References: <20220817214728.489904-1-axelrasmussen@google.com> <20220817214728.489904-3-axelrasmussen@google.com> In-Reply-To: From: Axel Rasmussen Date: Fri, 19 Aug 2022 13:12:10 -0700 Message-ID: Subject: Re: [PATCH v6 2/5] userfaultfd: add /dev/userfaultfd for fine grained access control To: Greg KH Cc: Alexander Viro , Andrew Morton , Dave Hansen , "Dmitry V . Levin" , Gleb Fotengauer-Malinovskiy , Hugh Dickins , Jan Kara , Jonathan Corbet , Mel Gorman , Mike Kravetz , Mike Rapoport , Nadav Amit , Peter Xu , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , zhangyi , linux-doc@vger.kernel.org, linux-fsdevel , LKML , Linuxkselftest , Linux MM , linux-security-module@vger.kernel.org, Mike Rapoport Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660939968; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TWnGx0tsPzDsYWN5IvwyG0/F4n3/lHDuvrydVsnCdTg=; b=lwZIwRdjKsANeTdd0JlNsRBKxRwVnxO37QYrvysPo7s2DcJ8tOu6xgQygnIOnQ6Bz/jpP+ AXcukz/cvUCVbFt4QjmlDT5z5OOrzVJhQzMJQhGl6swMXfafl5IKV1tJED8ftaJM7keks4 7vlY4RXrbxTxDcLw6Pwwmgs/PirPJFA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FamF99PO; spf=pass (imf07.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.166.52 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660939968; a=rsa-sha256; cv=none; b=fjLz3TWIJcWqK2QVU1W/pIKyeY+otn8R4eGTUGtwfI6JVI1aNtKAKv+4ayvvRl5s9gY4W7 pN8mQK46oF3myOZA3NoRFb3+VWyqBXvnEEn6xCGZVbmgcBAX+S0hBu6givTphNkq2zB+fv z9AzEM/+uW2mzccBEjJnHCjuw002+78= X-Stat-Signature: q1oqkao6t3rzfjftr95u195syoxqsmgi X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FamF99PO; spf=pass (imf07.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.166.52 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A0EBD40144 X-HE-Tag: 1660939968-253396 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Aug 17, 2022 at 11:26 PM Greg KH wrote: > > On Wed, Aug 17, 2022 at 02:47:25PM -0700, Axel Rasmussen wrote: > > +static int userfaultfd_dev_open(struct inode *inode, struct file *file) > > +{ > > + return 0; > > If your open does nothing, no need to list it here at all, right? > > > +} > > + > > +static long userfaultfd_dev_ioctl(struct file *file, unsigned int cmd, unsigned long flags) > > +{ > > + if (cmd != USERFAULTFD_IOC_NEW) > > + return -EINVAL; > > + > > + return new_userfaultfd(flags); > > +} > > + > > +static const struct file_operations userfaultfd_dev_fops = { > > + .open = userfaultfd_dev_open, > > + .unlocked_ioctl = userfaultfd_dev_ioctl, > > + .compat_ioctl = userfaultfd_dev_ioctl, > > Why do you need to set compat_ioctl? Shouldn't it just default to the > existing one? I took some more time looking at this today, and I think it actually has to be the way it is. I didn't find anywhere we noticed compat_ioctl unset, and default to the "normal" one (e.g. see the compat ioctl syscall definition in fs/ioctl.c). It looks to me like it really does need some value. It's common to use compat_ptr_ioctl for this, but since we're interpreting the arg as a scalar not as a pointer, doing that here would be incorrect. It looks like there are other existing examples that do it the same way, e.g. seccomp_notify_ops in linux/seccomp.c. > > And why is this a device node at all? Shouldn't the syscall handle all > of this (to be honest, I didn't read anything but the misc code, sorry.) > > thanks, > > greg k-h