2008-05-05 21:11:16 +04:00
|
|
|
/* $NetBSD: kern_fileassoc.c,v 1.31 2008/05/05 17:11:17 ad Exp $ */
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2006 Elad Efrat <elad@NetBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2007-01-09 15:49:36 +03:00
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2006-08-13 10:21:10 +04:00
|
|
|
#include <sys/cdefs.h>
|
2008-05-05 21:11:16 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: kern_fileassoc.c,v 1.31 2008/05/05 17:11:17 ad Exp $");
|
2006-12-08 16:23:22 +03:00
|
|
|
|
|
|
|
#include "opt_fileassoc.h"
|
2006-08-13 10:21:10 +04:00
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/exec.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/inttypes.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/fileassoc.h>
|
2006-12-11 18:24:27 +03:00
|
|
|
#include <sys/specificdata.h>
|
2006-07-16 23:37:55 +04:00
|
|
|
#include <sys/hash.h>
|
2006-09-06 17:37:49 +04:00
|
|
|
#include <sys/fstypes.h>
|
2006-12-11 18:24:27 +03:00
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/once.h>
|
2006-12-08 16:23:22 +03:00
|
|
|
|
2007-02-06 04:09:48 +03:00
|
|
|
#define FILEASSOC_INITIAL_TABLESIZE 128
|
|
|
|
|
2006-09-06 17:37:49 +04:00
|
|
|
static struct fileassoc_hash_entry *
|
|
|
|
fileassoc_file_lookup(struct vnode *, fhandle_t *);
|
|
|
|
static struct fileassoc_hash_entry *
|
|
|
|
fileassoc_file_add(struct vnode *, fhandle_t *);
|
2007-02-06 04:09:48 +03:00
|
|
|
static struct fileassoc_table *fileassoc_table_resize(struct fileassoc_table *);
|
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
static specificdata_domain_t fileassoc_domain;
|
2006-12-14 12:24:54 +03:00
|
|
|
static specificdata_key_t fileassoc_mountspecific_key;
|
2007-03-09 08:51:50 +03:00
|
|
|
static ONCE_DECL(control);
|
2006-12-11 18:24:27 +03:00
|
|
|
|
2006-07-16 23:37:55 +04:00
|
|
|
/*
|
|
|
|
* Hook entry.
|
|
|
|
* Includes the hook name for identification and private hook clear callback.
|
|
|
|
*/
|
2006-12-11 18:24:27 +03:00
|
|
|
struct fileassoc {
|
|
|
|
LIST_ENTRY(fileassoc) list;
|
|
|
|
const char *name; /* name. */
|
|
|
|
fileassoc_cleanup_cb_t cleanup_cb; /* clear callback. */
|
|
|
|
specificdata_key_t key;
|
2006-07-16 23:37:55 +04:00
|
|
|
};
|
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
static LIST_HEAD(, fileassoc) fileassoc_list;
|
|
|
|
|
2007-01-25 16:57:28 +03:00
|
|
|
/* An entry in the per-mount hash table. */
|
2006-07-16 23:37:55 +04:00
|
|
|
struct fileassoc_hash_entry {
|
2006-09-06 17:37:49 +04:00
|
|
|
fhandle_t *handle; /* File handle */
|
2006-12-11 18:24:27 +03:00
|
|
|
specificdata_reference data; /* Hooks. */
|
2007-02-07 12:38:04 +03:00
|
|
|
u_int nassocs; /* # of hooks. */
|
2006-07-16 23:37:55 +04:00
|
|
|
LIST_ENTRY(fileassoc_hash_entry) entries; /* List pointer. */
|
|
|
|
};
|
|
|
|
|
|
|
|
LIST_HEAD(fileassoc_hashhead, fileassoc_hash_entry);
|
|
|
|
|
|
|
|
struct fileassoc_table {
|
|
|
|
struct fileassoc_hashhead *hash_tbl;
|
|
|
|
size_t hash_size; /* Number of slots. */
|
|
|
|
u_long hash_mask;
|
2007-02-06 04:09:48 +03:00
|
|
|
size_t hash_used; /* # of used slots. */
|
2006-12-11 18:24:27 +03:00
|
|
|
specificdata_reference data;
|
2006-07-16 23:37:55 +04:00
|
|
|
};
|
2006-08-20 14:38:23 +04:00
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
/*
|
2006-09-06 17:37:49 +04:00
|
|
|
* Hashing function: Takes a number modulus the mask to give back an
|
|
|
|
* index into the hash table.
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
*/
|
2006-09-06 17:37:49 +04:00
|
|
|
#define FILEASSOC_HASH(tbl, handle) \
|
2006-09-08 17:57:38 +04:00
|
|
|
(hash32_buf((handle), FHANDLE_SIZE(handle), HASH32_BUF_INIT) \
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
& ((tbl)->hash_mask))
|
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
static void *
|
|
|
|
file_getdata(struct fileassoc_hash_entry *e, const struct fileassoc *assoc)
|
|
|
|
{
|
|
|
|
|
|
|
|
return specificdata_getspecific(fileassoc_domain, &e->data,
|
|
|
|
assoc->key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_setdata(struct fileassoc_hash_entry *e, const struct fileassoc *assoc,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
|
|
|
|
specificdata_setspecific(fileassoc_domain, &e->data, assoc->key,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_cleanup(struct fileassoc_hash_entry *e, const struct fileassoc *assoc)
|
|
|
|
{
|
|
|
|
fileassoc_cleanup_cb_t cb;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
cb = assoc->cleanup_cb;
|
|
|
|
if (cb == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data = file_getdata(e, assoc);
|
2006-12-23 11:35:43 +03:00
|
|
|
(*cb)(data);
|
2006-12-11 18:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_free(struct fileassoc_hash_entry *e)
|
|
|
|
{
|
|
|
|
struct fileassoc *assoc;
|
|
|
|
|
|
|
|
LIST_REMOVE(e, entries);
|
|
|
|
|
|
|
|
LIST_FOREACH(assoc, &fileassoc_list, list) {
|
|
|
|
file_cleanup(e, assoc);
|
|
|
|
}
|
|
|
|
vfs_composefh_free(e->handle);
|
|
|
|
specificdata_fini(fileassoc_domain, &e->data);
|
|
|
|
kmem_free(e, sizeof(*e));
|
|
|
|
}
|
|
|
|
|
2006-12-14 12:24:54 +03:00
|
|
|
static void
|
|
|
|
table_dtor(void *vp)
|
|
|
|
{
|
|
|
|
struct fileassoc_table *tbl = vp;
|
|
|
|
struct fileassoc_hashhead *hh;
|
|
|
|
u_long i;
|
|
|
|
|
|
|
|
/* Remove all entries from the table and lists */
|
|
|
|
hh = tbl->hash_tbl;
|
|
|
|
for (i = 0; i < tbl->hash_size; i++) {
|
|
|
|
struct fileassoc_hash_entry *mhe;
|
|
|
|
|
|
|
|
while ((mhe = LIST_FIRST(&hh[i])) != NULL) {
|
|
|
|
file_free(mhe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove hash table and sysctl node */
|
2008-05-05 21:11:16 +04:00
|
|
|
hashdone(tbl->hash_tbl, HASH_LIST, tbl->hash_mask);
|
2006-12-14 12:24:54 +03:00
|
|
|
specificdata_fini(fileassoc_domain, &tbl->data);
|
|
|
|
kmem_free(tbl, sizeof(*tbl));
|
|
|
|
}
|
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
/*
|
|
|
|
* Initialize the fileassoc subsystem.
|
|
|
|
*/
|
2006-12-11 18:24:27 +03:00
|
|
|
static int
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
fileassoc_init(void)
|
|
|
|
{
|
2006-12-14 12:24:54 +03:00
|
|
|
int error;
|
2006-12-11 18:24:27 +03:00
|
|
|
|
2006-12-14 12:24:54 +03:00
|
|
|
error = mount_specific_key_create(&fileassoc_mountspecific_key,
|
|
|
|
table_dtor);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2006-12-11 18:24:27 +03:00
|
|
|
fileassoc_domain = specificdata_domain_create();
|
|
|
|
|
|
|
|
return 0;
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a new hook.
|
|
|
|
*/
|
2006-12-11 18:24:27 +03:00
|
|
|
int
|
|
|
|
fileassoc_register(const char *name, fileassoc_cleanup_cb_t cleanup_cb,
|
|
|
|
fileassoc_t *result)
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
{
|
2006-12-11 18:24:27 +03:00
|
|
|
int error;
|
|
|
|
specificdata_key_t key;
|
|
|
|
struct fileassoc *assoc;
|
|
|
|
|
2006-12-14 12:24:54 +03:00
|
|
|
error = RUN_ONCE(&control, fileassoc_init);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2006-12-11 18:24:27 +03:00
|
|
|
error = specificdata_key_create(fileassoc_domain, &key, NULL);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
assoc = kmem_alloc(sizeof(*assoc), KM_SLEEP);
|
|
|
|
assoc->name = name;
|
|
|
|
assoc->cleanup_cb = cleanup_cb;
|
|
|
|
assoc->key = key;
|
|
|
|
LIST_INSERT_HEAD(&fileassoc_list, assoc, list);
|
|
|
|
*result = assoc;
|
|
|
|
|
|
|
|
return 0;
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deregister a hook.
|
|
|
|
*/
|
|
|
|
int
|
2006-12-11 18:24:27 +03:00
|
|
|
fileassoc_deregister(fileassoc_t assoc)
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
{
|
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
LIST_REMOVE(assoc, list);
|
2007-01-26 15:36:46 +03:00
|
|
|
specificdata_key_delete(fileassoc_domain, assoc->key);
|
2006-12-11 18:24:27 +03:00
|
|
|
kmem_free(assoc, sizeof(*assoc));
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
return 0;
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the hash table for the specified device.
|
|
|
|
*/
|
2006-07-16 23:37:55 +04:00
|
|
|
static struct fileassoc_table *
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
fileassoc_table_lookup(struct mount *mp)
|
|
|
|
{
|
2007-03-09 08:51:50 +03:00
|
|
|
int error;
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2007-03-09 08:51:50 +03:00
|
|
|
error = RUN_ONCE(&control, fileassoc_init);
|
|
|
|
if (error) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-12-14 12:24:54 +03:00
|
|
|
return mount_getspecific(mp, fileassoc_mountspecific_key);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-08-20 14:38:23 +04:00
|
|
|
* Perform a lookup on a hash table. If hint is non-zero then use the value
|
|
|
|
* of the hint as the identifier instead of performing a lookup for the
|
|
|
|
* fileid.
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
*/
|
2006-07-16 23:37:55 +04:00
|
|
|
static struct fileassoc_hash_entry *
|
2006-09-06 17:37:49 +04:00
|
|
|
fileassoc_file_lookup(struct vnode *vp, fhandle_t *hint)
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
{
|
|
|
|
struct fileassoc_table *tbl;
|
|
|
|
struct fileassoc_hashhead *tble;
|
|
|
|
struct fileassoc_hash_entry *e;
|
|
|
|
size_t indx;
|
2006-09-06 17:37:49 +04:00
|
|
|
fhandle_t *th;
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
int error;
|
|
|
|
|
2006-12-14 12:24:54 +03:00
|
|
|
tbl = fileassoc_table_lookup(vp->v_mount);
|
|
|
|
if (tbl == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-06 17:37:49 +04:00
|
|
|
if (hint == NULL) {
|
|
|
|
error = vfs_composefh_alloc(vp, &th);
|
2006-08-20 14:38:23 +04:00
|
|
|
if (error)
|
|
|
|
return (NULL);
|
2006-12-14 12:24:54 +03:00
|
|
|
} else {
|
2006-08-20 14:38:23 +04:00
|
|
|
th = hint;
|
2006-09-08 17:57:38 +04:00
|
|
|
}
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-08-20 14:38:23 +04:00
|
|
|
indx = FILEASSOC_HASH(tbl, th);
|
2006-09-06 17:37:49 +04:00
|
|
|
tble = &(tbl->hash_tbl[indx]);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
|
|
|
LIST_FOREACH(e, tble, entries) {
|
2006-12-14 12:24:54 +03:00
|
|
|
if (((FHANDLE_FILEID(e->handle)->fid_len ==
|
2006-09-08 17:57:38 +04:00
|
|
|
FHANDLE_FILEID(th)->fid_len)) &&
|
2006-09-06 17:37:49 +04:00
|
|
|
(memcmp(FHANDLE_FILEID(e->handle), FHANDLE_FILEID(th),
|
2006-10-28 02:17:09 +04:00
|
|
|
(FHANDLE_FILEID(th))->fid_len) == 0)) {
|
2006-12-14 12:24:54 +03:00
|
|
|
break;
|
2006-10-28 02:17:09 +04:00
|
|
|
}
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
}
|
|
|
|
|
2006-09-08 17:57:38 +04:00
|
|
|
if (hint == NULL)
|
|
|
|
vfs_composefh_free(th);
|
|
|
|
|
2006-12-14 12:24:54 +03:00
|
|
|
return e;
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return hook data associated with a vnode.
|
|
|
|
*/
|
|
|
|
void *
|
2006-12-11 18:24:27 +03:00
|
|
|
fileassoc_lookup(struct vnode *vp, fileassoc_t assoc)
|
2006-08-20 14:38:23 +04:00
|
|
|
{
|
2006-09-06 17:37:49 +04:00
|
|
|
struct fileassoc_hash_entry *mhe;
|
2006-08-20 14:38:23 +04:00
|
|
|
|
2006-09-06 17:37:49 +04:00
|
|
|
mhe = fileassoc_file_lookup(vp, NULL);
|
|
|
|
if (mhe == NULL)
|
|
|
|
return (NULL);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
return file_getdata(mhe, assoc);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
}
|
|
|
|
|
2007-02-06 04:09:48 +03:00
|
|
|
static struct fileassoc_table *
|
|
|
|
fileassoc_table_resize(struct fileassoc_table *tbl)
|
|
|
|
{
|
|
|
|
struct fileassoc_table *newtbl;
|
|
|
|
struct fileassoc_hashhead *hh;
|
|
|
|
u_long i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new table. Like the condition in fileassoc_file_add(),
|
|
|
|
* this is also temporary -- just double the number of slots.
|
|
|
|
*/
|
|
|
|
newtbl = kmem_zalloc(sizeof(*newtbl), KM_SLEEP);
|
|
|
|
newtbl->hash_size = (tbl->hash_size * 2);
|
|
|
|
if (newtbl->hash_size < tbl->hash_size)
|
|
|
|
newtbl->hash_size = tbl->hash_size;
|
2008-05-05 21:11:16 +04:00
|
|
|
newtbl->hash_tbl = hashinit(newtbl->hash_size, HASH_LIST,
|
|
|
|
true, &newtbl->hash_mask);
|
2007-02-06 04:09:48 +03:00
|
|
|
newtbl->hash_used = 0;
|
|
|
|
specificdata_init(fileassoc_domain, &newtbl->data);
|
|
|
|
|
|
|
|
/* XXX we need to make sure nothing uses fileassoc here! */
|
|
|
|
|
|
|
|
hh = tbl->hash_tbl;
|
|
|
|
for (i = 0; i < tbl->hash_size; i++) {
|
|
|
|
struct fileassoc_hash_entry *mhe;
|
|
|
|
|
|
|
|
while ((mhe = LIST_FIRST(&hh[i])) != NULL) {
|
|
|
|
struct fileassoc_hashhead *vhh;
|
|
|
|
size_t indx;
|
|
|
|
|
|
|
|
LIST_REMOVE(mhe, entries);
|
|
|
|
|
|
|
|
indx = FILEASSOC_HASH(newtbl, mhe->handle);
|
|
|
|
vhh = &(newtbl->hash_tbl[indx]);
|
|
|
|
|
|
|
|
LIST_INSERT_HEAD(vhh, mhe, entries);
|
|
|
|
|
|
|
|
newtbl->hash_used++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tbl->hash_used != newtbl->hash_used)
|
|
|
|
panic("fileassoc_table_resize: inconsistency detected! "
|
|
|
|
"needed %zu entries, got %zu", tbl->hash_used,
|
|
|
|
newtbl->hash_used);
|
|
|
|
|
2008-05-05 21:11:16 +04:00
|
|
|
hashdone(tbl->hash_tbl, HASH_LIST, tbl->hash_mask);
|
2007-02-06 04:09:48 +03:00
|
|
|
specificdata_fini(fileassoc_domain, &tbl->data);
|
|
|
|
kmem_free(tbl, sizeof(*tbl));
|
|
|
|
|
|
|
|
return (newtbl);
|
|
|
|
}
|
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
/*
|
|
|
|
* Create a new fileassoc table.
|
|
|
|
*/
|
2007-02-07 12:38:04 +03:00
|
|
|
static struct fileassoc_table *
|
2007-02-06 04:09:48 +03:00
|
|
|
fileassoc_table_add(struct mount *mp)
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
{
|
|
|
|
struct fileassoc_table *tbl;
|
|
|
|
|
|
|
|
/* Check for existing table for device. */
|
2007-02-07 12:38:04 +03:00
|
|
|
tbl = fileassoc_table_lookup(mp);
|
|
|
|
if (tbl != NULL)
|
|
|
|
return (tbl);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-12-26 11:55:32 +03:00
|
|
|
/* Allocate and initialize a table. */
|
2006-12-11 18:24:27 +03:00
|
|
|
tbl = kmem_zalloc(sizeof(*tbl), KM_SLEEP);
|
2007-02-06 04:09:48 +03:00
|
|
|
tbl->hash_size = FILEASSOC_INITIAL_TABLESIZE;
|
2008-05-05 21:11:16 +04:00
|
|
|
tbl->hash_tbl = hashinit(tbl->hash_size, HASH_LIST, true,
|
|
|
|
&tbl->hash_mask);
|
2007-02-06 04:09:48 +03:00
|
|
|
tbl->hash_used = 0;
|
2006-12-11 18:24:27 +03:00
|
|
|
specificdata_init(fileassoc_domain, &tbl->data);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-12-14 12:24:54 +03:00
|
|
|
mount_setspecific(mp, fileassoc_mountspecific_key, tbl);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2007-02-07 12:38:04 +03:00
|
|
|
return (tbl);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a table.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fileassoc_table_delete(struct mount *mp)
|
|
|
|
{
|
|
|
|
struct fileassoc_table *tbl;
|
|
|
|
|
|
|
|
tbl = fileassoc_table_lookup(mp);
|
|
|
|
if (tbl == NULL)
|
|
|
|
return (EEXIST);
|
|
|
|
|
2006-12-14 12:24:54 +03:00
|
|
|
mount_setspecific(mp, fileassoc_mountspecific_key, NULL);
|
|
|
|
table_dtor(tbl);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-08-11 23:17:47 +04:00
|
|
|
/*
|
|
|
|
* Run a callback for each hook entry in a table.
|
|
|
|
*/
|
|
|
|
int
|
Some Veriexec stuff that's been rotting in my tree for months.
Bug fixes:
- Fix crash reported by Scott Ellis on current-users@.
- Fix race conditions in enforcing the Veriexec rename and remove
policies. These are NOT security issues.
- Fix memory leak in rename handling when overwriting a monitored
file.
- Fix table deletion logic.
- Don't prevent query requests if not in learning mode.
KPI updates:
- fileassoc_table_run() now takes a cookie to pass to the callback.
- veriexec_table_add() was removed, it is now done internally. As a
result, there's no longer a need for VERIEXEC_TABLESIZE.
- veriexec_report() was removed, it is now internal.
- Perform sanity checks on the entry type, and enforce default type
in veriexec_file_add() rather than in veriexecctl.
- Add veriexec_flush(), used to delete all Veriexec tables, and
veriexec_dump(), used to fill an array with all Veriexec entries.
New features:
- Add a '-k' flag to veriexecctl, to keep the filenames in the kernel
database. This allows Veriexec to produce slightly more accurate
logs under certain circumstances. In the future, this can be either
replaced by vnode->pathname translation, or combined with it.
- Add a VERIEXEC_DUMP ioctl, to dump the entire Veriexec database.
This can be used to recover a database if the file was lost.
Example usage:
# veriexecctl dump > /etc/signatures
Note that only entries with the filename kept (that is, were loaded
with the '-k' flag) will be dumped.
Idea from Brett Lymn.
- Add a VERIEXEC_FLUSH ioctl, to delete all Veriexec entries. Sample
usage:
# veriexecctl flush
- Add a 'veriexec_flags' rc(8) variable, and make its default have
the '-k' flag. On systems using the default signatures file
(generaetd from running 'veriexecgen' with no arguments), this will
use additional 32kb of kernel memory on average.
- Add a '-e' flag to veriexecctl, to evaluate the fingerprint during
load. This is done automatically for files marked as 'untrusted'.
Misc. stuff:
- The code for veriexecctl was massively simplified as a result of
eliminating the need for VERIEXEC_TABLESIZE, and now uses a single
pass of the signatures file, making the loading somewhat faster.
- Lots of minor fixes found using the (still under development)
Veriexec regression testsuite.
- Some of the messages Veriexec prints were improved.
- Various documentation fixes.
All relevant man-pages were updated to reflect the above changes.
Binary compatibility with existing veriexecctl binaries is maintained.
2007-05-15 23:47:43 +04:00
|
|
|
fileassoc_table_run(struct mount *mp, fileassoc_t assoc, fileassoc_cb_t cb,
|
|
|
|
void *cookie)
|
2006-08-11 23:17:47 +04:00
|
|
|
{
|
|
|
|
struct fileassoc_table *tbl;
|
|
|
|
struct fileassoc_hashhead *hh;
|
|
|
|
u_long i;
|
|
|
|
|
|
|
|
tbl = fileassoc_table_lookup(mp);
|
|
|
|
if (tbl == NULL)
|
|
|
|
return (EEXIST);
|
|
|
|
|
|
|
|
hh = tbl->hash_tbl;
|
|
|
|
for (i = 0; i < tbl->hash_size; i++) {
|
|
|
|
struct fileassoc_hash_entry *mhe;
|
|
|
|
|
|
|
|
LIST_FOREACH(mhe, &hh[i], entries) {
|
2006-12-11 18:24:27 +03:00
|
|
|
void *data;
|
|
|
|
|
|
|
|
data = file_getdata(mhe, assoc);
|
|
|
|
if (data != NULL)
|
Some Veriexec stuff that's been rotting in my tree for months.
Bug fixes:
- Fix crash reported by Scott Ellis on current-users@.
- Fix race conditions in enforcing the Veriexec rename and remove
policies. These are NOT security issues.
- Fix memory leak in rename handling when overwriting a monitored
file.
- Fix table deletion logic.
- Don't prevent query requests if not in learning mode.
KPI updates:
- fileassoc_table_run() now takes a cookie to pass to the callback.
- veriexec_table_add() was removed, it is now done internally. As a
result, there's no longer a need for VERIEXEC_TABLESIZE.
- veriexec_report() was removed, it is now internal.
- Perform sanity checks on the entry type, and enforce default type
in veriexec_file_add() rather than in veriexecctl.
- Add veriexec_flush(), used to delete all Veriexec tables, and
veriexec_dump(), used to fill an array with all Veriexec entries.
New features:
- Add a '-k' flag to veriexecctl, to keep the filenames in the kernel
database. This allows Veriexec to produce slightly more accurate
logs under certain circumstances. In the future, this can be either
replaced by vnode->pathname translation, or combined with it.
- Add a VERIEXEC_DUMP ioctl, to dump the entire Veriexec database.
This can be used to recover a database if the file was lost.
Example usage:
# veriexecctl dump > /etc/signatures
Note that only entries with the filename kept (that is, were loaded
with the '-k' flag) will be dumped.
Idea from Brett Lymn.
- Add a VERIEXEC_FLUSH ioctl, to delete all Veriexec entries. Sample
usage:
# veriexecctl flush
- Add a 'veriexec_flags' rc(8) variable, and make its default have
the '-k' flag. On systems using the default signatures file
(generaetd from running 'veriexecgen' with no arguments), this will
use additional 32kb of kernel memory on average.
- Add a '-e' flag to veriexecctl, to evaluate the fingerprint during
load. This is done automatically for files marked as 'untrusted'.
Misc. stuff:
- The code for veriexecctl was massively simplified as a result of
eliminating the need for VERIEXEC_TABLESIZE, and now uses a single
pass of the signatures file, making the loading somewhat faster.
- Lots of minor fixes found using the (still under development)
Veriexec regression testsuite.
- Some of the messages Veriexec prints were improved.
- Various documentation fixes.
All relevant man-pages were updated to reflect the above changes.
Binary compatibility with existing veriexecctl binaries is maintained.
2007-05-15 23:47:43 +04:00
|
|
|
cb(data, cookie);
|
2006-08-11 23:17:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
/*
|
|
|
|
* Clear a table for a given hook.
|
|
|
|
*/
|
|
|
|
int
|
2006-12-11 18:24:27 +03:00
|
|
|
fileassoc_table_clear(struct mount *mp, fileassoc_t assoc)
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
{
|
|
|
|
struct fileassoc_table *tbl;
|
|
|
|
struct fileassoc_hashhead *hh;
|
|
|
|
u_long i;
|
|
|
|
|
|
|
|
tbl = fileassoc_table_lookup(mp);
|
|
|
|
if (tbl == NULL)
|
|
|
|
return (EEXIST);
|
|
|
|
|
|
|
|
hh = tbl->hash_tbl;
|
|
|
|
for (i = 0; i < tbl->hash_size; i++) {
|
|
|
|
struct fileassoc_hash_entry *mhe;
|
|
|
|
|
|
|
|
LIST_FOREACH(mhe, &hh[i], entries) {
|
2006-12-11 18:24:27 +03:00
|
|
|
file_cleanup(mhe, assoc);
|
|
|
|
file_setdata(mhe, assoc, NULL);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a file entry to a table.
|
|
|
|
*/
|
2006-07-16 23:37:55 +04:00
|
|
|
static struct fileassoc_hash_entry *
|
2006-09-06 17:37:49 +04:00
|
|
|
fileassoc_file_add(struct vnode *vp, fhandle_t *hint)
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
{
|
|
|
|
struct fileassoc_table *tbl;
|
|
|
|
struct fileassoc_hashhead *vhh;
|
|
|
|
struct fileassoc_hash_entry *e;
|
|
|
|
size_t indx;
|
2006-09-06 17:37:49 +04:00
|
|
|
fhandle_t *th;
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
int error;
|
|
|
|
|
2006-11-21 00:50:51 +03:00
|
|
|
if (hint == NULL) {
|
2006-09-06 17:37:49 +04:00
|
|
|
error = vfs_composefh_alloc(vp, &th);
|
2006-08-20 14:38:23 +04:00
|
|
|
if (error)
|
|
|
|
return (NULL);
|
|
|
|
} else
|
2006-09-06 17:37:49 +04:00
|
|
|
th = hint;
|
2006-08-20 14:38:23 +04:00
|
|
|
|
2006-09-06 17:37:49 +04:00
|
|
|
e = fileassoc_file_lookup(vp, th);
|
2006-09-08 17:57:38 +04:00
|
|
|
if (e != NULL) {
|
|
|
|
if (hint == NULL)
|
|
|
|
vfs_composefh_free(th);
|
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
return (e);
|
2006-09-08 17:57:38 +04:00
|
|
|
}
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
|
|
|
tbl = fileassoc_table_lookup(vp->v_mount);
|
2006-09-08 17:57:38 +04:00
|
|
|
if (tbl == NULL) {
|
2007-02-07 12:38:04 +03:00
|
|
|
tbl = fileassoc_table_add(vp->v_mount);
|
2006-09-08 17:57:38 +04:00
|
|
|
}
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-09-06 17:37:49 +04:00
|
|
|
indx = FILEASSOC_HASH(tbl, th);
|
|
|
|
vhh = &(tbl->hash_tbl[indx]);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
e = kmem_zalloc(sizeof(*e), KM_SLEEP);
|
2006-09-06 17:37:49 +04:00
|
|
|
e->handle = th;
|
2006-12-11 18:24:27 +03:00
|
|
|
specificdata_init(fileassoc_domain, &e->data);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
LIST_INSERT_HEAD(vhh, e, entries);
|
|
|
|
|
2007-02-06 04:09:48 +03:00
|
|
|
/*
|
|
|
|
* This decides when we need to resize the table. For now,
|
|
|
|
* resize it whenever we "filled" up the number of slots it
|
|
|
|
* has. That's not really true unless of course we had zero
|
|
|
|
* collisions. Think positive! :)
|
|
|
|
*/
|
|
|
|
if (++(tbl->hash_used) == tbl->hash_size) {
|
|
|
|
struct fileassoc_table *newtbl;
|
|
|
|
|
|
|
|
newtbl = fileassoc_table_resize(tbl);
|
|
|
|
mount_setspecific(vp->v_mount, fileassoc_mountspecific_key,
|
|
|
|
newtbl);
|
|
|
|
}
|
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
return (e);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a file entry from a table.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fileassoc_file_delete(struct vnode *vp)
|
|
|
|
{
|
2007-02-07 12:38:04 +03:00
|
|
|
struct fileassoc_table *tbl;
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
struct fileassoc_hash_entry *mhe;
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
KERNEL_LOCK(1, NULL);
|
|
|
|
|
2006-09-06 17:37:49 +04:00
|
|
|
mhe = fileassoc_file_lookup(vp, NULL);
|
2008-01-02 14:48:20 +03:00
|
|
|
if (mhe == NULL) {
|
|
|
|
KERNEL_UNLOCK_ONE(NULL);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
return (ENOENT);
|
2008-01-02 14:48:20 +03:00
|
|
|
}
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
file_free(mhe);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2007-02-07 12:38:04 +03:00
|
|
|
tbl = fileassoc_table_lookup(vp->v_mount);
|
|
|
|
--(tbl->hash_used); /* XXX gc? */
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
KERNEL_UNLOCK_ONE(NULL);
|
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-09-06 17:37:49 +04:00
|
|
|
* Add a hook to a vnode.
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
*/
|
|
|
|
int
|
2006-12-11 18:24:27 +03:00
|
|
|
fileassoc_add(struct vnode *vp, fileassoc_t assoc, void *data)
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
{
|
|
|
|
struct fileassoc_hash_entry *e;
|
2006-12-11 18:24:27 +03:00
|
|
|
void *olddata;
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-09-06 17:37:49 +04:00
|
|
|
e = fileassoc_file_lookup(vp, NULL);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
if (e == NULL) {
|
2006-09-06 17:37:49 +04:00
|
|
|
e = fileassoc_file_add(vp, NULL);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
if (e == NULL)
|
|
|
|
return (ENOTDIR);
|
|
|
|
}
|
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
olddata = file_getdata(e, assoc);
|
|
|
|
if (olddata != NULL)
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
return (EEXIST);
|
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
file_setdata(e, assoc, data);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2007-02-07 12:38:04 +03:00
|
|
|
e->nassocs++;
|
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear a hook from a vnode.
|
|
|
|
*/
|
|
|
|
int
|
2006-12-11 18:24:27 +03:00
|
|
|
fileassoc_clear(struct vnode *vp, fileassoc_t assoc)
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
{
|
|
|
|
struct fileassoc_hash_entry *mhe;
|
|
|
|
|
2006-09-06 17:37:49 +04:00
|
|
|
mhe = fileassoc_file_lookup(vp, NULL);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
if (mhe == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
|
2006-12-11 18:24:27 +03:00
|
|
|
file_cleanup(mhe, assoc);
|
|
|
|
file_setdata(mhe, assoc, NULL);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2007-02-07 12:38:04 +03:00
|
|
|
--(mhe->nassocs); /* XXX gc? */
|
|
|
|
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
return (0);
|
|
|
|
}
|