Fix locking as Andy explained. Also fill in uid and gid like sys_pipe did.
This commit is contained in:
parent
135645196a
commit
86ba58fd64
|
@ -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 @@ dmio_stat(struct file *fp, struct stat *st)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: putter.c,v 1.22 2009/04/11 15:47:33 christos Exp $")
|
|||
#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 @@ putter_fop_read(file_t *fp, off_t *off, struct uio *uio,
|
|||
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 @@ putter_fop_write(file_t *fp, off_t *off, struct uio *uio,
|
|||
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 @@ putter_fop_stat(file_t *fp, struct stat *st)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.25 2009/04/11 15:47:33 christos Ex
|
|||
#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 @@ static int
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ mq_stat_fop(file_t *fp, struct stat *st)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ pipe_stat(struct file *fp, struct stat *ub)
|
|||
{
|
||||
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 @@ pipe_stat(struct file *fp, struct stat *ub)
|
|||
* 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 */
|
||||
|
|
|
@ -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 @@ vn_write(file_t *fp, off_t *offset, struct uio *uio, kauth_cred_t cred,
|
|||
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
|
||||
|
|
|
@ -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 @@ bpf_stat(struct file *fp, struct stat *st)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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_read(int, struct uio *, int);
|
|||
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 @@ static int
|
|||
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
|
||||
|
|
|
@ -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 @@ cryptof_ioctl(struct file *fp, u_long cmd, void *data)
|
|||
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 @@ cryptof_ioctl(struct file *fp, u_long cmd, void *data)
|
|||
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 @@ mbail:
|
|||
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 @@ mbail:
|
|||
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 @@ mbail:
|
|||
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 @@ mbail:
|
|||
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 @@ mbail:
|
|||
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 @@ mbail:
|
|||
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 @@ cryptof_stat(struct file *fp, struct stat *st)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue