Module Name: src
Committed By: christos
Date: Sat Apr 11 23:05:26 UTC 2009
Modified Files:
src/sys/dev/dmover: dmover_io.c
src/sys/dev/putter: putter.c
src/sys/kern: kern_drvctl.c sys_mqueue.c sys_pipe.c vfs_vnops.c
src/sys/net: bpf.c if_tap.c
src/sys/opencrypto: cryptodev.c
Log Message:
Fix locking as Andy explained. Also fill in uid and gid like sys_pipe did.
To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/dmover/dmover_io.c
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/putter/putter.c
cvs rdiff -u -r1.25 -r1.26 src/sys/kern/kern_drvctl.c
cvs rdiff -u -r1.15 -r1.16 src/sys/kern/sys_mqueue.c
cvs rdiff -u -r1.111 -r1.112 src/sys/kern/sys_pipe.c
cvs rdiff -u -r1.164 -r1.165 src/sys/kern/vfs_vnops.c
cvs rdiff -u -r1.145 -r1.146 src/sys/net/bpf.c
cvs rdiff -u -r1.56 -r1.57 src/sys/net/if_tap.c
cvs rdiff -u -r1.48 -r1.49 src/sys/opencrypto/cryptodev.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/dmover/dmover_io.c
diff -u src/sys/dev/dmover/dmover_io.c:1.33 src/sys/dev/dmover/dmover_io.c:1.34
--- src/sys/dev/dmover/dmover_io.c:1.33 Sat Apr 11 11:47:33 2009
+++ src/sys/dev/dmover/dmover_io.c Sat Apr 11 19:05:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: dmover_io.c,v 1.33 2009/04/11 15:47:33 christos Exp $ */
+/* $NetBSD: dmover_io.c,v 1.34 2009/04/11 23:05:26 christos Exp $ */
/*
* Copyright (c) 2002, 2003 Wasabi Systems, Inc.
@@ -55,7 +55,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dmover_io.c,v 1.33 2009/04/11 15:47:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dmover_io.c,v 1.34 2009/04/11 23:05:26 christos Exp $");
#include <sys/param.h>
#include <sys/queue.h>
@@ -585,6 +585,8 @@
st->st_atime = ds->ds_atime;
st->st_mtime = ds->ds_mtime;
st->st_ctime = st->st_birthtime = ds->ds_btime;
+ st->st_uid = kauth_cred_geteuid(fp->f_cred);
+ st->st_gid = kauth_cred_getegid(fp->f_cred);
KERNEL_UNLOCK(NULL);
return 0;
}
Index: src/sys/dev/putter/putter.c
diff -u src/sys/dev/putter/putter.c:1.22 src/sys/dev/putter/putter.c:1.23
--- src/sys/dev/putter/putter.c:1.22 Sat Apr 11 11:47:33 2009
+++ src/sys/dev/putter/putter.c Sat Apr 11 19:05:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: putter.c,v 1.22 2009/04/11 15:47:33 christos Exp $ */
+/* $NetBSD: putter.c,v 1.23 2009/04/11 23:05:26 christos Exp $ */
/*
* Copyright (c) 2006, 2007 Antti Kantee. All Rights Reserved.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: putter.c,v 1.22 2009/04/11 15:47:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: putter.c,v 1.23 2009/04/11 23:05:26 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -47,6 +47,7 @@
#include <sys/stat.h>
#include <sys/socketvar.h>
#include <sys/module.h>
+#include <sys/kauth.h>
#include <dev/putter/putter_sys.h>
@@ -216,8 +217,8 @@
size_t origres, moved;
int error;
- getnanotime(&pi->pi_atime);
KERNEL_LOCK(1, NULL);
+ getnanotime(&pi->pi_atime);
if (pi->pi_private == PUTTER_EMBRYO || pi->pi_private == PUTTER_DEAD) {
printf("putter_fop_read: private %d not inited\n", pi->pi_idx);
@@ -265,8 +266,8 @@
size_t frsize;
int error;
- getnanotime(&pi->pi_mtime);
KERNEL_LOCK(1, NULL);
+ getnanotime(&pi->pi_mtime);
DPRINTF(("putter_fop_write (%p): writing response, resid %zu\n",
pi->pi_private, uio->uio_resid));
@@ -416,6 +417,8 @@
st->st_atimespec = pi->pi_atime;
st->st_mtimespec = pi->pi_mtime;
st->st_ctimespec = st->st_birthtimespec = pi->pi_btime;
+ st->st_uid = kauth_cred_geteuid(fp->f_cred);
+ st->st_gid = kauth_cred_getegid(fp->f_cred);
KERNEL_UNLOCK_ONE(NULL);
return 0;
}
Index: src/sys/kern/kern_drvctl.c
diff -u src/sys/kern/kern_drvctl.c:1.25 src/sys/kern/kern_drvctl.c:1.26
--- src/sys/kern/kern_drvctl.c:1.25 Sat Apr 11 11:47:33 2009
+++ src/sys/kern/kern_drvctl.c Sat Apr 11 19:05:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_drvctl.c,v 1.25 2009/04/11 15:47:33 christos Exp $ */
+/* $NetBSD: kern_drvctl.c,v 1.26 2009/04/11 23:05:26 christos Exp $ */
/*
* Copyright (c) 2004
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.25 2009/04/11 15:47:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.26 2009/04/11 23:05:26 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -45,6 +45,7 @@
#include <sys/drvctlio.h>
#include <sys/devmon.h>
#include <sys/stat.h>
+#include <sys/kauth.h>
struct drvctl_event {
TAILQ_ENTRY(drvctl_event) dce_link;
@@ -375,6 +376,8 @@
drvctl_stat(struct file *fp, struct stat *st)
{
(void)memset(st, 0, sizeof(*st));
+ st->st_uid = kauth_cred_geteuid(fp->f_cred);
+ st->st_gid = kauth_cred_getegid(fp->f_cred);
return 0;
}
Index: src/sys/kern/sys_mqueue.c
diff -u src/sys/kern/sys_mqueue.c:1.15 src/sys/kern/sys_mqueue.c:1.16
--- src/sys/kern/sys_mqueue.c:1.15 Sat Apr 11 11:47:33 2009
+++ src/sys/kern/sys_mqueue.c Sat Apr 11 19:05:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_mqueue.c,v 1.15 2009/04/11 15:47:33 christos Exp $ */
+/* $NetBSD: sys_mqueue.c,v 1.16 2009/04/11 23:05:26 christos Exp $ */
/*
* Copyright (c) 2007, 2008 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.15 2009/04/11 15:47:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.16 2009/04/11 23:05:26 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -246,14 +246,18 @@
struct mqueue *mq = fp->f_data;
(void)memset(st, 0, sizeof(*st));
- KERNEL_LOCK(1, NULL);
+
+ mutex_enter(&mq->mq_mtx);
st->st_mode = mq->mq_mode;
st->st_uid = mq->mq_euid;
st->st_gid = mq->mq_egid;
st->st_atimespec = mq->mq_atime;
st->st_mtimespec = mq->mq_mtime;
st->st_ctimespec = st->st_birthtimespec = mq->mq_btime;
- KERNEL_UNLOCK_ONE(NULL);
+ st->st_uid = kauth_cred_geteuid(fp->f_cred);
+ st->st_gid = kauth_cred_getegid(fp->f_cred);
+ mutex_exit(&mq->mq_mtx);
+
return 0;
}
Index: src/sys/kern/sys_pipe.c
diff -u src/sys/kern/sys_pipe.c:1.111 src/sys/kern/sys_pipe.c:1.112
--- src/sys/kern/sys_pipe.c:1.111 Sat Apr 11 11:46:18 2009
+++ src/sys/kern/sys_pipe.c Sat Apr 11 19:05:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_pipe.c,v 1.111 2009/04/11 15:46:18 christos Exp $ */
+/* $NetBSD: sys_pipe.c,v 1.112 2009/04/11 23:05:26 christos Exp $ */
/*-
* Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.111 2009/04/11 15:46:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.112 2009/04/11 23:05:26 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1185,6 +1185,7 @@
{
struct pipe *pipe = fp->f_data;
+ mutex_enter(pipe->pipe_lock);
memset(ub, 0, sizeof(*ub));
ub->st_mode = S_IFIFO | S_IRUSR | S_IWUSR;
ub->st_blksize = pipe->pipe_buffer.size;
@@ -1202,7 +1203,8 @@
* Left as 0: st_dev, st_ino, st_nlink, st_rdev, st_flags, st_gen.
* XXX (st_dev, st_ino) should be unique.
*/
- return (0);
+ mutex_exit(pipe->pipe_lock);
+ return 0;
}
/* ARGSUSED */
Index: src/sys/kern/vfs_vnops.c
diff -u src/sys/kern/vfs_vnops.c:1.164 src/sys/kern/vfs_vnops.c:1.165
--- src/sys/kern/vfs_vnops.c:1.164 Sat Apr 4 06:12:51 2009
+++ src/sys/kern/vfs_vnops.c Sat Apr 11 19:05:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_vnops.c,v 1.164 2009/04/04 10:12:51 ad Exp $ */
+/* $NetBSD: vfs_vnops.c,v 1.165 2009/04/11 23:05:26 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.164 2009/04/04 10:12:51 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.165 2009/04/11 23:05:26 christos Exp $");
#include "veriexec.h"
@@ -544,9 +544,13 @@
static int
vn_statfile(file_t *fp, struct stat *sb)
{
- struct vnode *vp = (struct vnode *)fp->f_data;
+ struct vnode *vp = fp->f_data;
+ int error;
- return vn_stat(vp, sb);
+ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+ error = vn_stat(vp, sb);
+ VOP_UNLOCK(vp, 0);
+ return error;
}
int
Index: src/sys/net/bpf.c
diff -u src/sys/net/bpf.c:1.145 src/sys/net/bpf.c:1.146
--- src/sys/net/bpf.c:1.145 Sat Apr 11 11:47:33 2009
+++ src/sys/net/bpf.c Sat Apr 11 19:05:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf.c,v 1.145 2009/04/11 15:47:33 christos Exp $ */
+/* $NetBSD: bpf.c,v 1.146 2009/04/11 23:05:26 christos Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.145 2009/04/11 15:47:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.146 2009/04/11 23:05:26 christos Exp $");
#if defined(_KERNEL_OPT)
#include "opt_bpf.h"
@@ -1137,6 +1137,8 @@
st->st_atimespec = d->bd_atime;
st->st_mtimespec = d->bd_mtime;
st->st_ctimespec = st->st_birthtimespec = d->bd_btime;
+ st->st_uid = kauth_cred_geteuid(fp->f_cred);
+ st->st_gid = kauth_cred_getegid(fp->f_cred);
KERNEL_UNLOCK_ONE(NULL);
return 0;
}
Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.56 src/sys/net/if_tap.c:1.57
--- src/sys/net/if_tap.c:1.56 Sat Apr 11 11:47:33 2009
+++ src/sys/net/if_tap.c Sat Apr 11 19:05:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: if_tap.c,v 1.56 2009/04/11 15:47:33 christos Exp $ */
+/* $NetBSD: if_tap.c,v 1.57 2009/04/11 23:05:26 christos Exp $ */
/*
* Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.56 2009/04/11 15:47:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.57 2009/04/11 23:05:26 christos Exp $");
#if defined(_KERNEL_OPT)
#include "bpfilter.h"
@@ -139,7 +139,6 @@
static int tap_dev_write(int, struct uio *, int);
static int tap_dev_ioctl(int, u_long, void *, struct lwp *);
static int tap_dev_poll(int, int, struct lwp *);
-static int tap_dev_stat(int , struct stat *);
static int tap_dev_kqfilter(int, struct knote *);
/* Fileops access routines */
@@ -979,27 +978,27 @@
tap_fops_stat(file_t *fp, struct stat *st)
{
int error;
- KERNEL_LOCK(1, NULL);
- error = tap_dev_stat((intptr_t)fp->f_data, st);
- KERNEL_UNLOCK_ONE(NULL);
- return error;
-}
-
-static int
-tap_dev_stat(int unit, struct stat *st)
-{
- struct tap_softc *sc =
- device_lookup_private(&tap_cd, unit);
-
- if (sc == NULL)
- return ENXIO;
+ struct tap_softc *sc;
+ int unit = (uintptr_t)fp->f_data;
(void)memset(st, 0, sizeof(*st));
+
+ KERNEL_LOCK(1, NULL);
+ sc = device_lookup_private(&tap_cd, unit);
+ if (sc == NULL) {
+ error = ENXIO;
+ goto out;
+ }
+
st->st_dev = makedev(cdevsw_lookup_major(&tap_cdevsw), unit);
st->st_atimespec = sc->sc_atime;
st->st_mtimespec = sc->sc_mtime;
st->st_ctimespec = st->st_birthtimespec = sc->sc_btime;
- return 0;
+ st->st_uid = kauth_cred_geteuid(fp->f_cred);
+ st->st_gid = kauth_cred_getegid(fp->f_cred);
+out:
+ KERNEL_UNLOCK_ONE(NULL);
+ return error;
}
static int
Index: src/sys/opencrypto/cryptodev.c
diff -u src/sys/opencrypto/cryptodev.c:1.48 src/sys/opencrypto/cryptodev.c:1.49
--- src/sys/opencrypto/cryptodev.c:1.48 Sat Apr 11 11:47:34 2009
+++ src/sys/opencrypto/cryptodev.c Sat Apr 11 19:05:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: cryptodev.c,v 1.48 2009/04/11 15:47:34 christos Exp $ */
+/* $NetBSD: cryptodev.c,v 1.49 2009/04/11 23:05:26 christos Exp $ */
/* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */
/* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.48 2009/04/11 15:47:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.49 2009/04/11 23:05:26 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -233,7 +233,9 @@
struct fcrypt *criofcr;
int criofd;
+ mutex_spin_enter(&crypto_mtx);
getnanotime(&fcr->atime);
+ mutex_spin_exit(&crypto_mtx);
switch (cmd) {
case CRIOGET: /* XXX deprecated, remove after 5.0 */
@@ -272,7 +274,9 @@
goto mbail;
}
+ mutex_spin_enter(&crypto_mtx);
fcr->mtime = fcr->atime;
+ mutex_spin_exit(&crypto_mtx);
error = cryptodev_msession(fcr, snop, sgop->count);
if (error) {
goto mbail;
@@ -284,8 +288,8 @@
kmem_free(snop, sgop->count * sizeof(struct session_n_op));
break;
case CIOCFSESSION:
- fcr->mtime = fcr->atime;
mutex_spin_enter(&crypto_mtx);
+ fcr->mtime = fcr->atime;
ses = *(u_int32_t *)data;
cse = csefind(fcr, ses);
if (cse == NULL)
@@ -295,7 +299,9 @@
mutex_spin_exit(&crypto_mtx);
break;
case CIOCNFSESSION:
+ mutex_spin_enter(&crypto_mtx);
fcr->mtime = fcr->atime;
+ mutex_spin_exit(&crypto_mtx);
sfop = (struct crypt_sfop *)data;
sesid = kmem_alloc((sfop->count * sizeof(u_int32_t)),
KM_SLEEP);
@@ -307,8 +313,8 @@
kmem_free(sesid, (sfop->count * sizeof(u_int32_t)));
break;
case CIOCCRYPT:
- fcr->mtime = fcr->atime;
mutex_spin_enter(&crypto_mtx);
+ fcr->mtime = fcr->atime;
cop = (struct crypt_op *)data;
cse = csefind(fcr, cop->ses);
mutex_spin_exit(&crypto_mtx);
@@ -320,7 +326,9 @@
DPRINTF(("cryptodev_op error = %d\n", error));
break;
case CIOCNCRYPTM:
+ mutex_spin_enter(&crypto_mtx);
fcr->mtime = fcr->atime;
+ mutex_spin_exit(&crypto_mtx);
mop = (struct crypt_mop *)data;
cnop = kmem_alloc((mop->count * sizeof(struct crypt_n_op)),
KM_SLEEP);
@@ -340,7 +348,9 @@
DPRINTF(("cryptodev_key error = %d\n", error));
break;
case CIOCNFKEYM:
+ mutex_spin_enter(&crypto_mtx);
fcr->mtime = fcr->atime;
+ mutex_spin_exit(&crypto_mtx);
mkop = (struct crypt_mkop *)data;
knop = kmem_alloc((mkop->count * sizeof(struct crypt_n_kop)),
KM_SLEEP);
@@ -358,7 +368,9 @@
error = crypto_getfeat((int *)data);
break;
case CIOCNCRYPTRETM:
+ mutex_spin_enter(&crypto_mtx);
fcr->mtime = fcr->atime;
+ mutex_spin_exit(&crypto_mtx);
crypt_ret = (struct cryptret *)data;
count = crypt_ret->count;
crypt_res = kmem_alloc((count * sizeof(struct crypt_result)),
@@ -1960,12 +1972,16 @@
struct fcrypt *fcr = fp->f_data;
(void)memset(st, 0, sizeof(st));
- KERNEL_LOCK(1, NULL);
+
+ mutex_spin_enter(&crypto_mtx);
st->st_dev = makedev(cdevsw_lookup_major(&crypto_cdevsw), fcr->sesn);
st->st_atimespec = fcr->atime;
st->st_mtimespec = fcr->mtime;
st->st_ctimespec = st->st_birthtimespec = fcr->btime;
- KERNEL_UNLOCK_ONE(NULL);
+ st->st_uid = kauth_cred_geteuid(fp->f_cred);
+ st->st_gid = kauth_cred_getegid(fp->f_cred);
+ mutex_spin_exit(&crypto_mtx);
+
return 0;
}