cregit-Linux how code gets into the kernel

Release 4.11 ipc/shm.c

Directory: ipc
/*
 * linux/ipc/shm.c
 * Copyright (C) 1992, 1993 Krishna Balasubramanian
 *       Many improvements/fixes by Bruno Haible.
 * Replaced `struct shm_desc' by `struct vm_area_struct', July 1994.
 * Fixed the shm swap deallocation (shm_unuse()), August 1998 Andrea Arcangeli.
 *
 * /proc/sysvipc/shm support (c) 1999 Dragos Acostachioaie <dragos@iname.com>
 * BIGMEM support, Andrea Arcangeli <andrea@suse.de>
 * SMP thread shm, Jean-Luc Boyard <jean-luc.boyard@siemens.fr>
 * HIGHMEM support, Ingo Molnar <mingo@redhat.com>
 * Make shmmax, shmall, shmmni sysctl'able, Christoph Rohland <cr@sap.com>
 * Shared /dev/zero support, Kanoj Sarcar <kanoj@sgi.com>
 * Move the mm functionality over to mm/shmem.c, Christoph Rohland <cr@sap.com>
 *
 * support for audit of ipc object properties and permission changes
 * Dustin Kirkland <dustin.kirkland@us.ibm.com>
 *
 * namespaces support
 * OpenVZ, SWsoft Inc.
 * Pavel Emelianov <xemul@openvz.org>
 *
 * Better ipc lock (kern_ipc_perm.lock) handling
 * Davidlohr Bueso <davidlohr.bueso@hp.com>, June 2013.
 */

#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/hugetlb.h>
#include <linux/shm.h>
#include <linux/init.h>
#include <linux/file.h>
#include <linux/mman.h>
#include <linux/shmem_fs.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/audit.h>
#include <linux/capability.h>
#include <linux/ptrace.h>
#include <linux/seq_file.h>
#include <linux/rwsem.h>
#include <linux/nsproxy.h>
#include <linux/mount.h>
#include <linux/ipc_namespace.h>

#include <linux/uaccess.h>

#include "util.h"


struct shm_file_data {
	
int id;
	
struct ipc_namespace *ns;
	
struct file *file;
	
const struct vm_operations_struct *vm_ops;
};


#define shm_file_data(file) (*((struct shm_file_data **)&(file)->private_data))


static const struct file_operations shm_file_operations;

static const struct vm_operations_struct shm_vm_ops;


#define shm_ids(ns)	((ns)->ids[IPC_SHM_IDS])


#define shm_unlock(shp)			\
	ipc_unlock(&(shp)->shm_perm)

static int newseg(struct ipc_namespace *, struct ipc_params *);
static void shm_open(struct vm_area_struct *vma);
static void shm_close(struct vm_area_struct *vma);
static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
#ifdef CONFIG_PROC_FS
static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
#endif


void shm_init_ns(struct ipc_namespace *ns) { ns->shm_ctlmax = SHMMAX; ns->shm_ctlall = SHMALL; ns->shm_ctlmni = SHMMNI; ns->shm_rmid_forced = 0; ns->shm_tot = 0; ipc_init_ids(&shm_ids(ns)); }

Contributors

PersonTokensPropCommitsCommitProp
Kirill Korotaev3163.27%120.00%
Linus Torvalds (pre-git)612.24%120.00%
Vasiliy Kulikov612.24%120.00%
WANG Cong36.12%120.00%
Pierre Peiffer36.12%120.00%
Total49100.00%5100.00%

/* * Called with shm_ids.rwsem (writer) and the shp structure locked. * Only shm_ids.rwsem remains locked on exit. */
static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) { struct shmid_kernel *shp; shp = container_of(ipcp, struct shmid_kernel, shm_perm); if (shp->shm_nattch) { shp->shm_perm.mode |= SHM_DEST; /* Do not find it any more */ shp->shm_perm.key = IPC_PRIVATE; shm_unlock(shp); } else shm_destroy(ns, shp); }

Contributors

PersonTokensPropCommitsCommitProp
Kirill Korotaev5171.83%133.33%
Pierre Peiffer1926.76%133.33%
Linus Torvalds (pre-git)11.41%133.33%
Total71100.00%3100.00%

#ifdef CONFIG_IPC_NS
void shm_exit_ns(struct ipc_namespace *ns) { free_ipcs(ns, &shm_ids(ns), do_shm_rmid); idr_destroy(&ns->ids[IPC_SHM_IDS].ipcs_idr); }

