2005-01-05 22:34:37 +00:00
|
|
|
/*-
|
1999-01-30 06:29:48 +00:00
|
|
|
* Copyright (c) 1998 Mark Newton
|
|
|
|
* Copyright (c) 1994, 1997 Christos Zoulas.
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Christos Zoulas.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-08-12 01:42:21 +00:00
|
|
|
|
2003-06-10 21:44:29 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-01-30 06:29:48 +00:00
|
|
|
#include <sys/param.h>
|
2014-03-16 10:55:57 +00:00
|
|
|
#include <sys/capsicum.h>
|
1999-01-30 06:29:48 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
/*#include <sys/ioctl.h>*/
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
#include <sys/malloc.h>
|
1999-01-30 06:29:48 +00:00
|
|
|
#include <sys/mount.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/namei.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/stat.h>
|
2004-08-24 20:21:21 +00:00
|
|
|
#include <sys/syscallsubr.h>
|
1999-01-30 06:29:48 +00:00
|
|
|
#include <sys/unistd.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/vnode.h>
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
|
2000-08-31 22:54:09 +00:00
|
|
|
#include <compat/svr4/svr4.h>
|
|
|
|
#include <compat/svr4/svr4_types.h>
|
|
|
|
#include <compat/svr4/svr4_signal.h>
|
|
|
|
#include <compat/svr4/svr4_proto.h>
|
|
|
|
#include <compat/svr4/svr4_util.h>
|
|
|
|
#include <compat/svr4/svr4_fcntl.h>
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2006-10-22 11:52:19 +00:00
|
|
|
#include <security/mac/mac_framework.h>
|
|
|
|
|
2002-03-20 05:48:58 +00:00
|
|
|
static int svr4_to_bsd_flags(int);
|
|
|
|
static u_long svr4_to_bsd_cmd(u_long);
|
|
|
|
static int fd_revoke(struct thread *, int);
|
|
|
|
static int fd_truncate(struct thread *, int, struct flock *);
|
|
|
|
static int bsd_to_svr4_flags(int);
|
|
|
|
static void bsd_to_svr4_flock(struct flock *, struct svr4_flock *);
|
|
|
|
static void svr4_to_bsd_flock(struct svr4_flock *, struct flock *);
|
|
|
|
static void bsd_to_svr4_flock64(struct flock *, struct svr4_flock64 *);
|
|
|
|
static void svr4_to_bsd_flock64(struct svr4_flock64 *, struct flock *);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
static u_long
|
|
|
|
svr4_to_bsd_cmd(cmd)
|
|
|
|
u_long cmd;
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case SVR4_F_DUPFD:
|
|
|
|
return F_DUPFD;
|
2008-03-17 18:27:28 +00:00
|
|
|
case SVR4_F_DUP2FD:
|
|
|
|
return F_DUP2FD;
|
1999-01-30 06:29:48 +00:00
|
|
|
case SVR4_F_GETFD:
|
|
|
|
return F_GETFD;
|
|
|
|
case SVR4_F_SETFD:
|
|
|
|
return F_SETFD;
|
|
|
|
case SVR4_F_GETFL:
|
|
|
|
return F_GETFL;
|
|
|
|
case SVR4_F_SETFL:
|
|
|
|
return F_SETFL;
|
|
|
|
case SVR4_F_GETLK:
|
|
|
|
return F_GETLK;
|
|
|
|
case SVR4_F_SETLK:
|
|
|
|
return F_SETLK;
|
|
|
|
case SVR4_F_SETLKW:
|
|
|
|
return F_SETLKW;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
svr4_to_bsd_flags(l)
|
|
|
|
int l;
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
r |= (l & SVR4_O_RDONLY) ? O_RDONLY : 0;
|
|
|
|
r |= (l & SVR4_O_WRONLY) ? O_WRONLY : 0;
|
|
|
|
r |= (l & SVR4_O_RDWR) ? O_RDWR : 0;
|
|
|
|
r |= (l & SVR4_O_NDELAY) ? O_NONBLOCK : 0;
|
|
|
|
r |= (l & SVR4_O_APPEND) ? O_APPEND : 0;
|
|
|
|
r |= (l & SVR4_O_SYNC) ? O_FSYNC : 0;
|
|
|
|
r |= (l & SVR4_O_NONBLOCK) ? O_NONBLOCK : 0;
|
|
|
|
r |= (l & SVR4_O_PRIV) ? O_EXLOCK : 0;
|
|
|
|
r |= (l & SVR4_O_CREAT) ? O_CREAT : 0;
|
|
|
|
r |= (l & SVR4_O_TRUNC) ? O_TRUNC : 0;
|
|
|
|
r |= (l & SVR4_O_EXCL) ? O_EXCL : 0;
|
|
|
|
r |= (l & SVR4_O_NOCTTY) ? O_NOCTTY : 0;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bsd_to_svr4_flags(l)
|
|
|
|
int l;
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
r |= (l & O_RDONLY) ? SVR4_O_RDONLY : 0;
|
|
|
|
r |= (l & O_WRONLY) ? SVR4_O_WRONLY : 0;
|
|
|
|
r |= (l & O_RDWR) ? SVR4_O_RDWR : 0;
|
|
|
|
r |= (l & O_NDELAY) ? SVR4_O_NONBLOCK : 0;
|
|
|
|
r |= (l & O_APPEND) ? SVR4_O_APPEND : 0;
|
|
|
|
r |= (l & O_FSYNC) ? SVR4_O_SYNC : 0;
|
|
|
|
r |= (l & O_NONBLOCK) ? SVR4_O_NONBLOCK : 0;
|
|
|
|
r |= (l & O_EXLOCK) ? SVR4_O_PRIV : 0;
|
|
|
|
r |= (l & O_CREAT) ? SVR4_O_CREAT : 0;
|
|
|
|
r |= (l & O_TRUNC) ? SVR4_O_TRUNC : 0;
|
|
|
|
r |= (l & O_EXCL) ? SVR4_O_EXCL : 0;
|
|
|
|
r |= (l & O_NOCTTY) ? SVR4_O_NOCTTY : 0;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
bsd_to_svr4_flock(iflp, oflp)
|
|
|
|
struct flock *iflp;
|
|
|
|
struct svr4_flock *oflp;
|
|
|
|
{
|
|
|
|
switch (iflp->l_type) {
|
|
|
|
case F_RDLCK:
|
|
|
|
oflp->l_type = SVR4_F_RDLCK;
|
|
|
|
break;
|
|
|
|
case F_WRLCK:
|
|
|
|
oflp->l_type = SVR4_F_WRLCK;
|
|
|
|
break;
|
|
|
|
case F_UNLCK:
|
|
|
|
oflp->l_type = SVR4_F_UNLCK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
oflp->l_type = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
oflp->l_whence = (short) iflp->l_whence;
|
|
|
|
oflp->l_start = (svr4_off_t) iflp->l_start;
|
|
|
|
oflp->l_len = (svr4_off_t) iflp->l_len;
|
|
|
|
oflp->l_sysid = 0;
|
|
|
|
oflp->l_pid = (svr4_pid_t) iflp->l_pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
svr4_to_bsd_flock(iflp, oflp)
|
|
|
|
struct svr4_flock *iflp;
|
|
|
|
struct flock *oflp;
|
|
|
|
{
|
|
|
|
switch (iflp->l_type) {
|
|
|
|
case SVR4_F_RDLCK:
|
|
|
|
oflp->l_type = F_RDLCK;
|
|
|
|
break;
|
|
|
|
case SVR4_F_WRLCK:
|
|
|
|
oflp->l_type = F_WRLCK;
|
|
|
|
break;
|
|
|
|
case SVR4_F_UNLCK:
|
|
|
|
oflp->l_type = F_UNLCK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
oflp->l_type = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
oflp->l_whence = iflp->l_whence;
|
|
|
|
oflp->l_start = (off_t) iflp->l_start;
|
|
|
|
oflp->l_len = (off_t) iflp->l_len;
|
|
|
|
oflp->l_pid = (pid_t) iflp->l_pid;
|
2008-03-26 15:23:12 +00:00
|
|
|
oflp->l_sysid = iflp->l_sysid;
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bsd_to_svr4_flock64(iflp, oflp)
|
|
|
|
struct flock *iflp;
|
|
|
|
struct svr4_flock64 *oflp;
|
|
|
|
{
|
|
|
|
switch (iflp->l_type) {
|
|
|
|
case F_RDLCK:
|
|
|
|
oflp->l_type = SVR4_F_RDLCK;
|
|
|
|
break;
|
|
|
|
case F_WRLCK:
|
|
|
|
oflp->l_type = SVR4_F_WRLCK;
|
|
|
|
break;
|
|
|
|
case F_UNLCK:
|
|
|
|
oflp->l_type = SVR4_F_UNLCK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
oflp->l_type = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
oflp->l_whence = (short) iflp->l_whence;
|
|
|
|
oflp->l_start = (svr4_off64_t) iflp->l_start;
|
|
|
|
oflp->l_len = (svr4_off64_t) iflp->l_len;
|
2008-03-26 15:23:12 +00:00
|
|
|
oflp->l_sysid = iflp->l_sysid;
|
1999-01-30 06:29:48 +00:00
|
|
|
oflp->l_pid = (svr4_pid_t) iflp->l_pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
svr4_to_bsd_flock64(iflp, oflp)
|
|
|
|
struct svr4_flock64 *iflp;
|
|
|
|
struct flock *oflp;
|
|
|
|
{
|
|
|
|
switch (iflp->l_type) {
|
|
|
|
case SVR4_F_RDLCK:
|
|
|
|
oflp->l_type = F_RDLCK;
|
|
|
|
break;
|
|
|
|
case SVR4_F_WRLCK:
|
|
|
|
oflp->l_type = F_WRLCK;
|
|
|
|
break;
|
|
|
|
case SVR4_F_UNLCK:
|
|
|
|
oflp->l_type = F_UNLCK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
oflp->l_type = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
oflp->l_whence = iflp->l_whence;
|
|
|
|
oflp->l_start = (off_t) iflp->l_start;
|
|
|
|
oflp->l_len = (off_t) iflp->l_len;
|
|
|
|
oflp->l_pid = (pid_t) iflp->l_pid;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
fd_revoke(td, fd)
|
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
int fd;
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
2000-07-11 22:07:57 +00:00
|
|
|
struct mount *mp;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct vattr vattr;
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
cap_rights_t rights;
|
1999-01-30 06:29:48 +00:00
|
|
|
int error, *retval;
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
retval = td->td_retval;
|
2011-08-11 12:30:23 +00:00
|
|
|
/*
|
|
|
|
* If we ever want to support Capsicum on SVR4 processes (unlikely)
|
|
|
|
* or FreeBSD grows a native frevoke() (more likely), we will need a
|
Merge Capsicum overhaul:
- Capability is no longer separate descriptor type. Now every descriptor
has set of its own capability rights.
- The cap_new(2) system call is left, but it is no longer documented and
should not be used in new code.
- The new syscall cap_rights_limit(2) should be used instead of
cap_new(2), which limits capability rights of the given descriptor
without creating a new one.
- The cap_getrights(2) syscall is renamed to cap_rights_get(2).
- If CAP_IOCTL capability right is present we can further reduce allowed
ioctls list with the new cap_ioctls_limit(2) syscall. List of allowed
ioctls can be retrived with cap_ioctls_get(2) syscall.
- If CAP_FCNTL capability right is present we can further reduce fcntls
that can be used with the new cap_fcntls_limit(2) syscall and retrive
them with cap_fcntls_get(2).
- To support ioctl and fcntl white-listing the filedesc structure was
heavly modified.
- The audit subsystem, kdump and procstat tools were updated to
recognize new syscalls.
- Capability rights were revised and eventhough I tried hard to provide
backward API and ABI compatibility there are some incompatible changes
that are described in detail below:
CAP_CREATE old behaviour:
- Allow for openat(2)+O_CREAT.
- Allow for linkat(2).
- Allow for symlinkat(2).
CAP_CREATE new behaviour:
- Allow for openat(2)+O_CREAT.
Added CAP_LINKAT:
- Allow for linkat(2). ABI: Reuses CAP_RMDIR bit.
- Allow to be target for renameat(2).
Added CAP_SYMLINKAT:
- Allow for symlinkat(2).
Removed CAP_DELETE. Old behaviour:
- Allow for unlinkat(2) when removing non-directory object.
- Allow to be source for renameat(2).
Removed CAP_RMDIR. Old behaviour:
- Allow for unlinkat(2) when removing directory.
Added CAP_RENAMEAT:
- Required for source directory for the renameat(2) syscall.
Added CAP_UNLINKAT (effectively it replaces CAP_DELETE and CAP_RMDIR):
- Allow for unlinkat(2) on any object.
- Required if target of renameat(2) exists and will be removed by this
call.
Removed CAP_MAPEXEC.
CAP_MMAP old behaviour:
- Allow for mmap(2) with any combination of PROT_NONE, PROT_READ and
PROT_WRITE.
CAP_MMAP new behaviour:
- Allow for mmap(2)+PROT_NONE.
Added CAP_MMAP_R:
- Allow for mmap(PROT_READ).
Added CAP_MMAP_W:
- Allow for mmap(PROT_WRITE).
Added CAP_MMAP_X:
- Allow for mmap(PROT_EXEC).
Added CAP_MMAP_RW:
- Allow for mmap(PROT_READ | PROT_WRITE).
Added CAP_MMAP_RX:
- Allow for mmap(PROT_READ | PROT_EXEC).
Added CAP_MMAP_WX:
- Allow for mmap(PROT_WRITE | PROT_EXEC).
Added CAP_MMAP_RWX:
- Allow for mmap(PROT_READ | PROT_WRITE | PROT_EXEC).
Renamed CAP_MKDIR to CAP_MKDIRAT.
Renamed CAP_MKFIFO to CAP_MKFIFOAT.
Renamed CAP_MKNODE to CAP_MKNODEAT.
CAP_READ old behaviour:
- Allow pread(2).
- Disallow read(2), readv(2) (if there is no CAP_SEEK).
CAP_READ new behaviour:
- Allow read(2), readv(2).
- Disallow pread(2) (CAP_SEEK was also required).
CAP_WRITE old behaviour:
- Allow pwrite(2).
- Disallow write(2), writev(2) (if there is no CAP_SEEK).
CAP_WRITE new behaviour:
- Allow write(2), writev(2).
- Disallow pwrite(2) (CAP_SEEK was also required).
Added convinient defines:
#define CAP_PREAD (CAP_SEEK | CAP_READ)
#define CAP_PWRITE (CAP_SEEK | CAP_WRITE)
#define CAP_MMAP_R (CAP_MMAP | CAP_SEEK | CAP_READ)
#define CAP_MMAP_W (CAP_MMAP | CAP_SEEK | CAP_WRITE)
#define CAP_MMAP_X (CAP_MMAP | CAP_SEEK | 0x0000000000000008ULL)
#define CAP_MMAP_RW (CAP_MMAP_R | CAP_MMAP_W)
#define CAP_MMAP_RX (CAP_MMAP_R | CAP_MMAP_X)
#define CAP_MMAP_WX (CAP_MMAP_W | CAP_MMAP_X)
#define CAP_MMAP_RWX (CAP_MMAP_R | CAP_MMAP_W | CAP_MMAP_X)
#define CAP_RECV CAP_READ
#define CAP_SEND CAP_WRITE
#define CAP_SOCK_CLIENT \
(CAP_CONNECT | CAP_GETPEERNAME | CAP_GETSOCKNAME | CAP_GETSOCKOPT | \
CAP_PEELOFF | CAP_RECV | CAP_SEND | CAP_SETSOCKOPT | CAP_SHUTDOWN)
#define CAP_SOCK_SERVER \
(CAP_ACCEPT | CAP_BIND | CAP_GETPEERNAME | CAP_GETSOCKNAME | \
CAP_GETSOCKOPT | CAP_LISTEN | CAP_PEELOFF | CAP_RECV | CAP_SEND | \
CAP_SETSOCKOPT | CAP_SHUTDOWN)
Added defines for backward API compatibility:
#define CAP_MAPEXEC CAP_MMAP_X
#define CAP_DELETE CAP_UNLINKAT
#define CAP_MKDIR CAP_MKDIRAT
#define CAP_RMDIR CAP_UNLINKAT
#define CAP_MKFIFO CAP_MKFIFOAT
#define CAP_MKNOD CAP_MKNODAT
#define CAP_SOCK_ALL (CAP_SOCK_CLIENT | CAP_SOCK_SERVER)
Sponsored by: The FreeBSD Foundation
Reviewed by: Christoph Mallon <christoph.mallon@gmx.de>
Many aspects discussed with: rwatson, benl, jonathan
ABI compatibility discussed with: kib
2013-03-02 00:53:12 +00:00
|
|
|
* CAP_FREVOKE here.
|
2011-08-11 12:30:23 +00:00
|
|
|
*
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
* In the meantime, use CAP_ALL(): if a SVR4 process wants to
|
2011-08-11 12:30:23 +00:00
|
|
|
* do an frevoke(), it needs to do it on either a regular file
|
|
|
|
* descriptor or a fully-privileged capability (which is effectively
|
|
|
|
* the same as a non-capability-restricted file descriptor).
|
|
|
|
*/
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
CAP_ALL(&rights);
|
|
|
|
if ((error = fgetvp(td, fd, &rights, &vp)) != 0)
|
2002-01-14 00:13:45 +00:00
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
if (vp->v_type != VCHR && vp->v_type != VBLK) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2002-08-12 01:42:21 +00:00
|
|
|
#ifdef MAC
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2007-10-24 19:04:04 +00:00
|
|
|
error = mac_vnode_check_revoke(td->td_ucred, vp);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2002-08-12 01:42:21 +00:00
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
|
2008-08-28 15:23:18 +00:00
|
|
|
if ((error = VOP_GETATTR(vp, &vattr, td->td_ucred)) != 0)
|
1999-01-30 06:29:48 +00:00
|
|
|
goto out;
|
|
|
|
|
2002-02-27 18:32:23 +00:00
|
|
|
if (td->td_ucred->cr_uid != vattr.va_uid &&
|
2007-06-12 00:12:01 +00:00
|
|
|
(error = priv_check(td, PRIV_VFS_ADMIN)) != 0)
|
1999-01-30 06:29:48 +00:00
|
|
|
goto out;
|
|
|
|
|
2000-07-11 22:07:57 +00:00
|
|
|
if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
|
|
|
|
goto out;
|
1999-08-26 14:53:31 +00:00
|
|
|
if (vcount(vp) > 1)
|
1999-01-30 06:29:48 +00:00
|
|
|
VOP_REVOKE(vp, REVOKEALL);
|
2000-07-11 22:07:57 +00:00
|
|
|
vn_finished_write(mp);
|
1999-01-30 06:29:48 +00:00
|
|
|
out:
|
|
|
|
vrele(vp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
fd_truncate(td, fd, flp)
|
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
int fd;
|
|
|
|
struct flock *flp;
|
|
|
|
{
|
|
|
|
off_t start, length;
|
2002-01-19 03:45:14 +00:00
|
|
|
struct file *fp;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct vnode *vp;
|
|
|
|
struct vattr vattr;
|
|
|
|
int error, *retval;
|
|
|
|
struct ftruncate_args ft;
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
cap_rights_t rights;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
retval = td->td_retval;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We only support truncating the file.
|
|
|
|
*/
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
error = fget(td, fd, cap_rights_init(&rights, CAP_FTRUNCATE), &fp);
|
|
|
|
if (error != 0)
|
2002-01-14 00:13:45 +00:00
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2003-06-22 08:41:43 +00:00
|
|
|
vp = fp->f_vnode;
|
2002-01-19 03:45:14 +00:00
|
|
|
|
|
|
|
if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
|
|
|
|
fdrop(fp, td);
|
1999-01-30 06:29:48 +00:00
|
|
|
return ESPIPE;
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2008-08-28 15:23:18 +00:00
|
|
|
if ((error = VOP_GETATTR(vp, &vattr, td->td_ucred)) != 0) {
|
2002-01-19 03:45:14 +00:00
|
|
|
fdrop(fp, td);
|
1999-01-30 06:29:48 +00:00
|
|
|
return error;
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
length = vattr.va_size;
|
|
|
|
|
|
|
|
switch (flp->l_whence) {
|
|
|
|
case SEEK_CUR:
|
|
|
|
start = fp->f_offset + flp->l_start;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEEK_END:
|
|
|
|
start = flp->l_start + length;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEEK_SET:
|
|
|
|
start = flp->l_start;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-01-19 03:45:14 +00:00
|
|
|
fdrop(fp, td);
|
1999-01-30 06:29:48 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start + flp->l_len < length) {
|
|
|
|
/* We don't support free'ing in the middle of the file */
|
2002-01-19 03:45:14 +00:00
|
|
|
fdrop(fp, td);
|
1999-01-30 06:29:48 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ft.fd = fd;
|
|
|
|
ft.length = start;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2011-09-16 13:58:51 +00:00
|
|
|
error = sys_ftruncate(td, &ft);
|
2002-01-13 11:58:06 +00:00
|
|
|
|
2002-01-19 03:45:14 +00:00
|
|
|
fdrop(fp, td);
|
2002-01-13 11:58:06 +00:00
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_open(td, uap)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_open_args *uap;
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct proc *p = td->td_proc;
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
char *newpath;
|
|
|
|
int bsd_flags, error, retval;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
CHECKALTEXIST(td, uap->path, &newpath);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
bsd_flags = svr4_to_bsd_flags(uap->flags);
|
2014-11-13 18:01:51 +00:00
|
|
|
error = kern_openat(td, AT_FDCWD, newpath, UIO_SYSSPACE, bsd_flags,
|
|
|
|
uap->mode);
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
free(newpath, M_TEMP);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
if (error) {
|
Back out alpha/alpha/trap.c:1.124, osf1_ioctl.c:1.14, osf1_misc.c:1.57,
osf1_signal.c:1.41, amd64/amd64/trap.c:1.291, linux_socket.c:1.60,
svr4_fcntl.c:1.36, svr4_ioctl.c:1.23, svr4_ipc.c:1.18, svr4_misc.c:1.81,
svr4_signal.c:1.34, svr4_stat.c:1.21, svr4_stream.c:1.55,
svr4_termios.c:1.13, svr4_ttold.c:1.15, svr4_util.h:1.10,
ext2_alloc.c:1.43, i386/i386/trap.c:1.279, vm86.c:1.58,
unaligned.c:1.12, imgact_elf.c:1.164, ffs_alloc.c:1.133:
Now that Giant is acquired in uprintf() and tprintf(), the caller no
longer leads to acquire Giant unless it also holds another mutex that
would generate a lock order reversal when calling into these functions.
Specifically not backed out is the acquisition of Giant in nfs_socket.c
and rpcclnt.c, where local mutexes are held and would otherwise violate
the lock order with Giant.
This aligns this code more with the eventual locking of ttys.
Suggested by: bde
2005-09-28 07:03:03 +00:00
|
|
|
/* uprintf("svr4_open(%s, 0x%0x, 0%o): %d\n", uap->path,
|
|
|
|
uap->flags, uap->mode, error);*/
|
1999-01-30 06:29:48 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
retval = td->td_retval[0];
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2001-01-23 21:33:55 +00:00
|
|
|
PROC_LOCK(p);
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
if (!(bsd_flags & O_NOCTTY) && SESS_LEADER(p) &&
|
|
|
|
!(p->p_flag & P_CONTROLT)) {
|
1999-01-30 06:29:48 +00:00
|
|
|
#if defined(NOTYET)
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
cap_rights_t rights;
|
|
|
|
struct file *fp;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
error = fget(td, retval,
|
|
|
|
cap_rights_init(&rights, CAP_IOCTL), &fp);
|
2001-01-23 21:33:55 +00:00
|
|
|
PROC_UNLOCK(p);
|
2002-01-13 11:58:06 +00:00
|
|
|
/*
|
|
|
|
* we may have lost a race the above open() and
|
|
|
|
* another thread issuing a close()
|
|
|
|
*/
|
2002-01-14 00:13:45 +00:00
|
|
|
if (error)
|
2002-01-13 11:58:06 +00:00
|
|
|
return (EBADF); /* XXX: correct errno? */
|
1999-01-30 06:29:48 +00:00
|
|
|
/* ignore any error, just give it a try */
|
|
|
|
if (fp->f_type == DTYPE_VNODE)
|
2002-08-17 02:36:16 +00:00
|
|
|
fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td->td_ucred,
|
|
|
|
td);
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, td);
|
|
|
|
} else {
|
2001-01-23 21:33:55 +00:00
|
|
|
PROC_UNLOCK(p);
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
2001-01-23 21:33:55 +00:00
|
|
|
#else
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
2001-01-23 21:33:55 +00:00
|
|
|
PROC_UNLOCK(p);
|
|
|
|
#endif
|
1999-01-30 06:29:48 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_open64(td, uap)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_open64_args *uap;
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
return svr4_sys_open(td, (struct svr4_sys_open_args *)uap);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_creat(td, uap)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_creat_args *uap;
|
|
|
|
{
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
char *newpath;
|
|
|
|
int error;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
CHECKALTEXIST(td, uap->path, &newpath);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2014-11-13 18:01:51 +00:00
|
|
|
error = kern_openat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC, uap->mode);
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
free(newpath, M_TEMP);
|
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_creat64(td, uap)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_creat64_args *uap;
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
return svr4_sys_creat(td, (struct svr4_sys_creat_args *)uap);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_llseek(td, uap)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
2001-01-23 21:33:55 +00:00
|
|
|
struct svr4_sys_llseek_args *uap;
|
1999-01-30 06:29:48 +00:00
|
|
|
{
|
|
|
|
struct lseek_args ap;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.fd = uap->fd;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.offset = (((u_int64_t) uap->offset1) << 32) |
|
|
|
|
uap->offset2;
|
1999-01-30 06:29:48 +00:00
|
|
|
#else
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.offset = (((u_int64_t) uap->offset2) << 32) |
|
|
|
|
uap->offset1;
|
1999-01-30 06:29:48 +00:00
|
|
|
#endif
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.whence = uap->whence;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2011-09-16 13:58:51 +00:00
|
|
|
return sys_lseek(td, &ap);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_access(td, uap)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_access_args *uap;
|
|
|
|
{
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
char *newpath;
|
|
|
|
int error;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
CHECKALTEXIST(td, uap->path, &newpath);
|
2014-11-13 18:01:51 +00:00
|
|
|
error = kern_accessat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
|
|
|
|
0, uap->amode);
|
- Implement svr4_emul_find() using kern_alternate_path(). This changes
the semantics in that the returned filename to use is now a kernel
pointer rather than a user space pointer. This required changing the
arguments to the CHECKALT*() macros some and changing the various system
calls that used pathnames to use the kern_foo() functions that can accept
kernel space filename pointers instead of calling the system call
directly.
- Use kern_open(), kern_access(), kern_msgctl(), kern_execve(),
kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(),
kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(),
kern_pathconf(), and kern_unlink().
2005-02-07 21:53:42 +00:00
|
|
|
free(newpath, M_TEMP);
|
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(NOTYET)
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_pread(td, uap)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_pread_args *uap;
|
|
|
|
{
|
|
|
|
struct pread_args pra;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just translate the args structure and call the NetBSD
|
|
|
|
* pread(2) system call (offset type is 64-bit in NetBSD).
|
|
|
|
*/
|
2002-12-14 01:56:26 +00:00
|
|
|
pra.fd = uap->fd;
|
|
|
|
pra.buf = uap->buf;
|
|
|
|
pra.nbyte = uap->nbyte;
|
|
|
|
pra.offset = uap->off;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
return pread(td, &pra);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(NOTYET)
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_pread64(td, v, retval)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
|
|
|
|
struct svr4_sys_pread64_args *uap = v;
|
|
|
|
struct sys_pread_args pra;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just translate the args structure and call the NetBSD
|
|
|
|
* pread(2) system call (offset type is 64-bit in NetBSD).
|
|
|
|
*/
|
2002-12-14 01:56:26 +00:00
|
|
|
pra.fd = uap->fd;
|
|
|
|
pra.buf = uap->buf;
|
|
|
|
pra.nbyte = uap->nbyte;
|
|
|
|
pra.offset = uap->off;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
return (sys_pread(td, &pra, retval));
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
#endif /* NOTYET */
|
|
|
|
|
|
|
|
#if defined(NOTYET)
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_pwrite(td, uap)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_pwrite_args *uap;
|
|
|
|
{
|
|
|
|
struct pwrite_args pwa;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just translate the args structure and call the NetBSD
|
|
|
|
* pwrite(2) system call (offset type is 64-bit in NetBSD).
|
|
|
|
*/
|
2002-12-14 01:56:26 +00:00
|
|
|
pwa.fd = uap->fd;
|
|
|
|
pwa.buf = uap->buf;
|
|
|
|
pwa.nbyte = uap->nbyte;
|
|
|
|
pwa.offset = uap->off;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
return pwrite(td, &pwa);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(NOTYET)
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_pwrite64(td, v, retval)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct svr4_sys_pwrite64_args *uap = v;
|
|
|
|
struct sys_pwrite_args pwa;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just translate the args structure and call the NetBSD
|
|
|
|
* pwrite(2) system call (offset type is 64-bit in NetBSD).
|
|
|
|
*/
|
2002-12-14 01:56:26 +00:00
|
|
|
pwa.fd = uap->fd;
|
|
|
|
pwa.buf = uap->buf;
|
|
|
|
pwa.nbyte = uap->nbyte;
|
|
|
|
pwa.offset = uap->off;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
return (sys_pwrite(td, &pwa, retval));
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
#endif /* NOTYET */
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
svr4_sys_fcntl(td, uap)
|
2009-05-29 05:58:46 +00:00
|
|
|
struct thread *td;
|
1999-01-30 06:29:48 +00:00
|
|
|
struct svr4_sys_fcntl_args *uap;
|
|
|
|
{
|
2004-08-24 20:21:21 +00:00
|
|
|
int cmd, error, *retval;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
retval = td->td_retval;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2004-08-24 20:21:21 +00:00
|
|
|
cmd = svr4_to_bsd_cmd(uap->cmd);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2004-08-24 20:21:21 +00:00
|
|
|
switch (cmd) {
|
1999-01-30 06:29:48 +00:00
|
|
|
case F_DUPFD:
|
2008-03-17 18:27:28 +00:00
|
|
|
case F_DUP2FD:
|
1999-01-30 06:29:48 +00:00
|
|
|
case F_GETFD:
|
|
|
|
case F_SETFD:
|
2004-08-24 20:21:21 +00:00
|
|
|
return (kern_fcntl(td, uap->fd, cmd, (intptr_t)uap->arg));
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
case F_GETFL:
|
2004-08-24 20:21:21 +00:00
|
|
|
error = kern_fcntl(td, uap->fd, cmd, (intptr_t)uap->arg);
|
1999-01-30 06:29:48 +00:00
|
|
|
if (error)
|
2004-08-24 20:21:21 +00:00
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
*retval = bsd_to_svr4_flags(*retval);
|
2004-08-24 20:21:21 +00:00
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
case F_SETFL:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* we must save the O_ASYNC flag, as that is
|
|
|
|
* handled by ioctl(_, I_SETSIG, _) emulation.
|
|
|
|
*/
|
|
|
|
int flags;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
DPRINTF(("Setting flags %p\n", uap->arg));
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2004-08-24 20:21:21 +00:00
|
|
|
error = kern_fcntl(td, uap->fd, F_GETFL, 0);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
flags = *retval;
|
|
|
|
flags &= O_ASYNC;
|
2002-12-14 01:56:26 +00:00
|
|
|
flags |= svr4_to_bsd_flags((u_long) uap->arg);
|
2004-08-24 20:21:21 +00:00
|
|
|
return (kern_fcntl(td, uap->fd, F_SETFL, flags));
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case F_GETLK:
|
|
|
|
case F_SETLK:
|
|
|
|
case F_SETLKW:
|
|
|
|
{
|
2004-08-24 20:21:21 +00:00
|
|
|
struct svr4_flock ifl;
|
|
|
|
struct flock fl;
|
1999-01-30 06:29:48 +00:00
|
|
|
|
2004-08-24 20:21:21 +00:00
|
|
|
error = copyin(uap->arg, &ifl, sizeof (ifl));
|
1999-01-30 06:29:48 +00:00
|
|
|
if (error)
|
2004-08-24 20:21:21 +00:00
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
svr4_to_bsd_flock(&ifl, &fl);
|
|
|
|
|
2004-08-24 20:21:21 +00:00
|
|
|
error = kern_fcntl(td, uap->fd, cmd, (intptr_t)&fl);
|
|
|
|
if (error || cmd != F_GETLK)
|
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
bsd_to_svr4_flock(&fl, &ifl);
|
|
|
|
|
2004-08-24 20:21:21 +00:00
|
|
|
return (copyout(&ifl, uap->arg, sizeof (ifl)));
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
case -1:
|
2002-12-14 01:56:26 +00:00
|
|
|
switch (uap->cmd) {
|
1999-01-30 06:29:48 +00:00
|
|
|
case SVR4_F_FREESP:
|
|
|
|
{
|
|
|
|
struct svr4_flock ifl;
|
|
|
|
struct flock fl;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
error = copyin(uap->arg, &ifl,
|
1999-01-30 06:29:48 +00:00
|
|
|
sizeof ifl);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
svr4_to_bsd_flock(&ifl, &fl);
|
2002-12-14 01:56:26 +00:00
|
|
|
return fd_truncate(td, uap->fd, &fl);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case SVR4_F_GETLK64:
|
|
|
|
case SVR4_F_SETLK64:
|
|
|
|
case SVR4_F_SETLKW64:
|
|
|
|
{
|
2004-08-24 20:21:21 +00:00
|
|
|
struct svr4_flock64 ifl;
|
|
|
|
struct flock fl;
|
|
|
|
|
|
|
|
switch (uap->cmd) {
|
|
|
|
case SVR4_F_GETLK64:
|
|
|
|
cmd = F_GETLK;
|
|
|
|
break;
|
|
|
|
case SVR4_F_SETLK64:
|
|
|
|
cmd = F_SETLK;
|
|
|
|
break;
|
|
|
|
case SVR4_F_SETLKW64:
|
|
|
|
cmd = F_SETLKW;
|
|
|
|
break;
|
|
|
|
}
|
2002-12-14 01:56:26 +00:00
|
|
|
error = copyin(uap->arg, &ifl,
|
2004-08-24 20:21:21 +00:00
|
|
|
sizeof (ifl));
|
1999-01-30 06:29:48 +00:00
|
|
|
if (error)
|
2004-08-24 20:21:21 +00:00
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
svr4_to_bsd_flock64(&ifl, &fl);
|
|
|
|
|
2004-08-24 20:21:21 +00:00
|
|
|
error = kern_fcntl(td, uap->fd, cmd,
|
|
|
|
(intptr_t)&fl);
|
|
|
|
if (error || cmd != F_GETLK)
|
|
|
|
return (error);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
bsd_to_svr4_flock64(&fl, &ifl);
|
|
|
|
|
2004-08-24 20:21:21 +00:00
|
|
|
return (copyout(&ifl, uap->arg,
|
|
|
|
sizeof (ifl)));
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case SVR4_F_FREESP64:
|
|
|
|
{
|
|
|
|
struct svr4_flock64 ifl;
|
|
|
|
struct flock fl;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
error = copyin(uap->arg, &ifl,
|
1999-01-30 06:29:48 +00:00
|
|
|
sizeof ifl);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
svr4_to_bsd_flock64(&ifl, &fl);
|
2002-12-14 01:56:26 +00:00
|
|
|
return fd_truncate(td, uap->fd, &fl);
|
1999-01-30 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case SVR4_F_REVOKE:
|
2002-12-14 01:56:26 +00:00
|
|
|
return fd_revoke(td, uap->fd);
|
1999-01-30 06:29:48 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
}
|