• Alexander Mikhalitsyn's avatar
    shm: extend forced shm destroy to support objects from several IPC nses · 85b6d246
    Alexander Mikhalitsyn authored
    Currently, the exit_shm() function not designed to work properly when
    task->sysvshm.shm_clist holds shm objects from different IPC namespaces.
    
    This is a real pain when sysctl kernel.shm_rmid_forced = 1, because it
    leads to use-after-free (reproducer exists).
    
    This is an attempt to fix the problem by extending exit_shm mechanism to
    handle shm's destroy from several IPC ns'es.
    
    To achieve that we do several things:
    
    1. add a namespace (non-refcounted) pointer to the struct shmid_kernel
    
    2. during new shm object creation (newseg()/shmget syscall) we
       initialize this pointer by current task IPC ns
    
    3. exit_shm() fully reworked such that it traverses over all shp's in
       task->sysvshm.shm_clist and gets IPC namespace not from current task
       as it was before but from shp's object itself, then call
       shm_destroy(shp, ns).
    
    Note: We need to be really careful here, because as it was said before
    (1), our pointer to IPC ns non-refcnt'ed.  T...
    85b6d246
shm.c 44.8 KB