Contributors

PersonTokensPropCommitsCommitProp
Kirill Korotaev1747.22%120.00%
Serge E. Hallyn1336.11%120.00%
Pierre Peiffer38.33%240.00%
Nadia Derbey38.33%120.00%
Total36100.00%5100.00%

#endif
static int __init ipc_ns_init(void) { shm_init_ns(&init_ipc_ns); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)950.00%350.00%
Linus Torvalds738.89%116.67%
Pierre Peiffer15.56%116.67%
Kirill Korotaev15.56%116.67%
Total18100.00%6100.00%

pure_initcall(ipc_ns_init);
void __init shm_init(void) { ipc_init_proc_interface("sysvipc/shm", #if BITS_PER_LONG <= 32 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n", #else " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n", #endif IPC_SHM_IDS, sysvipc_shm_proc_show); }

Contributors

PersonTokensPropCommitsCommitProp
Helge Deller1240.00%112.50%
Linus Torvalds (pre-git)826.67%450.00%
Linus Torvalds723.33%112.50%
Mike Waychison26.67%112.50%
Kirill Korotaev13.33%112.50%
Total30100.00%8100.00%


static inline struct shmid_kernel *shm_obtain_object(struct ipc_namespace *ns, int id) { struct kern_ipc_perm *ipcp = ipc_obtain_object_idr(&shm_ids(ns), id); if (IS_ERR(ipcp)) return ERR_CAST(ipcp); return container_of(ipcp, struct shmid_kernel, shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Davidlohr Bueso A57100.00%2100.00%
Total57100.00%2100.00%


static inline struct shmid_kernel *shm_obtain_object_check(struct ipc_namespace *ns, int id) { struct kern_ipc_perm *ipcp = ipc_obtain_object_check(&shm_ids(ns), id); if (IS_ERR(ipcp)) return ERR_CAST(ipcp); return container_of(ipcp, struct shmid_kernel, shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Davidlohr Bueso A57100.00%1100.00%
Total57100.00%1100.00%

/* * shm_lock_(check_) routines are called in the paths where the rwsem * is not necessarily held. */
static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) { struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id); /* * Callers of shm_lock() must validate the status of the returned ipc * object pointer (as returned by ipc_lock()), and error out as * appropriate. */ if (IS_ERR(ipcp)) return (void *)ipcp; return container_of(ipcp, struct shmid_kernel, shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Nadia Derbey3661.02%233.33%
Kirill A. Shutemov1118.64%116.67%
Linus Torvalds (pre-git)46.78%116.67%
Pierre Peiffer46.78%116.67%
Kirill Korotaev46.78%116.67%
Total59100.00%6100.00%


static inline void shm_lock_by_ptr(struct shmid_kernel *ipcp) { rcu_read_lock(); ipc_lock_object(&ipcp->shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Vasiliy Kulikov2295.65%150.00%
Davidlohr Bueso A14.35%150.00%
Total23100.00%2100.00%


static void shm_rcu_free(struct rcu_head *head) { struct ipc_rcu *p = container_of(head, struct ipc_rcu, rcu); struct shmid_kernel *shp = ipc_rcu_to_struct(p); security_shm_free(shp); ipc_rcu_free(head); }

Contributors

PersonTokensPropCommitsCommitProp
Davidlohr Bueso A46100.00%1100.00%
Total46100.00%1100.00%


static inline void shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *s) { list_del(&s->shm_clist); ipc_rmid(&shm_ids(ns), &s->shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)1333.33%240.00%
Nadia Derbey1025.64%120.00%
Kirill Korotaev820.51%120.00%
Jack Miller820.51%120.00%
Total39100.00%5100.00%


static int __shm_open(struct vm_area_struct *vma) { struct file *file = vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); struct shmid_kernel *shp; shp = shm_lock(sfd->ns, sfd->id); if (IS_ERR(shp)) return PTR_ERR(shp); shp->shm_atim = get_seconds(); shp->shm_lprid = task_tgid_vnr(current); shp->shm_nattch++; shm_unlock(shp); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3538.89%646.15%
Eric W. Biedermann2527.78%17.69%
Kirill A. Shutemov1921.11%17.69%
Kirill Korotaev44.44%17.69%
Pavel Emelyanov33.33%17.69%
Andi Kleen22.22%17.69%
Andrew Morton11.11%17.69%
Eric Sesterhenn / Snakebyte11.11%17.69%
Total90100.00%13100.00%

/* This is called by fork, once for every shm attach. */
static void shm_open(struct vm_area_struct *vma) { int err = __shm_open(vma); /* * We raced in the idr lookup or with shm_destroy(). * Either way, the ID is busted. */ WARN_ON_ONCE(err); }

Contributors

PersonTokensPropCommitsCommitProp
Kirill A. Shutemov2496.00%150.00%
Linus Torvalds (pre-git)14.00%150.00%
Total25100.00%2100.00%

/* * shm_destroy - free the struct shmid_kernel * * @ns: namespace * @shp: struct to free * * It has to be called with shp and shm_ids.rwsem (writer) locked, * but returns with shp unlocked and freed. */
static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) { struct file *shm_file; shm_file = shp->shm_file; shp->shm_file = NULL; ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT; shm_rmid(ns, shp); shm_unlock(shp); if (!is_file_hugepages(shm_file)) shmem_lock(shm_file, 0, shp->mlock_user); else if (shp->mlock_user) user_shm_unlock(i_size_read(file_inode(shm_file)), shp->mlock_user); fput(shm_file); ipc_rcu_putref(shp, shm_rcu_free); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3934.21%531.25%
Greg Thelen1714.91%16.25%
Rik Van Riel1311.40%16.25%
Hugh Dickins1210.53%212.50%
Kirill Korotaev97.89%16.25%
Andrew Morton87.02%16.25%
Linus Torvalds76.14%16.25%
Al Viro32.63%16.25%
Dave Hansen32.63%16.25%
Davidlohr Bueso A21.75%16.25%
Manfred Spraul10.88%16.25%
Total114100.00%16100.00%

/* * shm_may_destroy - identifies whether shm segment should be destroyed now * * Returns true if and only if there are no active users of the segment and * one of the following is true: * * 1) shmctl(id, IPC_RMID, NULL) was called for this shp * * 2) sysctl kernel.shm_rmid_forced is set to 1. */
static bool shm_may_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) { return (shp->shm_nattch == 0) && (ns->shm_rmid_forced || (shp->shm_perm.mode & SHM_DEST)); }

Contributors

PersonTokensPropCommitsCommitProp
Vasiliy Kulikov41100.00%1100.00%
Total41100.00%1100.00%

/* * remove the attach descriptor vma. * free memory for segment if it is marked destroyed. * The descriptor has already been removed from the current->mm->mmap list * and will later be kfree()d. */
static void shm_close(struct vm_area_struct *vma) { struct file *file = vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); struct shmid_kernel *shp; struct ipc_namespace *ns = sfd->ns; down_write(&shm_ids(ns).rwsem); /* remove from the list of attaches of the shm segment */ shp = shm_lock(ns, sfd->id); /* * We raced in the idr lookup or with shm_destroy(). * Either way, the ID is busted. */ if (WARN_ON_ONCE(IS_ERR(shp))) goto done; /* no-op */ shp->shm_lprid = task_tgid_vnr(current); shp->shm_dtim = get_seconds(); shp->shm_nattch--; if (shm_may_destroy(ns, shp)) shm_destroy(ns, shp); else shm_unlock(shp); done: up_write(&shm_ids(ns).rwsem); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5539.86%533.33%
Vasiliy Kulikov3122.46%16.67%
Kirill A. Shutemov1712.32%16.67%
Eric W. Biedermann1510.87%16.67%
Kirill Korotaev107.25%16.67%
Pavel Emelyanov32.17%16.67%
Nadia Derbey21.45%213.33%
Andi Kleen21.45%16.67%
Davidlohr Bueso A21.45%16.67%
Eric Sesterhenn / Snakebyte10.72%16.67%
Total138100.00%15100.00%

/* Called with ns->shm_ids(ns).rwsem locked */
static int shm_try_destroy_orphaned(int id, void *p, void *data) { struct ipc_namespace *ns = data; struct kern_ipc_perm *ipcp = p; struct shmid_kernel *shp = container_of(ipcp, struct shmid_kernel, shm_perm); /* * We want to destroy segments without users and with already * exit'ed originating process. * * As shp->* are changed under rwsem, it's safe to skip shp locking. */ if (shp->shm_creator != NULL) return 0; if (shm_may_destroy(ns, shp)) { shm_lock_by_ptr(shp); shm_destroy(ns, shp); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vasiliy Kulikov7488.10%333.33%
Linus Torvalds (pre-git)89.52%444.44%
Andrew Morton11.19%111.11%
Davidlohr Bueso A11.19%111.11%
Total84100.00%9100.00%


void shm_destroy_orphaned(struct ipc_namespace *ns) { down_write(&shm_ids(ns).rwsem); if (shm_ids(ns).in_use) idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_orphaned, ns); up_write(&shm_ids(ns).rwsem); }

Contributors

PersonTokensPropCommitsCommitProp
Vasiliy Kulikov5596.49%266.67%
Davidlohr Bueso A23.51%133.33%
Total57100.00%3100.00%

/* Locking assumes this will only be called with task == current */
void exit_shm(struct task_struct *task) { struct ipc_namespace *ns = task->nsproxy->ipc_ns; struct shmid_kernel *shp, *n; if (list_empty(&task->sysvshm.shm_clist)) return; /* * If kernel.shm_rmid_forced is not set then only keep track of * which shmids are orphaned, so that a later set of the sysctl * can clean them up. */ if (!ns->shm_rmid_forced) { down_read(&shm_ids(ns).rwsem); list_for_each_entry(shp, &task->sysvshm.shm_clist, shm_clist) shp->shm_creator = NULL; /* * Only under read lock but we are only called on current * so no entry on the list will be shared. */ list_del(&task->sysvshm.shm_clist); up_read(&shm_ids(ns).rwsem); return; } /* * Destroy all already created segments, that were not yet mapped, * and mark any mapped as orphan to cover the sysctl toggling. * Destroy is skipped if shm_may_destroy() returns false. */ down_write(&shm_ids(ns).rwsem); list_for_each_entry_safe(shp, n, &task->sysvshm.shm_clist, shm_clist) { shp->shm_creator = NULL; if (shm_may_destroy(ns, shp)) { shm_lock_by_ptr(shp); shm_destroy(ns, shp); } } /* Remove the list head from any segments still attached. */ list_del(&task->sysvshm.shm_clist); up_write(&shm_ids(ns).rwsem); }

Contributors

PersonTokensPropCommitsCommitProp
Jack Miller11766.86%220.00%
Vasiliy Kulikov4525.71%330.00%
Linus Torvalds (pre-git)74.00%220.00%
Kirill Korotaev31.71%110.00%
Davidlohr Bueso A21.14%110.00%
Nadia Derbey10.57%110.00%
Total175100.00%10100.00%


static int shm_fault(struct vm_fault *vmf) { struct file *file = vmf->vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); return sfd->vm_ops->fault(vmf); }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann1945.24%18.33%
Linus Torvalds (pre-git)1126.19%433.33%
Nicholas Piggin614.29%216.67%
Dave Jiang24.76%18.33%
Kirill Korotaev12.38%18.33%
Adrian Bunk12.38%18.33%
Hugh Dickins12.38%18.33%
David Howells12.38%18.33%
Total42100.00%12100.00%

#ifdef CONFIG_NUMA
static int shm_set_policy(struct vm_area_struct *vma, struct mempolicy *new) { struct file *file = vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); int err = 0; if (sfd->vm_ops->set_policy) err = sfd->vm_ops->set_policy(vma, new); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann4875.00%133.33%
Kirill Korotaev1523.44%133.33%
Adrian Bunk11.56%133.33%
Total64100.00%3100.00%


static struct mempolicy *shm_get_policy(struct vm_area_struct *vma, unsigned long addr) { struct file *file = vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); struct mempolicy *pol = NULL; if (sfd->vm_ops->get_policy) pol = sfd->vm_ops->get_policy(vma, addr); else if (vma->vm_policy) pol = vma->vm_policy; return pol; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann7290.00%133.33%
Adam Litke78.75%133.33%
Adrian Bunk11.25%133.33%
Total80100.00%3100.00%

#endif
static int shm_mmap(struct file *file, struct vm_area_struct *vma) { struct shm_file_data *sfd = shm_file_data(file); int ret; /* * In case of remap_file_pages() emulation, the file can represent * removed IPC ID: propogate shm_lock() error to caller. */ ret = __shm_open(vma); if (ret) return ret; ret = call_mmap(sfd->file, vma); if (ret) { shm_close(vma); return ret; } sfd->vm_ops = vma->vm_ops; #ifdef CONFIG_MMU WARN_ON(!sfd->vm_ops->fault); #endif vma->vm_ops = &shm_vm_ops; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann6361.76%116.67%
Kirill A. Shutemov2322.55%116.67%
Nicholas Piggin98.82%116.67%
David Howells54.90%116.67%
Davidlohr Bueso A10.98%116.67%
Miklos Szeredi10.98%116.67%
Total102100.00%6100.00%


static int shm_release(struct inode *ino, struct file *file) { struct shm_file_data *sfd = shm_file_data(file); put_ipc_ns(sfd->ns); shm_file_data(file) = NULL; kfree(sfd); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann4593.75%150.00%
Kirill Korotaev36.25%150.00%
Total48100.00%2100.00%


static int shm_fsync(struct file *file, loff_t start, loff_t end, int datasync) { struct shm_file_data *sfd = shm_file_data(file); if (!sfd->file->f_op->fsync) return -EINVAL; return call_fsync(sfd->file, start, end, datasync); }

Contributors

PersonTokensPropCommitsCommitProp
Adam Litke3966.10%125.00%
Josef Bacik1016.95%125.00%
Christoph Hellwig915.25%125.00%
Miklos Szeredi11.69%125.00%
Total59100.00%4100.00%


static long shm_fallocate(struct file *file, int mode, loff_t offset, loff_t len) { struct shm_file_data *sfd = shm_file_data(file); if (!sfd->file->f_op->fallocate) return -EOPNOTSUPP; return sfd->file->f_op->fallocate(file, mode, offset, len); }

Contributors

PersonTokensPropCommitsCommitProp
Will Deacon63100.00%1100.00%
Total63100.00%1100.00%


static unsigned long shm_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct shm_file_data *sfd = shm_file_data(file); return sfd->file->f_op->get_unmapped_area(sfd->file, addr, len, pgoff, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann5490.00%150.00%
Al Viro610.00%150.00%
Total60100.00%2100.00%

static const struct file_operations shm_file_operations = { .mmap = shm_mmap, .fsync = shm_fsync, .release = shm_release, .get_unmapped_area = shm_get_unmapped_area, .llseek = noop_llseek, .fallocate = shm_fallocate, }; /* * shm_file_operations_huge is now identical to shm_file_operations, * but we keep it distinct for the sake of is_file_shm_hugepages(). */ static const struct file_operations shm_file_operations_huge = { .mmap = shm_mmap, .fsync = shm_fsync, .release = shm_release, .get_unmapped_area = shm_get_unmapped_area, .llseek = noop_llseek, .fallocate = shm_fallocate, };
bool is_file_shm_hugepages(struct file *file) { return file->f_op == &shm_file_operations_huge; }

Contributors

PersonTokensPropCommitsCommitProp
Al Viro1794.44%150.00%
Yaowei Bai15.56%150.00%
Total18100.00%2100.00%

static const struct vm_operations_struct shm_vm_ops = { .open = shm_open, /* callback for a new vm-area open */ .close = shm_close, /* callback for when the vm-area is released */ .fault = shm_fault, #if defined(CONFIG_NUMA) .set_policy = shm_set_policy, .get_policy = shm_get_policy, #endif }; /** * newseg - Create a new shared memory segment * @ns: namespace * @params: ptr to the structure that contains key, size and shmflg * * Called with shm_ids.rwsem held as a writer. */
static int newseg(struct ipc_namespace *ns, struct ipc_params *params) { key_t key = params->key; int shmflg = params->flg; size_t size = params->u.size; int error; struct shmid_kernel *shp; size_t numpages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; struct file *file; char name[13]; int id; vm_flags_t acctflag = 0; if (size < SHMMIN || size > ns->shm_ctlmax) return -EINVAL; if (numpages << PAGE_SHIFT < size) return -ENOSPC; if (ns->shm_tot + numpages < ns->shm_tot || ns->shm_tot + numpages > ns->shm_ctlall) return -ENOSPC; shp = ipc_rcu_alloc(sizeof(*shp)); if (!shp) return -ENOMEM; shp->shm_perm.key = key; shp->shm_perm.mode = (shmflg & S_IRWXUGO); shp->mlock_user = NULL; shp->shm_perm.security = NULL; error = security_shm_alloc(shp); if (error) { ipc_rcu_putref(shp, ipc_rcu_free); return error; } sprintf(name, "SYSV%08x", key); if (shmflg & SHM_HUGETLB) { struct hstate *hs; size_t hugesize; hs = hstate_sizelog((shmflg >> SHM_HUGE_SHIFT) & SHM_HUGE_MASK); if (!hs) { error = -EINVAL; goto no_file; } hugesize = ALIGN(size, huge_page_size(hs)); /* hugetlb_file_setup applies strict accounting */ if (shmflg & SHM_NORESERVE) acctflag = VM_NORESERVE; file = hugetlb_file_setup(name, hugesize, acctflag, &shp->mlock_user, HUGETLB_SHMFS_INODE, (shmflg >> SHM_HUGE_SHIFT) & SHM_HUGE_MASK); } else { /* * Do not allow no accounting for OVERCOMMIT_NEVER, even * if it's asked for. */ if ((shmflg & SHM_NORESERVE) && sysctl_overcommit_memory != OVERCOMMIT_NEVER) acctflag = VM_NORESERVE; file = shmem_kernel_file_setup(name, size, acctflag); } error = PTR_ERR(file); if (IS_ERR(file)) goto no_file; shp->shm_cprid = task_tgid_vnr(current); shp->shm_lprid = 0; shp->shm_atim = shp->shm_dtim = 0; shp->shm_ctim = get_seconds(); shp->shm_segsz = size; shp->shm_nattch = 0; shp->shm_file = file; shp->shm_creator = current; id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); if (id < 0) { error = id; goto no_id; } list_add(&shp->shm_clist, &current->sysvshm.shm_clist); /* * shmid gets reported as "inode#" in /proc/pid/maps. * proc-ps tools use this. Changing this will break them. */ file_inode(file)->i_ino = shp->shm_perm.id; ns->shm_tot += numpages; error = shp->shm_perm.id; ipc_unlock_object(&shp->shm_perm); rcu_read_unlock(); return error; no_id: if (is_file_hugepages(file) && shp->mlock_user) user_shm_unlock(size, shp->mlock_user); fput(file); no_file: ipc_rcu_putref(shp, shm_rcu_free); return error; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)18433.64%1628.07%
Linus Torvalds366.58%23.51%
Nadia Derbey346.22%23.51%
Manfred Spraul254.57%47.02%
Badari Pulavarty254.57%23.51%
Hugh Dickins244.39%35.26%
Stephen D. Smalley244.39%23.51%
Andrew Morton244.39%47.02%
Naoya Horiguchi244.39%11.75%
Greg Kroah-Hartman224.02%35.26%
Li Zefan183.29%11.75%
Mel Gorman173.11%11.75%
Jack Miller152.74%11.75%
Kirill Korotaev132.38%11.75%
Rik Van Riel122.19%11.75%
Eric W. Biedermann122.19%11.75%
Davidlohr Bueso A112.01%35.26%
Andi Kleen101.83%23.51%
Vasiliy Kulikov61.10%11.75%
Al Viro30.55%11.75%
Pavel Emelyanov30.55%11.75%
Eric B Munson20.37%11.75%
Guy Streeter10.18%11.75%
Robin Holt10.18%11.75%
Motohiro Kosaki10.18%11.75%
Total547100.00%57100.00%

/* * Called with shm_ids.rwsem and ipcp locked. */
static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg) { struct shmid_kernel *shp; shp = container_of(ipcp, struct shmid_kernel, shm_perm); return security_shm_associate(shp, shmflg); }

Contributors

PersonTokensPropCommitsCommitProp
Nadia Derbey40100.00%2100.00%
Total40100.00%2100.00%

/* * Called with shm_ids.rwsem and ipcp locked. */
static inline int shm_more_checks(struct kern_ipc_perm *ipcp, struct ipc_params *params) { struct shmid_kernel *shp; shp = container_of(ipcp, struct shmid_kernel, shm_perm); if (shp->shm_segsz < params->u.size) return -EINVAL; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Nadia Derbey53100.00%2100.00%
Total53100.00%2100.00%

SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg) { struct ipc_namespace *ns; static const struct ipc_ops shm_ops = { .getnew = newseg, .associate = shm_security, .more_checks = shm_more_checks, }; struct ipc_params shm_params; ns = current->nsproxy->ipc_ns; shm_params.key = key; shm_params.flg = shmflg; shm_params.u.size = size; return ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params); }
static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_ds *in, int version) { switch (version) { case IPC_64: