Home | History | Annotate | Download | only in kern
History log of /src/sys/kern/sysv_shm.c
RevisionDateAuthorComments
 1.142  02-Mar-2024  mlelstv Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.
Should fix PR 57979
 1.141  09-Oct-2019  chs branches: 1.141.26;
simpler fix for the race between shmat() and shmdt():
change shmat() to hold shm_lock until it is completely done.
 1.140  09-Oct-2019  chs revert rev 1.139 (fixing a race between shmat() and shmdt())
that approach turned out to be too complicated.
 1.139  01-Oct-2019  chs in shmdt(), wait until shmat() completes before detaching.

Reported-by: syzbot+8f470a1bf36b47ae0040@syzkaller.appspotmail.com
Reported-by: syzbot+45810b4c41ed65d9148d@syzkaller.appspotmail.com
 1.138  23-Aug-2019  maxv Fix stupid bugs in linux_sys_shmctl(): the index could be out of bound
(page fault) and there was no proper locking.

Maybe we should just remove LINUX_SHM_STAT, like compat_linux32.
 1.137  07-Aug-2019  pgoyette Many years ago someone created a new __link_set_sysctl_funcs to hold
the list of routines that need to be called for setting up sysctl
variables. This worked great for all code included in the kernel
itself, but didn't deal with modules that want to create their own
sysctl data. So, we ended up with a lot of #ifdef _MODULE blocks
so modules could explicitly call their setup functions when loaded
as non-built-in modules.

So today, we complete the task that was started so many years ago.

When modules are loaded, after we've called xxx_modcmd(INIT...) we
check if the module contains its own __link_set_sysctl_funcs, and
if so we call the functions listed. We add a struct sysctllog member
to the struct module so we can call sysctl_teardown() when the module
gets unloaded. (The sequence of events ensures that the sysctl stuff
doesn't get created until the rest of the module's init code does any
required memory allocation.)

So, no more need to explicitly call the sysctl setup routines when
built as a loadable module.
 1.136  06-Aug-2019  riastradh Acquire shmseg uobj reference while we hold shm_lock.

Otherwise nothing prevents it from being detached under our feet when
we drop shm_lock.

Reported-by: syzbot+a76c618a6808a0fda475@syzkaller.appspotmail.com
 1.135  10-Jun-2019  chs branches: 1.135.2;
shmctl(SHM_LOCK) does not need to mess with mappings of the shm segment,
uvm_obj_wirepages() is sufficient. this fixes the problem reported in
https://syzkaller.appspot.com/bug?id=71f9271d761f5b6ed517a18030dc04f0135e6179
 1.134  10-Apr-2019  pgoyette Replace some "panic()" calls with simple "printf() ; return error"

There's no good reason for these build-time parameters to be allowed to
panic the kernel when it is easy to simply disable the module code and
fail gracefully.

While we're at it, similarly replace panic() when malloc fails to also
fail gracefully.
 1.133  21-Feb-2019  mrg for sysv ipc stat operations, explicitly copy the exported parts
instead of the whole ds structure.

besides triggering a recently added assert in netbsd32, this stops
exposing kernel addresses.

copy the mode clamping to 0777 from sem to shm and msg.


while here, make sure that the compat callers to sysv_ipc clear
the contents of the compat structure before setting the result
members to ensure padding bytes are cleared.

don't set/copy _sem_base, _msg_first, _msg_last or _shm_internal.
even if used, which seems very dodgy, they leak KVAs as well.
possibly this may affect linux binaries, in particular, the
comments around _shm_internal ("XXX Oh well.") may mean apps
rely upon these but hopefully not -- the comments date back to
rev 1.1 in 1995.

