diff options
author | dchagin <dchagin@FreeBSD.org> | 2017-03-15 16:38:39 +0000 |
---|---|---|
committer | dchagin <dchagin@FreeBSD.org> | 2017-03-15 16:38:39 +0000 |
commit | b8129eaf84f85d9a5cbdc81025dd8314f8148d85 (patch) | |
tree | e6c7c72459a687709a96584c6b3673bca57d7a92 /sys/sys | |
parent | 466bdf25f48f01fdeff163183f0be4fa531d8545 (diff) | |
download | FreeBSD-src-b8129eaf84f85d9a5cbdc81025dd8314f8148d85.zip FreeBSD-src-b8129eaf84f85d9a5cbdc81025dd8314f8148d85.tar.gz |
MFC r305093 (by mjg@):
fd: add fdeget_locked and use in kern_descrip
MFC r305756 (by oshogbo@):
fd: add fget_cap and fget_cap_locked primitives.
They can be used to obtain capabilities along with a referenced fp.
MFC r306174 (by oshogbo@):
capsicum: propagate rights on accept(2)
Descriptor returned by accept(2) should inherits capabilities rights from
the listening socket.
PR: 201052
MFC r306184 (by oshogbo@):
fd: simplify fgetvp_rights by using fget_cap_locked.
MFC r306225 (by mjg@):
fd: fix up fgetvp_rights after r306184
fget_cap_locked returns a referenced file, but the fgetvp_rights does
not need it. Instead, due to the filedesc lock being held, it can
ref the vnode after the file was looked up.
Fix up fget_cap_locked to be consistent with other _locked helpers and not
ref the file.
This plugs a leak introduced in r306184.
MFC r306232 (by oshogbo@):
fd: fix up fget_cap
If the kernel is not compiled with the CAPABILITIES kernel options
fget_unlocked doesn't return the sequence number so fd_modify will
always report modification, in that case we got infinity loop.
MFC r311474 (by glebius@):
Use getsock_cap() instead of fgetsock().
MFC r312079 (by glebius@):
Use getsock_cap() instead of deprecated fgetsock().
MFC r312081 (by glebius@):
Use getsock_cap() instead of deprecated fgetsock().
MFC r312087 (by glebius@):
Remove deprecated fgetsock() and fputsock().
Bump __FreeBSD_version as getsock_cap changed and
fgetsock/fputsock pair removed.
Diffstat (limited to 'sys/sys')
-rw-r--r-- | sys/sys/file.h | 6 | ||||
-rw-r--r-- | sys/sys/filedesc.h | 17 | ||||
-rw-r--r-- | sys/sys/param.h | 2 | ||||
-rw-r--r-- | sys/sys/socketvar.h | 3 |
4 files changed, 20 insertions, 8 deletions
diff --git a/sys/sys/file.h b/sys/sys/file.h index 6926081..c51f26a 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -50,8 +50,6 @@ struct thread; struct uio; struct knote; struct vnode; -struct socket; - #endif /* _KERNEL */ @@ -268,10 +266,6 @@ int fgetvp_read(struct thread *td, int fd, cap_rights_t *rightsp, int fgetvp_write(struct thread *td, int fd, cap_rights_t *rightsp, struct vnode **vpp); -int fgetsock(struct thread *td, int fd, cap_rights_t *rightsp, - struct socket **spp, u_int *fflagp); -void fputsock(struct socket *sp); - static __inline int _fnoop(void) { diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index b34a2f1..dfd81a4 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -190,6 +190,11 @@ int getvnode(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp); void mountcheckdirs(struct vnode *olddp, struct vnode *newdp); +int fget_cap_locked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, + struct file **fpp, struct filecaps *havecapsp); +int fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp, + struct file **fpp, struct filecaps *havecapsp); + /* Return a referenced file from an unlocked descriptor. */ int fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, struct file **fpp, seq_t *seqp); @@ -207,6 +212,18 @@ fget_locked(struct filedesc *fdp, int fd) return (fdp->fd_ofiles[fd].fde_file); } +static __inline struct filedescent * +fdeget_locked(struct filedesc *fdp, int fd) +{ + + FILEDESC_LOCK_ASSERT(fdp); + + if ((u_int)fd > fdp->fd_lastfile) + return (NULL); + + return (&fdp->fd_ofiles[fd]); +} + static __inline bool fd_modified(struct filedesc *fdp, int fd, seq_t seq) { diff --git a/sys/sys/param.h b/sys/sys/param.h index 05f3672..96680f9 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -58,7 +58,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1100509 /* Master, propagated to newvers */ +#define __FreeBSD_version 1100510 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 3bc2bae..7decd63 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -321,6 +321,7 @@ extern u_long sb_max; extern so_gen_t so_gencnt; struct file; +struct filecaps; struct filedesc; struct mbuf; struct sockaddr; @@ -340,7 +341,7 @@ struct uio; */ int getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len); int getsock_cap(struct thread *td, int fd, cap_rights_t *rightsp, - struct file **fpp, u_int *fflagp); + struct file **fpp, u_int *fflagp, struct filecaps *havecaps); void soabort(struct socket *so); int soaccept(struct socket *so, struct sockaddr **nam); void soaio_enqueue(struct task *task); |