Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3890605rwb; Fri, 30 Sep 2022 09:40:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5rkHJk/1OupY9Tfe18gjLwrsiJstXjcQ3NKopFBs1RfV5nwSOiJ1nQIuVkAGc+3XaMULuq X-Received: by 2002:a63:d456:0:b0:43b:f4a3:81b5 with SMTP id i22-20020a63d456000000b0043bf4a381b5mr8307071pgj.200.1664556015419; Fri, 30 Sep 2022 09:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664556015; cv=none; d=google.com; s=arc-20160816; b=SAR7uiMnjNEWudCJlHZVZeqkBvLbnt/p6sj1dSjOuLCZ3AYSEDuAtpVuXhcd5ktiet BomGil30wL1UrKVZDdU+UCoqclBQRqI2B9lIbaLBxVaER3sq/FyxiD7lIsCgaZZVWyKe euVpTOkTwG4wSq0g4ZLHb/yUQ6DxuaQPKIk3FHEGuny1yGe3ADcgUa92jBLz9MilgXp2 50UWSUBfRyrAHHZWCUrdgQ+lg/nQ8+1com+AAz0ATl/fX3Pb6N9re+GcEinYfiF8rs49 GrbCN7/4QE3+4ZzU37nZ2OTCUQ9XIAiM/jYv9Nijnap2h7f36af/tNCeI/CqGFkHu3Oh XOgw== 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=8hgnBHOnzjH2/xDuAHlrA5hUrdf+D9mEcWE5ZKsBIGo=; b=pITrkn1LIHVUyVrOjviTzhJOMSYg44owAunTuj96fAU1dgWqh/fHphkDL2efbgwSBm 5fnQ1vB9Jr5ebV48Li/X7BbvUoNX86yS5WtmsQZOUpZOq+mTZ22YCLTFVCeuj+NbGMYQ izdLd5ORIWkGWNWatQkybk+89MpFXRpNCIOUX57JjGcjnmMJay8w/qGgfxMlyyUHKwRw 5vwwMoW6yIRkAuzwJmNcOqpwYX7Y2o+NS7cSV5YkX+ijc4sApoDVY4vinlJliIyJCf7m 458+bCCCMQ7Y1jkbqfUNVXXc8+/HJRTspdvpNgfgREbOsIpWgEk+FX+Iv4tKEinx1BSe mL/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="jvD/5B81"; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i124-20020a628782000000b00535dfe411cfsi2549559pfe.189.2022.09.30.09.40.03; Fri, 30 Sep 2022 09:40:15 -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=@intel.com header.s=Intel header.b="jvD/5B81"; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232091AbiI3QYq (ORCPT + 99 others); Fri, 30 Sep 2022 12:24:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232060AbiI3QYo (ORCPT ); Fri, 30 Sep 2022 12:24:44 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A5596465; Fri, 30 Sep 2022 09:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664555077; x=1696091077; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=aPat+vyuzHmTIY+ssdYQgbZFBJqiO2JzUm9LnYYjyXo=; b=jvD/5B819uZ/02X3LSBnOJjroRN9MZ+bovZOF9hsKmJE623RniRwTmvc WZfbIAuL5ypaDUhSY3MocTNqdrqc/dBaJyXUsNSdUch8/mayR04Edje3l Uda7ok8CsxW88tlsaHdTUMjwm+biPD7/H2XvoXRKBaFiuG6y0DIFi6wew RR4EjKP2vibfS0ruooS808VnkbYxwJNgt8gZMzE1C+K0lBjtKjQKMMdEP 9dct1SWO+RHQ1gh+awmbJllaMG4HQI7VH7Nx9AkjGATJevuTGzzObVOnp yEUlm7wEVpUuwmBn3dvOqc6catdDU9F01KlGlTNxokLOKCc8AoV3hEKAS g==; X-IronPort-AV: E=McAfee;i="6500,9779,10486"; a="364074345" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="364074345" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 09:23:14 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10486"; a="748280523" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="748280523" Received: from herrerop-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.38.128]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 09:23:04 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id DF624104BD6; Fri, 30 Sep 2022 19:23:01 +0300 (+03) Date: Fri, 30 Sep 2022 19:23:01 +0300 From: "Kirill A . Shutemov" To: Fuad Tabba Cc: Chao Peng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com, Muchun Song , wei.w.wang@intel.com Subject: Re: [PATCH v8 1/8] mm/memfd: Introduce userspace inaccessible memfd Message-ID: <20220930162301.i226o523teuikygq@box.shutemov.name> References: <20220915142913.2213336-1-chao.p.peng@linux.intel.com> <20220915142913.2213336-2-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 Fri, Sep 30, 2022 at 05:14:00PM +0100, Fuad Tabba wrote: > Hi, > > <...> > > > diff --git a/mm/memfd_inaccessible.c b/mm/memfd_inaccessible.c > > new file mode 100644 > > index 000000000000..2d33cbdd9282 > > --- /dev/null > > +++ b/mm/memfd_inaccessible.c > > @@ -0,0 +1,219 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +#include "linux/sbitmap.h" > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +struct inaccessible_data { > > + struct mutex lock; > > + struct file *memfd; > > + struct list_head notifiers; > > +}; > > + > > +static void inaccessible_notifier_invalidate(struct inaccessible_data *data, > > + pgoff_t start, pgoff_t end) > > +{ > > + struct inaccessible_notifier *notifier; > > + > > + mutex_lock(&data->lock); > > + list_for_each_entry(notifier, &data->notifiers, list) { > > + notifier->ops->invalidate(notifier, start, end); > > + } > > + mutex_unlock(&data->lock); > > +} > > + > > +static int inaccessible_release(struct inode *inode, struct file *file) > > +{ > > + struct inaccessible_data *data = inode->i_mapping->private_data; > > + > > + fput(data->memfd); > > + kfree(data); > > + return 0; > > +} > > + > > +static long inaccessible_fallocate(struct file *file, int mode, > > + loff_t offset, loff_t len) > > +{ > > + struct inaccessible_data *data = file->f_mapping->private_data; > > + struct file *memfd = data->memfd; > > + int ret; > > + > > + if (mode & FALLOC_FL_PUNCH_HOLE) { > > + if (!PAGE_ALIGNED(offset) || !PAGE_ALIGNED(len)) > > + return -EINVAL; > > + } > > + > > + ret = memfd->f_op->fallocate(memfd, mode, offset, len); > > I think that shmem_file_operations.fallocate is only set if > CONFIG_TMPFS is enabled (shmem.c). Should there be a check at > initialization that fallocate is set, or maybe a config dependency, or > can we count on it always being enabled? It is already there: config MEMFD_CREATE def_bool TMPFS || HUGETLBFS And we reject inaccessible memfd_create() for HUGETLBFS. But if we go with a separate syscall, yes, we need the dependency. > > + inaccessible_notifier_invalidate(data, offset, offset + len); > > + return ret; > > +} > > + > > <...> > > > +void inaccessible_register_notifier(struct file *file, > > + struct inaccessible_notifier *notifier) > > +{ > > + struct inaccessible_data *data = file->f_mapping->private_data; > > + > > + mutex_lock(&data->lock); > > + list_add(¬ifier->list, &data->notifiers); > > + mutex_unlock(&data->lock); > > +} > > +EXPORT_SYMBOL_GPL(inaccessible_register_notifier); > > If the memfd wasn't marked as inaccessible, or more generally > speaking, if the file isn't a memfd_inaccessible file, this ends up > accessing an uninitialized pointer for the notifier list. Should there > be a check for that here, and have this function return an error if > that's not the case? I think it is "don't do that" category. inaccessible_register_notifier() caller has to know what file it operates on, no? -- Kiryl Shutsemau / Kirill A. Shutemov