the _key, _seq and _msg_cbytes members are exported as before as
i found multiple consumers of these (no less than ipcs(1), and
they appear to be useful for debugging and more.


XXX: the naming of compat functions have too many styles. there
are at least 3 different ones changed here.
 1.132  03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.131  26-Nov-2015  martin branches: 1.131.10; 1.131.16; 1.131.18;
We never exec(2) with a kernel vmspace, so do not test for that, but instead
KASSERT() that we don't.
When calculating the load address for the interpreter (e.g. ld.elf_so),
we need to take into account wether the exec'd process will run with
topdown memory or bottom up. We can not use the current vmspace's flags
to test for that, as this happens too early. Luckily the execpack already
knows what the new state will be later, so instead of testing the current
vmspace, pass the info as additional argument to struct emul
e_vm_default_addr.
Fix all such functions and adopt all callers.
 1.130  06-Nov-2015  pgoyette In sysv_sem.c, defer establishment of exithook so we can initialize the
module code from module_init() rather than waiting until after calling
exec_init(). Use a RUN_ONCE routine at entry to each sys_sem* syscall
to establish the exithook, and no longer KASSERT that the hook has
been set before removing it. (A manually loaded module can be unloaded
before any syscalls have been invoked.)

Remove the conditional calls to the various xxx_init() routines from
init_main.c - we now rely on module_init() to handle initialization.

Let each sub-component's xxx_init() routine handle its own sysctl
sub-tree initialization; this removes another set of #ifdef ugliness.

Tested both built-in and loadable versions and verified that atf
test kernel/t_sysv passes.
 1.129  05-Nov-2015  pgoyette Now that SYSVSHM is modularized, reattach the linkages from uvm so that
we can correctly clean up on process exit or fork.

Without this, firefox attaches to a shared memory segment but doesn't
detach before exit. Thus once firefox causes an autoload for sysv_ipc
it cannot be unloaded since the segment still retains references.
 1.128  13-May-2015  pgoyette More prep: add a xxxfini() routine to each subcomponent so we can
clean up after ourselves. Mostly, this checks to make sure that
there are no active itmes, and then deallocates wired kernel virtual
memory. For SYSVSEM, we also disestablish the exithook() so we
won't try to call it after destroying its memory pool!
 1.127  13-May-2015  pgoyette More preparation for modularizing the SYSVxxx options. Here we
change the kern.ipc.sysvxxx sysctls into dynamic values, so each
sub-component of SYSVxxx can declare its own availability.
 1.126  12-May-2015  pgoyette In preparation for modularization of the SYSV* options, restore the
use of opt_sysv.h to get the -DSYSVxxx definitions.
 1.125  27-May-2014  njoly branches: 1.125.2; 1.125.4; 1.125.6; 1.125.10;
In shmrealloc(), add missing condvar initialisations for segments
copied from previous location.
 1.124  25-Feb-2014  pooka branches: 1.124.2;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
 1.123  13-Mar-2012  elad branches: 1.123.2; 1.123.4;
Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.
 1.122  27-Aug-2011  christos branches: 1.122.2; 1.122.6;
Add an optional pglist argument to uvm_obj_wirepages, to be
filled with the list of pages that were wired.
 1.121  30-Jul-2011  uebayasi Correct sizes to pass uvm_km_free(9) in error paths.
 1.120  12-Jun-2011  rmind Welcome to 5.99.53! Merge rmind-uvmplock branch:

- Reorganize locking in UVM and provide extra serialisation for pmap(9).
New lock order: [vmpage-owner-lock] -> pmap-lock.

- Simplify locking in some pmap(9) modules by removing P->V locking.

- Use lock object on vmobjlock (and thus vnode_t::v_interlock) to share
the locks amongst UVM objects where necessary (tmpfs, layerfs, unionfs).

- Rewrite and optimise x86 TLB shootdown code, make it simpler and cleaner.
Add TLBSTATS option for x86 to collect statistics about TLB shootdowns.

- Unify /dev/mem et al in MI code and provide required locking (removes
kernel-lock on some ports). Also, avoid cache-aliasing issues.

Thanks to Andrew Doran and Joerg Sonnenberger, as their initial patches
formed the core changes of this branch.
 1.119  13-May-2011  rmind branches: 1.119.2;
- Replace shmmap_entry_pool with kmem(9), as pool is not worth.
- Sprinkle __cacheline_aligned and __read_mostly.
 1.118  27-Jul-2010  jakllsch branches: 1.118.2;
Use 'z' printf format modifier to print size_t in debug code.
 1.117  05-Oct-2009  rmind branches: 1.117.2; 1.117.4;
shmexit: simplify a lot by avoiding unnecessary memory allocations, since
it is a last reference, just re-lock and check mapping list again. Often
there wont be re-locks at all, moreover, shm_lock is not contended at all.
 1.116  06-Mar-2009  joerg Remove SHMMAXPGS from all kernel configs. Dynamically compute the
initial limit as 1/4 of the physical memory. Ensure the limit is at
least 1024 pages, the old default on most platforms.
 1.115  11-Jan-2009  christos branches: 1.115.2;
merge christos-time_t
 1.114  22-Dec-2008  rmind sys_shmat: initialise shmid of shmmap entry earlier. Now error path,
i.e. shm_delete_mapping, wont use random value.
 1.113  27-Oct-2008  erh branches: 1.113.2;
Change the order of error checks in shmget so EEXIST is returned before
EINVAL or EACCESS so callers have a more reliable way to tell if a
shared memory segment already exists.
 1.112  07-Oct-2008  rmind branches: 1.112.2;
- Allow changing of kern.ipc.shmmax, just to avoid confusion.
- Change type of kern.ipc.shmmax to CTLTYPE_QUAD.
 1.111  19-Sep-2008  rmind Fix the aligning of memory blocks again, finally...
Tested by <martin> on his sparc64 box.
 1.110  31-May-2008  ad branches: 1.110.4;
shmrealloc: destroy condition variables before freeing them.
 1.109  29-May-2008  rmind sys_shmget: use the correct size variable for uobj_wirepages().
Adjust shm_memlock() for consistency too.

Fixes PR/38782, reported by Adam Hoka.
 1.108  11-May-2008  rmind sys_shmget: fix an object leak in case of error.
 1.107  28-Apr-2008  martin branches: 1.107.2;
Remove clause 3 and 4 from TNF licenses
 1.106  12-Apr-2008  rmind branches: 1.106.2; 1.106.4;
Fix shared memory code that it could handle > 4GB addresses correctly.
PR/38109, patch (a little bit modified) from Chris Brand.
 1.105  30-Jan-2008  njoly branches: 1.105.6; 1.105.8;
Fix shm_cv/newshm_cv offset value by using the correct sizeof argument
(kcondvar_t -> struct shmid_ds).

ok by rmind@
 1.104  27-Jan-2008  rmind - sys_shmget: size type must be size_t, not int. Should avoid possible
problems with huge allocations.
- shmrealloc: use newshmni for calculation of new sz, shminfo.shmmni
was a mistake. Convert sz to size_t type.
 1.103  07-Jan-2008  ad Patch up sysctl locking:

- Lock processes, credentials, filehead etc correctly.
- Acquire a read hold on sysctl_treelock if only doing a query.
- Don't wire down the output buffer. It doesn't work correctly and the code
regularly does long term sleeps with it held - it's not worth it.
- Don't hold locks other than sysctl_lock while doing copyout().
- Drop sysctl_lock while doing copyout / allocating memory in a few places.
- Don't take kernel_lock for sysctl.
- Fix a number of bugs spotted along the way
 1.102  02-Jan-2008  ad Merge vmlocking2 to head.
 1.101  20-Dec-2007  dsl Convert all the system call entry points from:
int foo(struct lwp *l, void *v, register_t *retval)
to:
int foo(struct lwp *l, const struct foo_args *uap, register_t *retval)
Fixup compat code to not write into 'uap' and (in some cases) to actually
pass a correctly formatted 'uap' structure with the right name to the
next routine.
A few 'compat' routines that just call standard ones have been deleted.
All the 'compat' code compiles (along with the kernels required to test
build it).
98% done by automated scripts.
 1.100  29-Apr-2007  msaitoh branches: 1.100.8; 1.100.14; 1.100.16; 1.100.20;
fix typos
 1.99  12-Mar-2007  ad branches: 1.99.2;
Pass an ipl argument to pool_init/POOL_INIT to be used when initializing
the pool's lock.
 1.98  04-Mar-2007  christos branches: 1.98.2;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.97  22-Feb-2007  thorpej TRUE -> true, FALSE -> false
 1.96  15-Feb-2007  ad branches: 1.96.2;
Replace some uses of lockmgr() / simplelocks.
 1.95  09-Feb-2007  ad Merge newlock2 to head.
 1.94  07-Feb-2007  rmind PR/28458: shmat(2) shmaddr argument is not honored as intended.
Patch applied, thanks for Minoura Makoto.

Please note, that one should fail if cannot attach to shmaddr,
but not attach it to other place.

OK by uwe@
 1.93  28-Nov-2006  ad Avoid sleeping with a held simple_lock.
 1.92  25-Nov-2006  christos PR/34837: Mindaguas: Add SysV SHM dynamic reallocation and locking to the
physical memory
 1.91  01-Nov-2006  yamt remove some __unused from function parameters.
 1.90  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.89  23-Jul-2006  ad branches: 1.89.4; 1.89.6;
Use the LWP cached credentials where sane.
 1.88  07-Jun-2006  kardel merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.87  14-May-2006  elad branches: 1.87.2;
integrate kauth.
 1.86  07-Dec-2005  thorpej branches: 1.86.4; 1.86.6; 1.86.8; 1.86.10; 1.86.12;
Use ANSI function delcs.
 1.85  10-Nov-2005  christos fix debugging; remove some defines that are now in the header file.
 1.84  01-Apr-2005  yamt branches: 1.84.2;
merge yamt-km branch.
- don't use managed mappings/backing objects for wired memory allocations.
save some resources like pv_entry. also fix (most of) PR/27030.
- simplify kernel memory management API.
- simplify pmap bootstrap of some ports.
- some related cleanups.
 1.83  26-Mar-2005  fvdl Fix some things regarding COMPAT_NETBSD32 and limits/VM addresses.

* For sparc64 and amd64, define *SIZ32 VM constants.
* Add a new function pointer to struct emul, pointing at a function
that will return the default VM map address. The default function
is uvm_map_defaultaddr, which just uses the VM_DEFAULT_ADDRESS
macro. This gives emulations control over the default map address,
and allows things to be mapped at the right address (in 32bit range)
for COMPAT_NETBSD32.
* Add code to adjust the data and stack limits when a COMPAT_NETBSD32
or COMPAT_SVR4_32 binary is executed.
* Don't use USRSTACK in kern_resource.c, use p_vmspace->vm_minsaddr
instead (emulations might have set it differently)
* Since this changes struct emul, bump kernel version to 3.99.2

Tested on amd64, compile-tested on sparc64.
 1.82  17-Oct-2004  jdolecek branches: 1.82.4; 1.82.6; 1.82.10;
fix typo (missing &)
 1.81  17-Oct-2004  jdolecek use nointr allocator for shmmap_entry_pool - this is always accessed
from process context
 1.80  16-Oct-2004  jdolecek kill the indirection via struct shm_handle and store pointer to the uvm
object direct to _shm_private; the indirection doesn't serve any
useful purpose and just wastes memory and cpu cycles
 1.79  28-Sep-2004  jdolecek add flag for shmget(2) to specify that later shmat(2) for the shared memory
segment should succeed even if the segment would be marked removed; use this
to implement the Linux-compatible semantics of shmat(2)

this fixes the old Linux VMware3 graphics problem with local display,
and possibly other local Linux X clients using MIT-SHM
 1.78  28-Sep-2004  jdolecek fold shmat1() back into sys_shmat(), the change in rev 1.64 is not sufficient
for Linux-compatible shmat() behaviour - shmat() for the removed shared memory
segment must work from all callers, the shared memory id could be passed e.g.
to native X server via MIT-SHM

temporarily remove the functionality, the Linux-compatible semantics
will be reimplemented differently
 1.77  25-Apr-2004  simonb Initialise (most) pools from a link set instead of explicit calls
to pool_init. Untouched pools are ones that either in arch-specific
code, or aren't initialiased during initial system startup.

Convert struct session, ucred and lockf to pools.
 1.76  23-Mar-2004  junyoung branches: 1.76.2;
- Nuke __P().
- Drop trailing spaces.
 1.75  06-Feb-2004  christos include <uvm/uvm_object.h> for the benefit of ports that don't include
it in <machine/pmap.h>
 1.74  05-Feb-2004  christos - Don't use uao_ functions directly; use them through the pgops methods.
- Fix missing reference leak in the error path of shmat() mentioned in
Full-Disclosure.
 1.73  06-Dec-2003  simonb Wrap long line.
 1.72  05-Dec-2003  jdolecek add #ifdef DEBUG segnum sanity check in shm_delete_mapping()
 1.71  26-Oct-2003  jdolecek allocate virtual memory for SYSV shm, msg and semaphore structures
separately from the bufpages, so that it would be possible to eventually
make their limits changeable in runtime

make static all local variables which do not need to be exported to other
kernel parts
 1.70  10-Sep-2003  drochner Fix the "COW" case if a process does a detach() between fork()
and exit(): we have to lookup the entry in the private copy
again, otherwise the wrong list is manipulated.
should fix a panic on postgres shutdown reported by Marc Recht

being here, improve sone debug messages
 1.69  09-Sep-2003  drochner Make per-process shm segment descriptor magement scale better for large
shminfo.shmseg, in view of the fact that only few processes utilize a
significant fraction of it:
-turn the table into a linked list, elements allocated from a pool(9)
-On fork(), just bump a refcount instead of copying the list; it will
be decremented on exit() and exec(). Only copy if an attach or detach
takes place in between, which is rarely the case.
 1.68  20-Feb-2003  atatat branches: 1.68.2;
Introduce "top down" memory management for mmap()ed allocations. This
means that the dynamic linker gets mapped in at the top of available
user virtual memory (typically just below the stack), shared libraries
get mapped downwards from that point, and calls to mmap() that don't
specify a preferred address will get mapped in below those.

This means that the heap and the mmap()ed allocations will grow
towards each other, allowing one or the other to grow larger than
before. Previously, the heap was limited to MAXDSIZ by the placement
of the dynamic linker (and the process's rlimits) and the space
available to mmap was hobbled by this reservation.

This is currently only enabled via an *option* for the i386 platform
(though other platforms are expected to follow). Add "options
USE_TOPDOWN_VM" to your kernel config file, rerun config, and rebuild
your kernel to take advantage of this.

Note that the pmap_prefer() interface has not yet been modified to
play nicely with this, so those platforms require a bit more work
(most notably the sparc) before they can use this new memory
arrangement.

This change also introduces a VM_DEFAULT_ADDRESS() macro that picks
the appropriate default address based on the size of the allocation or
the size of the process's text segment accordingly. Several drivers
and the SYSV SHM address assignment were changed to use this instead
of each one picking their own "default".
 1.67  01-Feb-2003  thorpej Add extensible malloc types, adapted from FreeBSD. This turns
malloc types into a structure, a pointer to which is passed around,
instead of an int constant. Allow the limit to be adjusted when the
malloc type is defined, or with a function call, as suggested by
Jonathan Stone.
 1.66  30-Jan-2003  atatat Two small changes to the ELF exec code:

(1) ELFNAME(load_file)() now takes a pointer to the entry point
offset, instead of taking a pointer to the entry point itself. This
allows proper adjustment of the ultimate entry point at a higher level
if the object containing the entry point is moved before the exec is
finished.

(2) Introduce VMCMD_FIXED, which means the address at which a given
vmcmd describes a mapping is fixed (ie, should not be moved). Don't
set this for entries pertaining to ld.so.

Also some minor comment/whitespace tweaks.
 1.65  18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.64  03-Apr-2002  fvdl branches: 1.64.4;
Split off the backend of the shmat system call, and find removed segments
if requested. This enables the linux compat code to be bug compatible
(under Linux, shmat() to a removed segment works).
 1.63  15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.62  12-Nov-2001  lukem add RCSIDs
 1.61  15-Mar-2001  chs branches: 1.61.2; 1.61.6;
eliminate the KERN_* error codes in favor of the traditional E* codes.
the mapping is:

KERN_SUCCESS 0
KERN_INVALID_ADDRESS EFAULT
KERN_PROTECTION_FAILURE EACCES
KERN_NO_SPACE ENOMEM
KERN_INVALID_ARGUMENT EINVAL
KERN_FAILURE various, mostly turn into KASSERTs
KERN_RESOURCE_SHORTAGE ENOMEM
KERN_NOT_RECEIVER <unused>
KERN_NO_ACCESS <unused>
KERN_PAGES_LOCKED <unused>
 1.60  14-Nov-2000  thorpej branches: 1.60.2;
NBPG -> PAGE_SIZE
 1.59  13-Sep-2000  thorpej Add an align argument to uvm_map() and some callers of that
routine. Works similarly fto pmap_prefer(), but allows callers
to specify a minimum power-of-two alignment of the region.
How we ever got along without this for so long is beyond me.
 1.58  22-Jul-2000  simonb Delete a couple of <uvm/uvm_extern.h> includes that were for
<sys/sysctl.h> only.
 1.57  27-Jun-2000  mrg remove include of <vm/vm.h>
 1.56  02-Jun-2000  simonb branches: 1.56.2;
Add new sysctl node "KERN_SYSVIPC_INFO" with "KERN_SYSVIPC_MSG_INFO",
"KERN_SYSVIPC_SEM_INFO" and "KERN_SYSVIPC_SHM_INFO" to return the
info and data structures for the relevent SysV IPC types. The return
structures use fixed-size types and should be compat32 safe. All
user-visible changes are protected with
#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)

Make all variable declarations extern in msg.h, sem.h and shm.h and
add relevent variable declarations to sysv_*.c and remove unneeded
header files from those .c files.

Make compat14 SysV IPC conversion functions and sysctl_file() static.

Change the data pointer to "void *" in sysctl_clockrate(),
sysctl_ntptime(), sysctl_file() and sysctl_doeproc().
 1.55  15-Apr-2000  simonb branches: 1.55.2;
Remove shmsegs declaration from conf/param.c - it doesn't belong here.
Instead, put it in kern/sysv_shm.c.
 1.54  26-Mar-2000  kleink Merge parts of chs-ubc2 into the trunk:
* Remove the casts to vaddr_t from the round_page() and trunc_page() macros to
make them type-generic, which is necessary i.e. to operate on file offsets
without truncating them.
* In due course, cast pointer arguments to these macros to an appropriate
integral type (paddr_t, vaddr_t).

Originally done by Chuck Silvers, updated by myself.
 1.53  03-Dec-1999  ragge First round of discarding the CL* macros.
 1.52  25-Aug-1999  thorpej branches: 1.52.2; 1.52.8;
Overhaul of the SVID IPC facilities, primarily to use the types specified
by the Single UNIX Specification version 2, rather than the SVR2-derived
types. While I was here, I did a namespace sweep to expose the constants
and strucutures, and structure members described by SUSv2; documentation
updates coming shortly.

Fixes kern/8158.
 1.51  24-Mar-1999  mrg branches: 1.51.4;
completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.
 1.50  21-Oct-1998  tron No need to get definition of "SYSV..." from "opt_sysv.h" because they
must be set if these files are compiled.
 1.49  19-Oct-1998  tron Defopt SYSVMSG, SYSVSEM and SYSVSHM.
 1.48  15-Aug-1998  mycroft Make copyright notices with my name consistent.
 1.47  13-Aug-1998  eeh Merge paddr_t changes into the main branch.
 1.46  04-Aug-1998  perry Abolition of bcopy, ovbcopy, bcmp, and bzero, phase one.
bcopy(x, y, z) -> memcpy(y, x, z)
ovbcopy(x, y, z) -> memmove(y, x, z)
bcmp(x, y, z) -> memcmp(x, y, z)
bzero(x, y) -> memset(x, 0, y)
 1.45  24-Jul-1998  thorpej branches: 1.45.2;
uvm_deallocate() takes an address and a size, not an address range. From
ITOH Yasufumi <yasufu-i@is.aist-nara.ac.jp>, PR #5834.
 1.44  07-May-1998  kleink Various SysV IPC prototype changes.
 1.43  10-Feb-1998  mrg - add defopt's for UVM, UVMHIST and PMAP_NEW.
- remove unnecessary UVMHIST_DECL's.
 1.42  05-Feb-1998  mrg initial import of the new virtual memory system, UVM, into -current.

UVM was written by chuck cranor <chuck@maria.wustl.edu>, with some
minor portions derived from the old Mach code. i provided some help
getting swap and paging working, and other bug fixes/ideas. chuck
silvers <chuq@chuq.com> also provided some other fixes.

this is the rest of the MI portion changes.

this will be KNF'd shortly. :-)
 1.41  03-Jan-1998  thorpej Make shmexit() and shmfork() take struct vmspace *'s, not struct proc *'s,
and update internal interfaces appropriately.
 1.40  09-Oct-1997  drochner Fix error handling - call wakeup() in error case too.
 1.39  07-Oct-1997  drochner Use a swap pager backed VM object for sysV shm instead of kernel VM.
Mostly from FreeBSD.
 1.38  01-Sep-1996  christos branches: 1.38.10;
Calling shmdt(2) before calling shmat(2) would crash the system because
p->p_vmspace->vm_shm would be NULL. Protected the rest of the cases where
that might happen too. This was the reason why sunxdoom would panic the
system in SVR4 emulation.
 1.37  16-Mar-1996  christos branches: 1.37.4;
Fix printf() formats.
 1.36  09-Feb-1996  christos More proto fixes
 1.35  04-Feb-1996  christos First pass at prototyping
 1.34  09-Dec-1995  mycroft Remove unused third arg to shmfork().
 1.33  07-Oct-1995  mycroft Prefix names of system call implementation functions with `sys_'.
 1.32  19-Sep-1995  thorpej Make system calls conform to a standard prototype and bring those
prototypes into scope.
 1.31  29-Jun-1995  cgd try to insure that the 'default' address for shm segments is the same
from process to process. It apparently is on SysV systems, and some
programs depend on this. Suggested by John Birrell <jb@werple.mira.net.au>.
 1.30  24-Jun-1995  christos Extracted all of the compat_xxx routines, and created a library [libcompat]
for them. There are a few #ifdef COMPAT_XX remaining, but they are not easy
or worth eliminating (yet).
 1.29  05-Jun-1995  pk We need some compat_10 routines if COMPAT_SUNOS is on (PR #1008).
 1.28  10-May-1995  christos tty_tb.c: need to include ioctl_compat.h in order to compile.
sysv_shm.c: make shm_find_segment_by_shmid global so it can be used by
COMPAT_HPUX. There should be a better way...
rest: Add #ifdef COMPAT_HPUX where needed
 1.27  22-Dec-1994  cgd kill the #if 0 around SHM_*LOCK. makes no difference, though...
 1.26  20-Oct-1994  cgd update for new syscall args description mechanism
 1.25  31-Aug-1994  mycroft Decrease shm_nused when a segment is deleted.
 1.24  22-Aug-1994  deraadt initialize shmmax to `# of pages' at compile time; multiply by NBPG at
boot time (in shminit). This supports architecture families with varying
values for NBPG, and does not break ipcs.
 1.23  04-Jul-1994  glass branches: 1.23.2;
returning a gift
 1.22  29-Jun-1994  cgd New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'
 1.21  25-Jun-1994  mycroft shm map is pageable.
 1.20  03-Jun-1994  mycroft Use the same algorithm as mmap() with MAP_ANON for placing the segment.
 1.19  03-Jun-1994  mycroft Get rid of unneeded bzero().
 1.18  03-Jun-1994  cgd sane initialization. fix bug kern/274
 1.17  25-May-1994  mycroft Update copyright.
 1.16  25-May-1994  mycroft If we try to create a key that's already being created, wait.
 1.15  25-May-1994  mycroft And finally, some optimization.
 1.14  25-May-1994  mycroft Fix this up some more. (I just read SVID again.)
 1.13  25-May-1994  mycroft Generalize ipcperm() a little.
 1.12  25-May-1994  mycroft Clean this up a bit, and fix several bugs.
 1.11  25-May-1994  hpeyerl sysv_shm.c from Adam.
sysv_ipc.c from me.
and various sundry changes to make sysv_ipc.c fit in.
(somewhat untested and not very pleasant reading material)
 1.10  08-Jan-1994  cgd SHM_LOCK and SHM_UNLOCK aren't just HPUXCOMPAT
 1.9  08-Jan-1994  mycroft #include vm_user.h.
 1.8  18-Dec-1993  mycroft Canonicalize all #includes.
 1.7  14-Nov-1993  cgd Add the System V message queue and semaphore facilities. Implemented
by Daniel Boulet <danny@BouletFermat.ab.ca>
 1.6  01-Aug-1993  mycroft branches: 1.6.2;
Add RCS identifiers (this time on the correct side of the branch), and
incorporate recent changes in netbsd-0-9 branch.
 1.5  17-Jul-1993  mycroft Finish moving struct definitions outside of function declarations.
 1.4  04-Jul-1993  cgd shminit has void return type.
 1.3  20-May-1993  cgd add $Id$ strings, and clean up file headers where necessary
 1.2  09-Apr-1993  cgd From: Guido van Rooij <guido@gvr.win.tue.nl>

when mmapping a file, permissions are checked as it should be. When
mprotect()-ing the address range afterwards, no protection was checked
regarding the protection of the file originally opened. So
when you open /usr/bin/su RDONLY and SHARED you could afterwards change
the mmapped region to READ|WRITE. This gave the possibility to obtain
root privs obviously.
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.2.2  14-Nov-1993  mycroft Canonicalize all #includes.
 1.6.2.1  14-Nov-1993  cgd Update from trunk:
Add the System V message queue and semaphore facilities. Implemented
by Daniel Boulet <danny@BouletFermat.ab.ca>
 1.23.2.1  31-Aug-1994  cgd from trunk
 1.37.4.1  11-Dec-1996  mycroft From trunk:
Fix panic when shmdt(2) is called before shmat(2).
 1.38.10.1  14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.45.2.1  30-Jul-1998  eeh Split vm_offset_t and vm_size_t into paddr_t, psize_t, vaddr_t, and vsize_t.
 1.51.4.1  11-Aug-1999  chs add casts for trunc_page() and round_page() args.
 1.52.8.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.52.2.3  27-Mar-2001  bouyer Sync with HEAD.
 1.52.2.2  22-Nov-2000  bouyer Sync with HEAD.
 1.52.2.1  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
 1.55.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.56.2.2  11-Apr-2004  jmc Add some missing includes 1.5 needs for the patch from #122 to work correctly
 1.56.2.1  08-Apr-2004  jmc Pullup patch (requested by groo in ticket #122)

Don't use uao_ functions directly; use them through the pgops methods.
Fix missing reference leak in the error path of shmat().
 1.60.2.6  29-May-2002  nathanw #include <sys/sa.h> before <sys/syscallargs.h>, to provide sa_upcall_t
now that <sys/param.h> doesn't include <sys/sa.h>.

(Behold the Power of Ed)
 1.60.2.5  17-Apr-2002  nathanw Catch up to -current.
 1.60.2.4  08-Jan-2002  nathanw Catch up to -current.
 1.60.2.3  14-Nov-2001  nathanw Catch up to -current.
 1.60.2.2  09-Apr-2001  nathanw Catch up with -current.
 1.60.2.1  05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.61.6.1  12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.61.2.2  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.61.2.1  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.64.4.2  09-Feb-2004  tron Pull up revision 1.75 (requested by he in ticket #1609):
include <uvm/uvm_object.h> for the benefit of ports that don't include
it in <machine/pmap.h>
 1.64.4.1  07-Feb-2004  jmc Pullup rev 1.74 (requested by groo in ticket #1604)

Don't use uao_ functions directly; use them through the pgops methods.
Fix missing reference leak in the error path of shmat() mentioned in
Full-Disclosure.
 1.68.2.6  11-Dec-2005  christos Sync with head.
 1.68.2.5  01-Apr-2005  skrll Sync with HEAD.
 1.68.2.4  19-Oct-2004  skrll Sync with HEAD
 1.68.2.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.68.2.2  18-Sep-2004  skrll Sync with HEAD.
 1.68.2.1  03-Aug-2004  skrll Sync with HEAD
 1.76.2.1  04-Oct-2004  jmc Pullup rev 1.78 (requested by jdolecek in ticket #884)

Fix linux handling of SysV-style shared memory. Fixed Linux VMware display
problems.
 1.82.10.1  18-Sep-2005  tron Pull up following revision(s) (requested by fvdl in ticket #798):
sys/compat/sunos/sunos_exec.c: revision 1.47
sys/compat/pecoff/pecoff_emul.c: revision 1.11
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.45
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.12
sys/sys/proc.h: revision 1.198
sys/compat/mach/mach_exec.c: revision 1.56
sys/compat/freebsd/freebsd_exec.c: revision 1.27
sys/arch/sparc64/include/vmparam.h: revision 1.27
sys/kern/kern_resource.c: revision 1.91
sys/compat/netbsd32/netbsd32_netbsd.c: revision 1.88
sys/compat/osf1/osf1_exec.c: revision 1.39
sys/compat/svr4_32/svr4_32_resource.c: revision 1.5
sys/compat/ultrix/ultrix_misc.c: revision 1.99
sys/compat/svr4_32/svr4_32_exec.h: revision 1.9
sys/kern/exec_elf32.c: revision 1.103
sys/compat/aoutm68k/aoutm68k_exec.c: revision 1.19
sys/compat/sunos32/sunos32_exec.c: revision 1.20
sys/compat/hpux/hpux_exec.c: revision 1.46
sys/compat/darwin/darwin_exec.c: revision 1.40
sys/kern/sysv_shm.c: revision 1.83
sys/uvm/uvm_extern.h: revision 1.99
sys/uvm/uvm_mmap.c: revision 1.89
sys/kern/kern_exec.c: revision 1.195
sys/compat/netbsd32/netbsd32.h: revision 1.31
sys/arch/sparc64/sparc64/svr4_32_machdep.c: revision 1.20
sys/compat/svr4/svr4_exec.c: revision 1.56
sys/compat/irix/irix_exec.c: revision 1.41
sys/compat/ibcs2/ibcs2_exec.c: revision 1.63
sys/compat/svr4_32/svr4_32_exec.c: revision 1.16
sys/arch/amd64/include/vmparam.h: revision 1.8
sys/compat/linux/common/linux_exec.c: revision 1.73
Fix some things regarding COMPAT_NETBSD32 and limits/VM addresses.
* For sparc64 and amd64, define *SIZ32 VM constants.
* Add a new function pointer to struct emul, pointing at a function
that will return the default VM map address. The default function
is uvm_map_defaultaddr, which just uses the VM_DEFAULT_ADDRESS
macro. This gives emulations control over the default map address,
and allows things to be mapped at the right address (in 32bit range)
for COMPAT_NETBSD32.
* Add code to adjust the data and stack limits when a COMPAT_NETBSD32
or COMPAT_SVR4_32 binary is executed.
* Don't use USRSTACK in kern_resource.c, use p_vmspace->vm_minsaddr
instead (emulations might have set it differently)
* Since this changes struct emul, bump kernel version to 3.99.2
Tested on amd64, compile-tested on sparc64.
 1.82.6.2  26-Mar-2005  yamt sync with head.
 1.82.6.1  25-Jan-2005  yamt convert to new apis.
 1.82.4.1  29-Apr-2005  kent sync with -current
 1.84.2.6  04-Feb-2008  yamt sync with head.
 1.84.2.5  21-Jan-2008  yamt sync with head
 1.84.2.4  03-Sep-2007  yamt sync with head.
 1.84.2.3  26-Feb-2007  yamt sync with head.
 1.84.2.2  30-Dec-2006  yamt sync with head.
 1.84.2.1  21-Jun-2006  yamt sync with head.
 1.86.12.1  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.86.10.2  06-May-2006  christos - Move kauth_cred_t declaration to <sys/types.h>
- Cleanup struct ucred; forward declarations that are unused.
- Don't include <sys/kauth.h> in any header, but include it in the c files
that need it.

Approved by core.
 1.86.10.1  08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.86.8.3  11-Aug-2006  yamt sync with head
 1.86.8.2  26-Jun-2006  yamt sync with head.
 1.86.8.1  24-May-2006  yamt sync with head.
 1.86.6.2  01-Jun-2006  kardel Sync with head.
 1.86.6.1  04-Feb-2006  simonb Adapt for timecounters: mostly use get*time() and use "time_second"
instead of "time.tv_sec".
 1.86.4.1  09-Sep-2006  rpaulo sync with head
 1.87.2.1  19-Jun-2006  chap Sync with head.
 1.89.6.2  10-Dec-2006  yamt sync with head.
 1.89.6.1  22-Oct-2006  yamt sync with head
 1.89.4.3  09-Feb-2007  ad Sync with HEAD.
 1.89.4.2  30-Jan-2007  ad Remove support for SA. Ok core@.
 1.89.4.1  12-Jan-2007  ad Sync with head.
 1.96.2.4  07-May-2007  yamt sync with head.
 1.96.2.3  24-Mar-2007  yamt sync with head.
 1.96.2.2  12-Mar-2007  rmind Sync with HEAD.
 1.96.2.1  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.98.2.2  08-Jun-2007  ad Sync with head.
 1.98.2.1  13-Mar-2007  ad Sync with head.
 1.99.2.1  11-Jul-2007  mjf Sync with head.
 1.100.20.2  08-Jan-2008  bouyer Sync with HEAD
 1.100.20.1  02-Jan-2008  bouyer Sync with HEAD
 1.100.16.3  26-Dec-2007  ad Sync with head.
 1.100.16.2  05-Dec-2007  rmind Decrease shm_realloc_disable in correct places.
 1.100.16.1  05-Dec-2007  rmind - Make SysV shared memory subsystem MP-safe;
- Replace tsleep/wakeup with condvars;
- Replace malloc with kmem;
- Avoid holding of lock while reallocating;
- Fix the check of last segment when reallocating;
- sys_shmat: unmap if uvm_map_pageable() fails;
- Few cosmetics;

Proposed on <tech-kern>.
 1.100.14.1  18-Feb-2008  mjf Sync with HEAD.
 1.100.8.2  23-Mar-2008  matt sync with HEAD
 1.100.8.1  09-Jan-2008  matt sync with HEAD
 1.105.8.3  27-Dec-2008  christos merge with head.
 1.105.8.2  01-Nov-2008  christos Sync with head.
 1.105.8.1  29-Mar-2008  christos Welcome to the time_t=long long dev_t=uint64_t branch.
 1.105.6.3  17-Jan-2009  mjf Sync with HEAD.
 1.105.6.2  28-Sep-2008  mjf Sync with HEAD.
 1.105.6.1  02-Jun-2008  mjf Sync with HEAD.
 1.106.4.4  11-Aug-2010  yamt sync with head.
 1.106.4.3  11-Mar-2010  yamt sync with head
 1.106.4.2  04-May-2009  yamt sync with head.
 1.106.4.1  16-May-2008  yamt sync with head.
 1.106.2.2  04-Jun-2008  yamt sync with head
 1.106.2.1  18-May-2008  yamt sync with head.
 1.107.2.4  10-Oct-2008  skrll Sync with HEAD.
 1.107.2.3  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.107.2.2  14-May-2008  wrstuden Per discussion with ad, remove most of the #include <sys/sa.h> lines
as they were including sa.h just for the type(s) needed for syscallargs.h.

Instead, create a new file, sys/satypes.h, which contains just the
types needed for syscallargs.h. Yes, there's only one now, but that
may change and it's probably more likely to change if it'd be difficult
to handle. :-)

Per discussion with matt at n dot o, add an include of satypes.h to
sigtypes.h. Upcall handlers are kinda signal handlers, and signalling
is the header file that's already included for syscallargs.h that
closest matches SA.

This shaves about 3000 lines off of the diff of the branch relative
to the base. That also represents about 18% of the total before this
checkin.

I think this reduction is very good thing.
 1.107.2.1  10-May-2008  wrstuden Initial checkin of re-adding SA. Everything except kern_sa.c
compiles in GENERIC for i386. This is still a work-in-progress, but
this checkin covers most of the mechanical work (changing signalling
to be able to accomidate SA's process-wide signalling and re-adding
includes of sys/sa.h and savar.h). Subsequent changes will be much
more interesting.

Also, kern_sa.c has received partial cleanup. There's still more
to do, though.
 1.110.4.2  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.110.4.1  19-Oct-2008  haad Sync with HEAD.
 1.112.2.2  28-Apr-2009  skrll Sync with HEAD.
 1.112.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.113.2.1  14-Jan-2009  snj Pull up following revision(s) (requested by rmind in ticket #248):
sys/kern/sysv_shm.c: revision 1.114
sys_shmat: initialise shmid of shmmap entry earlier. Now error path,
i.e. shm_delete_mapping, wont use random value.
 1.115.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.117.4.3  31-May-2011  rmind sync with head
 1.117.4.2  05-Mar-2011  rmind sync with head
 1.117.4.1  23-Apr-2010  rmind Use consistent naming - uvm_obj_*().
 1.117.2.1  17-Aug-2010  uebayasi Sync with HEAD.
 1.118.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.119.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.122.6.1  05-Apr-2012  mrg sync to latest -current.
 1.122.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.122.2.1  17-Apr-2012  yamt sync with head
 1.123.4.1  18-May-2014  rmind sync with head
 1.123.2.2  03-Dec-2017  jdolecek update from HEAD
 1.123.2.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.124.2.1  10-Aug-2014  tls Rebase.
 1.125.10.2  21-Jan-2020  martin Pull up the following, requested by christos in ticket #1720:

sys/compat/common/kern_sig_43.c 1.36
sys/compat/linux/arch/amd64/linux_machdep.c 1.59
sys/compat/linux/common/linux_fcntl.h 1.18
sys/compat/linux/common/linux_file64.c 1.62
sys/compat/linux/common/linux_ipc.c 1.57
sys/compat/linux/common/linux_misc.c 1.243
sys/compat/linux/common/linux_signal.c 1.81
sys/compat/linux/common/linux_socket.c 1.149 (patch)
sys/compat/linux/common/linux_socket.h 1.24
sys/compat/linux/common/linux_statfs.h 1.7
sys/compat/linux/common/linux_termios.c 1.38
sys/compat/linux/common/linux_termios.h 1.22
sys/compat/linux32/common/linux32_dirent.c 1.20
sys/compat/linux32/common/linux32_ioctl.c 1.14
sys/compat/linux32/common/linux32_misc.c 1.27
sys/compat/linux32/common/linux32_signal.c 1.20
sys/compat/linux32/common/linux32_sysinfo.c 1.8
sys/compat/linux32/common/linux32_termios.c 1.15
sys/compat/linux32/common/linux32_utsname.c 1.10
sys/compat/netbsd32/netbsd32_compat_20.c 1.39
sys/compat/netbsd32/netbsd32_compat_43.c 1.59
sys/compat/netbsd32/netbsd32_compat_50.c 1.44
sys/compat/ossaudio/ossaudio.c 1.75
sys/kern/sysv_shm.c 1.138
sys/miscfs/procfs/procfs_linux.c 1.75 (patch)
sys/sys/shm.h 1.54 (patch)

Fix various info leaks, out of bound access, usage of uninitialized
values and direct access to userland variables from kernel space
and memory leaks in system calls implemented for the compatibility
subsystems.
 1.125.10.1  23-Feb-2019  martin Pull up following revision(s) (requested by mrg in ticket #1679):
sys/compat/sys/ipc.h: revision 1.6
sys/compat/sys/ipc.h: revision 1.7
sys/compat/sys/shm.h: revision 1.8
sys/kern/sysv_shm.c: revision 1.133
sys/compat/sys/sem.h: revision 1.7
sys/compat/linux/common/linux_ipc.c: revision 1.56
sys/compat/netbsd32/netbsd32_conv.h: revision 1.38
sys/kern/sysv_sem.c: revision 1.96
sys/compat/netbsd32/netbsd32_compat_14.c: revision 1.28
sys/compat/netbsd32/netbsd32_compat_14.c: revision 1.29
sys/compat/linux32/common/linux32_ipccall.c: revision 1.12
sys/kern/sysv_msg.c: revision 1.73
sys/compat/sys/msg.h: revision 1.6

for sysv ipc stat operations, explicitly copy the exported parts
instead of the whole ds structure.
besides triggering a recently added assert in netbsd32, this stops
exposing kernel addresses.

copy the mode clamping to 0777 from sem to shm and msg.

while here, make sure that the compat callers to sysv_ipc clear
the contents of the compat structure before setting the result
members to ensure padding bytes are cleared.

don't set/copy _sem_base, _msg_first, _msg_last or _shm_internal.
even if used, which seems very dodgy, they leak KVAs as well.
possibly this may affect linux binaries, in particular, the
comments around _shm_internal ("XXX Oh well.") may mean apps
rely upon these but hopefully not -- the comments date back to
rev 1.1 in 1995.

the _key, _seq and _msg_cbytes members are exported as before as
i found multiple consumers of these (no less than ipcs(1), and
they appear to be useful for debugging and more.

XXX: the naming of compat functions have too many styles. there
are at least 3 different ones changed here.

fix naming errors in previous. (this file is no longer compiled, but
this fix makes the pull up more obvious, before deleting this file.)

include libkern.h or strings.h. should fix i386 build issues.
 1.125.6.1  23-Feb-2019  martin Pull up following revision(s) (requested by mrg in ticket #1679):
sys/compat/sys/ipc.h: revision 1.6
sys/compat/sys/ipc.h: revision 1.7
sys/compat/sys/shm.h: revision 1.8
sys/kern/sysv_shm.c: revision 1.133
sys/compat/sys/sem.h: revision 1.7
sys/compat/linux/common/linux_ipc.c: revision 1.56
sys/compat/netbsd32/netbsd32_conv.h: revision 1.38
sys/kern/sysv_sem.c: revision 1.96
sys/compat/netbsd32/netbsd32_compat_14.c: revision 1.28
sys/compat/netbsd32/netbsd32_compat_14.c: revision 1.29
sys/compat/linux32/common/linux32_ipccall.c: revision 1.12
sys/kern/sysv_msg.c: revision 1.73
sys/compat/sys/msg.h: revision 1.6

for sysv ipc stat operations, explicitly copy the exported parts
instead of the whole ds structure.
besides triggering a recently added assert in netbsd32, this stops
exposing kernel addresses.

copy the mode clamping to 0777 from sem to shm and msg.

while here, make sure that the compat callers to sysv_ipc clear
the contents of the compat structure before setting the result
members to ensure padding bytes are cleared.

don't set/copy _sem_base, _msg_first, _msg_last or _shm_internal.
even if used, which seems very dodgy, they leak KVAs as well.
possibly this may affect linux binaries, in particular, the
comments around _shm_internal ("XXX Oh well.") may mean apps
rely upon these but hopefully not -- the comments date back to
rev 1.1 in 1995.

the _key, _seq and _msg_cbytes members are exported as before as
i found multiple consumers of these (no less than ipcs(1), and
they appear to be useful for debugging and more.

XXX: the naming of compat functions have too many styles. there
are at least 3 different ones changed here.

fix naming errors in previous. (this file is no longer compiled, but
this fix makes the pull up more obvious, before deleting this file.)

include libkern.h or strings.h. should fix i386 build issues.
 1.125.4.2  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.125.4.1  06-Jun-2015  skrll Sync with HEAD
 1.125.2.2  21-Jan-2020  martin Pull up the following, requested by christos in ticket #1720:

sys/compat/common/kern_sig_43.c 1.36
sys/compat/linux/arch/amd64/linux_machdep.c 1.59
sys/compat/linux/common/linux_fcntl.h 1.18
sys/compat/linux/common/linux_file64.c 1.62
sys/compat/linux/common/linux_ipc.c 1.57
sys/compat/linux/common/linux_misc.c 1.243
sys/compat/linux/common/linux_signal.c 1.81
sys/compat/linux/common/linux_socket.c 1.149 (patch)
sys/compat/linux/common/linux_socket.h 1.24
sys/compat/linux/common/linux_statfs.h 1.7
sys/compat/linux/common/linux_termios.c 1.38
sys/compat/linux/common/linux_termios.h 1.22
sys/compat/linux32/common/linux32_dirent.c 1.20
sys/compat/linux32/common/linux32_ioctl.c 1.14
sys/compat/linux32/common/linux32_misc.c 1.27
sys/compat/linux32/common/linux32_signal.c 1.20
sys/compat/linux32/common/linux32_sysinfo.c 1.8
sys/compat/linux32/common/linux32_termios.c 1.15
sys/compat/linux32/common/linux32_utsname.c 1.10
sys/compat/netbsd32/netbsd32_compat_20.c 1.39
sys/compat/netbsd32/netbsd32_compat_43.c 1.59
sys/compat/netbsd32/netbsd32_compat_50.c 1.44
sys/compat/ossaudio/ossaudio.c 1.75
sys/kern/sysv_shm.c 1.138
sys/miscfs/procfs/procfs_linux.c 1.75 (patch)
sys/sys/shm.h 1.54 (patch)

Fix various info leaks, out of bound access, usage of uninitialized
values and direct access to userland variables from kernel space
and memory leaks in system calls implemented for the compatibility
subsystems.
 1.125.2.1  23-Feb-2019  martin Pull up following revision(s) (requested by mrg in ticket #1679):
sys/compat/sys/ipc.h: revision 1.6
sys/compat/sys/ipc.h: revision 1.7
sys/compat/sys/shm.h: revision 1.8
sys/kern/sysv_shm.c: revision 1.133
sys/compat/sys/sem.h: revision 1.7
sys/compat/linux/common/linux_ipc.c: revision 1.56
sys/compat/netbsd32/netbsd32_conv.h: revision 1.38
sys/kern/sysv_sem.c: revision 1.96
sys/compat/netbsd32/netbsd32_compat_14.c: revision 1.28
sys/compat/netbsd32/netbsd32_compat_14.c: revision 1.29
sys/compat/linux32/common/linux32_ipccall.c: revision 1.12
sys/kern/sysv_msg.c: revision 1.73
sys/compat/sys/msg.h: revision 1.6

for sysv ipc stat operations, explicitly copy the exported parts
instead of the whole ds structure.
besides triggering a recently added assert in netbsd32, this stops
exposing kernel addresses.

copy the mode clamping to 0777 from sem to shm and msg.

while here, make sure that the compat callers to sysv_ipc clear
the contents of the compat structure before setting the result
members to ensure padding bytes are cleared.

don't set/copy _sem_base, _msg_first, _msg_last or _shm_internal.
even if used, which seems very dodgy, they leak KVAs as well.
possibly this may affect linux binaries, in particular, the
comments around _shm_internal ("XXX Oh well.") may mean apps
rely upon these but hopefully not -- the comments date back to
rev 1.1 in 1995.

the _key, _seq and _msg_cbytes members are exported as before as
i found multiple consumers of these (no less than ipcs(1), and
they appear to be useful for debugging and more.

XXX: the naming of compat functions have too many styles. there
are at least 3 different ones changed here.

fix naming errors in previous. (this file is no longer compiled, but
this fix makes the pull up more obvious, before deleting this file.)

include libkern.h or strings.h. should fix i386 build issues.
 1.131.18.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.131.18.1  10-Jun-2019  christos Sync with HEAD
 1.131.16.1  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.131.10.3  11-Mar-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1945):

sys/kern/sysv_shm.c: revision 1.142 (patch)

Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.

Should fix PR 57979
 1.131.10.2  21-Jan-2020  martin Pull up the following, requested by christos in ticket #1487:

sys/compat/common/kern_sig_43.c 1.36
sys/compat/linux/arch/amd64/linux_machdep.c 1.59
sys/compat/linux/common/linux_fcntl.h 1.18
sys/compat/linux/common/linux_file64.c 1.62
sys/compat/linux/common/linux_ipc.c 1.57
sys/compat/linux/common/linux_misc.c 1.243
sys/compat/linux/common/linux_signal.c 1.81
sys/compat/linux/common/linux_socket.c 1.149
sys/compat/linux/common/linux_socket.h 1.24
sys/compat/linux/common/linux_statfs.h 1.7
sys/compat/linux/common/linux_termios.c 1.38
sys/compat/linux/common/linux_termios.h 1.22
sys/compat/linux32/common/linux32_dirent.c 1.20
sys/compat/linux32/common/linux32_ioctl.c 1.14
sys/compat/linux32/common/linux32_misc.c 1.27
sys/compat/linux32/common/linux32_signal.c 1.20
sys/compat/linux32/common/linux32_sysinfo.c 1.8
sys/compat/linux32/common/linux32_termios.c 1.15
sys/compat/linux32/common/linux32_utsname.c 1.10
sys/compat/netbsd32/netbsd32_compat_20.c 1.39
sys/compat/netbsd32/netbsd32_compat_43.c 1.59
sys/compat/netbsd32/netbsd32_compat_50.c 1.44
sys/compat/ossaudio/ossaudio.c 1.75
sys/kern/sysv_shm.c 1.138
sys/miscfs/procfs/procfs_linux.c 1.75 (patch)
sys/sys/shm.h 1.54

Fix various info leaks, out of bound access, usage of uninitialized
values and direct access to userland variables from kernel space
and memory leaks in system calls implemented for the compatibility
subsystems.
 1.131.10.1  23-Feb-2019  martin Pull up following revision(s) (requested by mrg in ticket #1195):
sys/compat/sys/ipc.h: revision 1.6
sys/compat/sys/ipc.h: revision 1.7
sys/compat/sys/shm.h: revision 1.8
sys/kern/sysv_shm.c: revision 1.133
sys/compat/sys/sem.h: revision 1.7
sys/compat/linux/common/linux_ipc.c: revision 1.56
sys/compat/netbsd32/netbsd32_conv.h: revision 1.38
sys/kern/sysv_sem.c: revision 1.96
sys/compat/netbsd32/netbsd32_compat_14.c: revision 1.28
sys/compat/netbsd32/netbsd32_compat_14.c: revision 1.29
sys/compat/linux32/common/linux32_ipccall.c: revision 1.12
sys/kern/sysv_msg.c: revision 1.73
sys/compat/sys/msg.h: revision 1.6

for sysv ipc stat operations, explicitly copy the exported parts
instead of the whole ds structure.
besides triggering a recently added assert in netbsd32, this stops
exposing kernel addresses.

copy the mode clamping to 0777 from sem to shm and msg.

while here, make sure that the compat callers to sysv_ipc clear
the contents of the compat structure before setting the result
members to ensure padding bytes are cleared.

don't set/copy _sem_base, _msg_first, _msg_last or _shm_internal.
even if used, which seems very dodgy, they leak KVAs as well.
possibly this may affect linux binaries, in particular, the
comments around _shm_internal ("XXX Oh well.") may mean apps
rely upon these but hopefully not -- the comments date back to
rev 1.1 in 1995.

the _key, _seq and _msg_cbytes members are exported as before as
i found multiple consumers of these (no less than ipcs(1), and
they appear to be useful for debugging and more.

XXX: the naming of compat functions have too many styles. there
are at least 3 different ones changed here.

fix naming errors in previous. (this file is no longer compiled, but
this fix makes the pull up more obvious, before deleting this file.)

include libkern.h or strings.h. should fix i386 build issues.
 1.135.2.5  11-Mar-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1814):

sys/kern/sysv_shm.c: revision 1.142

Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.

Should fix PR 57979
 1.135.2.4  10-Oct-2019  martin Pull up following revision(s) (requested by chs in ticket #294):

sys/kern/sysv_shm.c: revision 1.140,1.141

revert rev 1.139 (fixing a race between shmat() and shmdt())
that approach turned out to be too complicated.

-

simpler fix for the race between shmat() and shmdt():
change shmat() to hold shm_lock until it is completely done.
 1.135.2.3  03-Oct-2019  martin Pull up following revision(s) (requested by chs in ticket #275):

sys/kern/sysv_shm.c: revision 1.139

in shmdt(), wait until shmat() completes before detaching.
 1.135.2.2  13-Sep-2019  martin Pull up following revision(s) (requested by maxv in ticket #194):

sys/compat/linux/common/linux_socket.c: revision 1.146
sys/compat/linux/common/linux_socket.c: revision 1.147
sys/compat/linux/common/linux_socket.c: revision 1.148
sys/compat/linux/common/linux_socket.c: revision 1.149
sys/compat/linux/arch/amd64/linux_machdep.c: revision 1.59
sys/compat/linux32/common/linux32_sysinfo.c: revision 1.8
sys/kern/sysv_shm.c: revision 1.138
sys/compat/linux/common/linux_file64.c: revision 1.61
sys/compat/linux/common/linux_file64.c: revision 1.62
sys/compat/netbsd32/netbsd32_compat_43.c: revision 1.58
sys/compat/linux32/common/linux32_dirent.c: revision 1.20
sys/compat/linux32/common/linux32_utsname.c: revision 1.10
sys/compat/linux/common/linux_termios.h: revision 1.22
sys/compat/linux32/common/linux32_termios.c: revision 1.15
sys/compat/linux32/common/linux32_misc.c: revision 1.27
sys/compat/linux32/common/linux32_ioctl.c: revision 1.14
sys/compat/linux/common/linux_statfs.h: revision 1.7
sys/compat/linux/common/linux_ipc.c: revision 1.57
sys/compat/linux/common/linux_fcntl.h: revision 1.18
sys/compat/linux/common/linux_socket.h: revision 1.24
sys/sys/shm.h: revision 1.54
sys/compat/ossaudio/ossaudio.c: revision 1.75
sys/compat/linux32/common/linux32_signal.c: revision 1.20
sys/miscfs/procfs/procfs_linux.c: revision 1.75
sys/compat/linux/common/linux_signal.c: revision 1.81
sys/compat/linux/common/linux_termios.c: revision 1.38
sys/compat/linux/common/linux_misc.c: revision 1.241
sys/compat/linux/common/linux_misc.c: revision 1.242
sys/compat/linux/common/linux_misc.c: revision 1.243
sys/compat/linux/common/linux_misc.c: revision 1.244

Fix info leaks.

Fix stupid bugs in linux_sys_shmctl(): the index could be out of bound
(page fault) and there was no proper locking.
Maybe we should just remove LINUX_SHM_STAT, like compat_linux32.

Remove printf.

When dealing with an unknown value, set -1, to prevent (harmless)
uninitialized accesses later.

Add a default case, don't call sys_ioctl() with an uninitialized 'com'
argument.

Fix error handling, returns an errno, not -1.

Put the printf under DEBUG_LINUX.


Hum, don't forget the 'pid' argument, otherwise we're not gonna go very
far.

Don't read data from userland directly. This simply does not work on any
recent x86 CPU (thanks to SMAP) and all architectures that forbid direct
access to userland from the kernel. But I guess no one noticed because no
one ever uses compat_linux, right?

Hum, don't pass an mbuf to realloc(). Inspired from copyin32_msg_control().

Fix memory leak.

I don't see the point in having this useless printf, but add a '\n' to it,
so that it at least displays useless stuff correctly.

Hum, remove incorrect assignment. Userland could have passed a smaller
namelen, and the uninitialized bytes from sb_data were being used later in
the network stack.
 1.135.2.1  10-Sep-2019  martin Pull up following revision(s) (requested by maxv in ticket #191):

sys/kern/sysv_shm.c: revision 1.136

Acquire shmseg uobj reference while we hold shm_lock.

Otherwise nothing prevents it from being detached under our feet when
we drop shm_lock.
 1.141.26.1  11-Mar-2024  martin Pull up following revision(s) (requested by riastradh in ticket #626):

sys/kern/sysv_shm.c: revision 1.142

Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.

Should fix PR 57979

RSS XML Feed