Message ID | 20221202013404.163143-6-jeffxu@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp588608wrr; Thu, 1 Dec 2022 17:38:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf63dtKKVrpF7Sw4I4QUrCsi32yX+D+YJxRiuGmxazXRye5XhDmN9iEPaorNIpAhgc97FDas X-Received: by 2002:a62:1dcd:0:b0:576:4b38:c08e with SMTP id d196-20020a621dcd000000b005764b38c08emr2225070pfd.37.1669945089249; Thu, 01 Dec 2022 17:38:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669945089; cv=none; d=google.com; s=arc-20160816; b=nlG4LxpwjujWQgWWyVemJaE2ZqfAmguYgucdo/21AcPv4cGH8D3Ibh3xtic9T9vwys sG5P9mNPBzSICyP9J2iFnDc3YPhom33r0gZXW2msmjKW6eDPivVL3jSXjG6URaJ2iEfG PFpL5CEXdeBGFRVxp+SJ0lCLsfURrnSD/HHxWdYv8YJ4nBKXZ+sZmtDBRgaw9KS10mD3 AjwrYEbBkwr7m7vLGqlyK1pLA6Pj7rZMg0DxIIhkfFHA9krvDCjwlWLRKOQOAykD2E8F BpT2OXnmKnw/gEyaxWpSceu+PhhVtgH0SDdAQwPYw+UAdZCpxgHgfQs2mlQ6T+IrO8s5 X34Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U9zf1d7pWFvO5Dl06Tc/rERXX92s0ACmtz1UYSxOlaY=; b=F0yFk5aOpOtdqFrgBth23kwugsRmWSzJSDXVnft1D9/e/6Jv/d4ocHmcC5tty7zltb 44MmOikKFtNkDmOYE8EJN4WbVgsXtVnYy2YXwacGkwU8tGM6tNhb/EKQ75v5XFLmc/xh DVG55WOqdLDEmmYXBtGKlp+q5jCnYTNqXneZsc26Hv5M/WQ0pW3+3JqA5EaqTZuu0Ml1 dH28uIA/QONuoetIBgj1tWsSytdJbFvH2KH8y9rh9ccHaBJOSK524bJHWdCF3pMrCaFr BpU4bsbML8BoNGIUvOVga0u835K9AcQIrxI0IsdXbcn6mHkG3T1KBJug8T5LGZILY77Y d9xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FvIJKzfh; 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=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a056a00140e00b00571d3860297si6429525pfu.80.2022.12.01.17.37.56; Thu, 01 Dec 2022 17:38:09 -0800 (PST) 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=@chromium.org header.s=google header.b=FvIJKzfh; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231530AbiLBBgL (ORCPT <rfc822;heyuhang3455@gmail.com> + 99 others); Thu, 1 Dec 2022 20:36:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231701AbiLBBf5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 1 Dec 2022 20:35:57 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36044D3A11 for <linux-kernel@vger.kernel.org>; Thu, 1 Dec 2022 17:35:56 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id v3so3188117pgh.4 for <linux-kernel@vger.kernel.org>; Thu, 01 Dec 2022 17:35:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U9zf1d7pWFvO5Dl06Tc/rERXX92s0ACmtz1UYSxOlaY=; b=FvIJKzfhufXOfFCwbK279zKP3kDpFkktmuEZtRklod4CjdJZXWVx2GkmuMC+NBUBAu ehvM8eVp2de1X6BG99Db5X3LgBBChBic5sHpT5lnWZzI9pmMm7bb3cqs3DAYrbTF8bGT hhTDQq47TN5mYVRB0LBflW7mbrbzHg1eej8qI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U9zf1d7pWFvO5Dl06Tc/rERXX92s0ACmtz1UYSxOlaY=; b=H10PWTnMwOHb3hQjsEnINn3heNmxDI+9hKS5jpw/NV83bwLgh7ClxlG9ngF40HRymn 24d8bQD+odGQRc4ykvPC8PfyGnDHVpA7glXwcT+Pnj7unyozVFRZ8Ksywwb490i7BqVy HgslM4xZf1RAuSW8jB4d/JYe4yHU7OYUer3ma4tqBZWSwGEHStR+3pGt1WTa6m1obiUu 5aSzgkuKelDqjcOZybv4auxiurmiYFm+JnMqqCn0chXHeRH9UWpUjc3cd1/20PK879tc thPgZCQiYJEs0YOXTaUa79mUwJq7BTPd54SdH63uj7HMwuFgTcKGeNjuXP/hQRc9Uiu0 cXKA== X-Gm-Message-State: ANoB5pkqCFJ/8OoyuvuocKZLobjm5m98ilT+YqVNPPH4UV1mnWCAXCjg qdrhRM2BBcA2+hynsJjr8TuskA== X-Received: by 2002:a65:6a01:0:b0:477:693f:b8d3 with SMTP id m1-20020a656a01000000b00477693fb8d3mr43344990pgu.333.1669944955762; Thu, 01 Dec 2022 17:35:55 -0800 (PST) Received: from jeffxud.c.googlers.com.com (30.202.168.34.bc.googleusercontent.com. [34.168.202.30]) by smtp.gmail.com with ESMTPSA id s13-20020a65690d000000b00477fb27eaddsm3074241pgq.63.2022.12.01.17.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 17:35:55 -0800 (PST) From: jeffxu@chromium.org To: skhan@linuxfoundation.org, keescook@chromium.org Cc: akpm@linux-foundation.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@google.com, jeffxu@google.com, jorgelo@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mnissler@chromium.org, jannh@google.com, linux-hardening@vger.kernel.org, Jeff Xu <jeffxu@chromium.org> Subject: [PATCH v3] mm/memfd: security hook for memfd_create Date: Fri, 2 Dec 2022 01:34:03 +0000 Message-Id: <20221202013404.163143-6-jeffxu@google.com> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog In-Reply-To: <20221202013404.163143-1-jeffxu@google.com> References: <20221202013404.163143-1-jeffxu@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751064342084638333?= X-GMAIL-MSGID: =?utf-8?q?1751064342084638333?= |
Series |
[v3] mm/memfd: security hook for memfd_create
|
|
Commit Message
Jeff Xu
Dec. 2, 2022, 1:34 a.m. UTC
From: Jeff Xu <jeffxu@chromium.org> The new security_memfd_create allows lsm to check flags of memfd_create. The security by default system (such as chromeos) can use this to implement system wide lsm to allow only non-executable memfd being created. Signed-off-by: Jeff Xu <jeffxu@chromium.org> --- include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 4 ++++ include/linux/security.h | 6 ++++++ mm/memfd.c | 5 +++++ 4 files changed, 16 insertions(+)
Comments
Hi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/jeffxu-chromium-org/mm-memfd-security-hook-for-memfd_create/20221202-094044
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20221202013404.163143-6-jeffxu%40google.com
patch subject: [PATCH v3] mm/memfd: security hook for memfd_create
config: x86_64-defconfig
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/63daa2490ad1a865f02ff504c8c3fcd6fd72c0c3
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review jeffxu-chromium-org/mm-memfd-security-hook-for-memfd_create/20221202-094044
git checkout 63daa2490ad1a865f02ff504c8c3fcd6fd72c0c3
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
ld: mm/memfd.o: in function `__do_sys_memfd_create':
>> memfd.c:(.text+0xe4): undefined reference to `security_memfd_create'
Hi, Thank you for the patch! Yet something to improve: [auto build test ERROR on akpm-mm/mm-everything] url: https://github.com/intel-lab-lkp/linux/commits/jeffxu-chromium-org/mm-memfd-security-hook-for-memfd_create/20221202-094044 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20221202013404.163143-6-jeffxu%40google.com patch subject: [PATCH v3] mm/memfd: security hook for memfd_create config: i386-randconfig-a001 compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/63daa2490ad1a865f02ff504c8c3fcd6fd72c0c3 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review jeffxu-chromium-org/mm-memfd-security-hook-for-memfd_create/20221202-094044 git checkout 63daa2490ad1a865f02ff504c8c3fcd6fd72c0c3 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): ld: mm/memfd.o: in function `__do_sys_memfd_create': >> mm/memfd.c:316: undefined reference to `security_memfd_create' vim +316 mm/memfd.c 265 266 SYSCALL_DEFINE2(memfd_create, 267 const char __user *, uname, 268 unsigned int, flags) 269 { 270 unsigned int *file_seals; 271 struct file *file; 272 int fd, error; 273 char *name; 274 long len; 275 276 if (!(flags & MFD_HUGETLB)) { 277 if (flags & ~(unsigned int)MFD_ALL_FLAGS) 278 return -EINVAL; 279 } else { 280 /* Allow huge page size encoding in flags. */ 281 if (flags & ~(unsigned int)(MFD_ALL_FLAGS | 282 (MFD_HUGE_MASK << MFD_HUGE_SHIFT))) 283 return -EINVAL; 284 } 285 286 /* length includes terminating zero */ 287 len = strnlen_user(uname, MFD_NAME_MAX_LEN + 1); 288 if (len <= 0) 289 return -EFAULT; 290 if (len > MFD_NAME_MAX_LEN + 1) 291 return -EINVAL; 292 293 name = kmalloc(len + MFD_NAME_PREFIX_LEN, GFP_KERNEL); 294 if (!name) 295 return -ENOMEM; 296 297 strcpy(name, MFD_NAME_PREFIX); 298 if (copy_from_user(&name[MFD_NAME_PREFIX_LEN], uname, len)) { 299 error = -EFAULT; 300 goto err_name; 301 } 302 303 /* terminating-zero may have changed after strnlen_user() returned */ 304 if (name[len + MFD_NAME_PREFIX_LEN - 1]) { 305 error = -EFAULT; 306 goto err_name; 307 } 308 309 fd = get_unused_fd_flags((flags & MFD_CLOEXEC) ? O_CLOEXEC : 0); 310 if (fd < 0) { 311 error = fd; 312 goto err_name; 313 } 314 315 /* security hook for memfd_create */ > 316 error = security_memfd_create(name, flags);
On Fri, Dec 02, 2022 at 01:34:03AM +0000, jeffxu@chromium.org wrote: > From: Jeff Xu <jeffxu@chromium.org> > > The new security_memfd_create allows lsm to check flags of > memfd_create. > > The security by default system (such as chromeos) can use this > to implement system wide lsm to allow only non-executable memfd > being created. > > Signed-off-by: Jeff Xu <jeffxu@chromium.org> > --- > include/linux/lsm_hook_defs.h | 1 + > include/linux/lsm_hooks.h | 4 ++++ > include/linux/security.h | 6 ++++++ > mm/memfd.c | 5 +++++ > 4 files changed, 16 insertions(+) > > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > index ec119da1d89b..fd40840927c8 100644 > --- a/include/linux/lsm_hook_defs.h > +++ b/include/linux/lsm_hook_defs.h > @@ -164,6 +164,7 @@ LSM_HOOK(int, 0, file_alloc_security, struct file *file) > LSM_HOOK(void, LSM_RET_VOID, file_free_security, struct file *file) > LSM_HOOK(int, 0, file_ioctl, struct file *file, unsigned int cmd, > unsigned long arg) > +LSM_HOOK(int, 0, memfd_create, char *name, unsigned int flags) > LSM_HOOK(int, 0, mmap_addr, unsigned long addr) > LSM_HOOK(int, 0, mmap_file, struct file *file, unsigned long reqprot, > unsigned long prot, unsigned long flags) > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > index 4ec80b96c22e..5a18a6552278 100644 > --- a/include/linux/lsm_hooks.h > +++ b/include/linux/lsm_hooks.h > @@ -543,6 +543,10 @@ > * simple integer value. When @arg represents a user space pointer, it > * should never be used by the security module. > * Return 0 if permission is granted. > + * @memfd_create: > + * @name is the name of memfd file. > + * @flags is the flags used in memfd_create. > + * Return 0 if permission is granted. > * @mmap_addr : > * Check permissions for a mmap operation at @addr. > * @addr contains virtual address that will be used for the operation. > diff --git a/include/linux/security.h b/include/linux/security.h > index ca1b7109c0db..5b87a780822a 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -384,6 +384,7 @@ int security_file_permission(struct file *file, int mask); > int security_file_alloc(struct file *file); > void security_file_free(struct file *file); > int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); > +int security_memfd_create(char *name, unsigned int flags); > int security_mmap_file(struct file *file, unsigned long prot, > unsigned long flags); > int security_mmap_addr(unsigned long addr); > @@ -963,6 +964,11 @@ static inline int security_file_ioctl(struct file *file, unsigned int cmd, > return 0; > } > > +static inline int security_memfd_create(char *name, unsigned int flags) > +{ > + return 0; > +} I think this is missing the security/security.c changes for the non-inline version? -Kees > + > static inline int security_mmap_file(struct file *file, unsigned long prot, > unsigned long flags) > { > diff --git a/mm/memfd.c b/mm/memfd.c > index 69e897dea6d5..96dcfbfed09e 100644 > --- a/mm/memfd.c > +++ b/mm/memfd.c > @@ -346,6 +346,11 @@ SYSCALL_DEFINE2(memfd_create, > goto err_name; > } > > + /* security hook for memfd_create */ > + error = security_memfd_create(name, flags); > + if (error) > + return error; > + > if (flags & MFD_HUGETLB) { > file = hugetlb_file_setup(name, 0, VM_NORESERVE, > HUGETLB_ANONHUGE_INODE, > -- > 2.39.0.rc0.267.gcb52ba06e7-goog >
On Fri, Dec 2, 2022 at 2:58 PM Kees Cook <keescook@chromium.org> wrote: > > On Fri, Dec 02, 2022 at 01:34:03AM +0000, jeffxu@chromium.org wrote: > > From: Jeff Xu <jeffxu@chromium.org> > > > > The new security_memfd_create allows lsm to check flags of > > memfd_create. > > > > The security by default system (such as chromeos) can use this > > to implement system wide lsm to allow only non-executable memfd > > being created. > > > > Signed-off-by: Jeff Xu <jeffxu@chromium.org> > > --- > > include/linux/lsm_hook_defs.h | 1 + > > include/linux/lsm_hooks.h | 4 ++++ > > include/linux/security.h | 6 ++++++ > > mm/memfd.c | 5 +++++ > > 4 files changed, 16 insertions(+) > > > > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > > index ec119da1d89b..fd40840927c8 100644 > > --- a/include/linux/lsm_hook_defs.h > > +++ b/include/linux/lsm_hook_defs.h > > @@ -164,6 +164,7 @@ LSM_HOOK(int, 0, file_alloc_security, struct file *file) > > LSM_HOOK(void, LSM_RET_VOID, file_free_security, struct file *file) > > LSM_HOOK(int, 0, file_ioctl, struct file *file, unsigned int cmd, > > unsigned long arg) > > +LSM_HOOK(int, 0, memfd_create, char *name, unsigned int flags) > > LSM_HOOK(int, 0, mmap_addr, unsigned long addr) > > LSM_HOOK(int, 0, mmap_file, struct file *file, unsigned long reqprot, > > unsigned long prot, unsigned long flags) > > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > > index 4ec80b96c22e..5a18a6552278 100644 > > --- a/include/linux/lsm_hooks.h > > +++ b/include/linux/lsm_hooks.h > > @@ -543,6 +543,10 @@ > > * simple integer value. When @arg represents a user space pointer, it > > * should never be used by the security module. > > * Return 0 if permission is granted. > > + * @memfd_create: > > + * @name is the name of memfd file. > > + * @flags is the flags used in memfd_create. > > + * Return 0 if permission is granted. > > * @mmap_addr : > > * Check permissions for a mmap operation at @addr. > > * @addr contains virtual address that will be used for the operation. > > diff --git a/include/linux/security.h b/include/linux/security.h > > index ca1b7109c0db..5b87a780822a 100644 > > --- a/include/linux/security.h > > +++ b/include/linux/security.h > > @@ -384,6 +384,7 @@ int security_file_permission(struct file *file, int mask); > > int security_file_alloc(struct file *file); > > void security_file_free(struct file *file); > > int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); > > +int security_memfd_create(char *name, unsigned int flags); > > int security_mmap_file(struct file *file, unsigned long prot, > > unsigned long flags); > > int security_mmap_addr(unsigned long addr); > > @@ -963,6 +964,11 @@ static inline int security_file_ioctl(struct file *file, unsigned int cmd, > > return 0; > > } > > > > +static inline int security_memfd_create(char *name, unsigned int flags) > > +{ > > + return 0; > > +} > > I think this is missing the security/security.c changes for the > non-inline version? > Yes. I will add that in V4. > -Kees > > > + > > static inline int security_mmap_file(struct file *file, unsigned long prot, > > unsigned long flags) > > { > > diff --git a/mm/memfd.c b/mm/memfd.c > > index 69e897dea6d5..96dcfbfed09e 100644 > > --- a/mm/memfd.c > > +++ b/mm/memfd.c > > @@ -346,6 +346,11 @@ SYSCALL_DEFINE2(memfd_create, > > goto err_name; > > } > > > > + /* security hook for memfd_create */ > > + error = security_memfd_create(name, flags); > > + if (error) > > + return error; > > + > > if (flags & MFD_HUGETLB) { > > file = hugetlb_file_setup(name, 0, VM_NORESERVE, > > HUGETLB_ANONHUGE_INODE, > > -- > > 2.39.0.rc0.267.gcb52ba06e7-goog > > > > -- > Kees Cook
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index ec119da1d89b..fd40840927c8 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -164,6 +164,7 @@ LSM_HOOK(int, 0, file_alloc_security, struct file *file) LSM_HOOK(void, LSM_RET_VOID, file_free_security, struct file *file) LSM_HOOK(int, 0, file_ioctl, struct file *file, unsigned int cmd, unsigned long arg) +LSM_HOOK(int, 0, memfd_create, char *name, unsigned int flags) LSM_HOOK(int, 0, mmap_addr, unsigned long addr) LSM_HOOK(int, 0, mmap_file, struct file *file, unsigned long reqprot, unsigned long prot, unsigned long flags) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 4ec80b96c22e..5a18a6552278 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -543,6 +543,10 @@ * simple integer value. When @arg represents a user space pointer, it * should never be used by the security module. * Return 0 if permission is granted. + * @memfd_create: + * @name is the name of memfd file. + * @flags is the flags used in memfd_create. + * Return 0 if permission is granted. * @mmap_addr : * Check permissions for a mmap operation at @addr. * @addr contains virtual address that will be used for the operation. diff --git a/include/linux/security.h b/include/linux/security.h index ca1b7109c0db..5b87a780822a 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -384,6 +384,7 @@ int security_file_permission(struct file *file, int mask); int security_file_alloc(struct file *file); void security_file_free(struct file *file); int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); +int security_memfd_create(char *name, unsigned int flags); int security_mmap_file(struct file *file, unsigned long prot, unsigned long flags); int security_mmap_addr(unsigned long addr); @@ -963,6 +964,11 @@ static inline int security_file_ioctl(struct file *file, unsigned int cmd, return 0; } +static inline int security_memfd_create(char *name, unsigned int flags) +{ + return 0; +} + static inline int security_mmap_file(struct file *file, unsigned long prot, unsigned long flags) { diff --git a/mm/memfd.c b/mm/memfd.c index 69e897dea6d5..96dcfbfed09e 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -346,6 +346,11 @@ SYSCALL_DEFINE2(memfd_create, goto err_name; } + /* security hook for memfd_create */ + error = security_memfd_create(name, flags); + if (error) + return error; + if (flags & MFD_HUGETLB) { file = hugetlb_file_setup(name, 0, VM_NORESERVE, HUGETLB_ANONHUGE_INODE,