Commit Graph

141 Commits

Author SHA1 Message Date
chs
cf529c6de1 simpler fix for the race between shmat() and shmdt():
change shmat() to hold shm_lock until it is completely done.
2019-10-09 17:47:13 +00:00
chs
a851cc5747 revert rev 1.139 (fixing a race between shmat() and shmdt())
that approach turned out to be too complicated.
2019-10-09 17:44:45 +00:00
chs
db38f3713d in shmdt(), wait until shmat() completes before detaching.
Reported-by: syzbot+8f470a1bf36b47ae0040@syzkaller.appspotmail.com
Reported-by: syzbot+45810b4c41ed65d9148d@syzkaller.appspotmail.com
2019-10-01 16:36:58 +00:00
maxv
542f82ceb4 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.
2019-08-23 10:22:14 +00:00
pgoyette
97b627eca5 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.
2019-08-07 00:38:01 +00:00
riastradh
6eb7fd2b53 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
2019-08-06 15:48:06 +00:00
chs
c7c4f4753b 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
2019-06-10 00:35:47 +00:00
pgoyette
18ed4257bd 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.
2019-04-10 10:03:50 +00:00
mrg
39e3203eaa 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.
2019-02-21 03:37:18 +00:00
riastradh
d1579b2d70 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!)
2018-09-03 16:29:22 +00:00
martin
76713fa86f 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.
2015-11-26 13:15:34 +00:00
pgoyette
462d797f59 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.
2015-11-06 02:26:42 +00:00
pgoyette
51126f7011 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.
2015-11-05 00:10:47 +00:00
pgoyette
446e5f46eb 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!
2015-05-13 01:16:15 +00:00
pgoyette
748778c4ee 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.
2015-05-13 01:00:16 +00:00
pgoyette
ae8c40588e In preparation for modularization of the SYSV* options, restore the
use of opt_sysv.h to get the -DSYSVxxx definitions.
2015-05-12 05:19:20 +00:00
njoly
2e3c0c8e82 In shmrealloc(), add missing condvar initialisations for segments
copied from previous location.
2014-05-27 21:00:46 +00:00
pooka
4f6fb3bf35 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.
2014-02-25 18:30:08 +00:00
elad
0c9d8d15c9 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.
2012-03-13 18:40:26 +00:00
christos
262ad41ded Add an optional pglist argument to uvm_obj_wirepages, to be
filled with the list of pages that were wired.
2011-08-27 09:11:52 +00:00
uebayasi
4d58dccaac Correct sizes to pass uvm_km_free(9) in error paths. 2011-07-30 06:19:02 +00:00
rmind
e225b7bd09 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.
2011-06-12 03:35:36 +00:00
rmind
2db2f4467c - Replace shmmap_entry_pool with kmem(9), as pool is not worth.
- Sprinkle __cacheline_aligned and __read_mostly.
2011-05-13 22:22:55 +00:00
jakllsch
359dcd7f55 Use 'z' printf format modifier to print size_t in debug code. 2010-07-27 14:25:23 +00:00
rmind
5503429772 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.
2009-10-05 23:47:04 +00:00
joerg
f5b0fec0e0 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.
2009-03-06 20:31:46 +00:00
christos
461a86f9bd merge christos-time_t 2009-01-11 02:45:45 +00:00
rmind
d2fec2fc4f sys_shmat: initialise shmid of shmmap entry earlier. Now error path,
i.e. shm_delete_mapping, wont use random value.
2008-12-22 13:49:17 +00:00
erh
75072b1c6f 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.
2008-10-27 15:40:56 +00:00
rmind
68121d6afa - Allow changing of kern.ipc.shmmax, just to avoid confusion.
- Change type of kern.ipc.shmmax to CTLTYPE_QUAD.
2008-10-07 09:35:03 +00:00
rmind
ea71ae9284 Fix the aligning of memory blocks again, finally...
Tested by <martin> on his sparc64 box.
2008-09-19 11:21:33 +00:00
ad
10d96b47b0 shmrealloc: destroy condition variables before freeing them. 2008-05-31 13:11:14 +00:00
rmind
15e36ef766 sys_shmget: use the correct size variable for uobj_wirepages().
Adjust shm_memlock() for consistency too.

Fixes PR/38782, reported by Adam Hoka.
2008-05-29 21:38:18 +00:00
rmind
76db3ec4cd sys_shmget: fix an object leak in case of error. 2008-05-11 18:48:00 +00:00
martin
ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
rmind
8d700f664c Fix shared memory code that it could handle > 4GB addresses correctly.
PR/38109, patch (a little bit modified) from Chris Brand.
2008-04-12 20:49:22 +00:00
njoly
1a6eaef2f2 Fix shm_cv/newshm_cv offset value by using the correct sizeof argument
(kcondvar_t -> struct shmid_ds).

ok by rmind@
2008-01-30 21:09:41 +00:00
rmind
4c26b5ddf3 - 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.
2008-01-27 18:37:50 +00:00
ad
77e0b2120f 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
2008-01-07 16:12:52 +00:00
ad
4a780c9ae2 Merge vmlocking2 to head. 2008-01-02 11:48:20 +00:00
dsl
7e2790cf6f 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.
2007-12-20 23:02:38 +00:00
msaitoh
8ce1f4fff2 fix typos 2007-04-29 20:23:34 +00:00
ad
59d979c5f1 Pass an ipl argument to pool_init/POOL_INIT to be used when initializing
the pool's lock.
2007-03-12 18:18:22 +00:00
christos
53524e44ef Kill caddr_t; there will be some MI fallout, but it will be fixed shortly. 2007-03-04 05:59:00 +00:00
thorpej
4f3d5a9cc0 TRUE -> true, FALSE -> false 2007-02-22 06:34:42 +00:00
ad
9abeea588a Replace some uses of lockmgr() / simplelocks. 2007-02-15 15:40:50 +00:00
ad
b07ec3fc38 Merge newlock2 to head. 2007-02-09 21:55:00 +00:00
rmind
ea2709ce49 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@
2007-02-07 18:45:36 +00:00
ad
dfe7788c29 Avoid sleeping with a held simple_lock. 2006-11-28 20:35:16 +00:00
christos
df031f1edc PR/34837: Mindaguas: Add SysV SHM dynamic reallocation and locking to the
physical memory
2006-11-25 21:40:04 +00:00