Page MenuHomeFreeBSD

D3314.id7700.diff
No OneTemporary

D3314.id7700.diff

Index: sys/compat/cloudabi/cloudabi_fd.c
===================================================================
--- sys/compat/cloudabi/cloudabi_fd.c
+++ sys/compat/cloudabi/cloudabi_fd.c
@@ -523,6 +523,7 @@
struct cloudabi_sys_fd_stat_put_args *uap)
{
cloudabi_fdstat_t fsb;
+ cap_rights_t rights;
int error, oflags;
error = copyin(uap->buf, &fsb, sizeof(fsb));
@@ -540,6 +541,13 @@
CLOUDABI_FDFLAG_DSYNC | CLOUDABI_FDFLAG_RSYNC))
oflags |= O_SYNC;
return (kern_fcntl(td, uap->fd, F_SETFL, oflags));
+ } else if (uap->flags == CLOUDABI_FDSTAT_RIGHTS) {
+ /* Convert rights. */
+ error = cloudabi_convert_rights(
+ fsb.fs_rights_base | fsb.fs_rights_inheriting, &rights);
+ if (error != 0)
+ return (error);
+ return (kern_cap_rights_limit(td, uap->fd, &rights));
}
return (EINVAL);
}
Index: sys/kern/sys_capability.c
===================================================================
--- sys/kern/sys_capability.c
+++ sys/kern/sys_capability.c
@@ -213,15 +213,41 @@
return (cap_rights_fde(&fdp->fd_ofiles[fd]));
}
+int
+kern_cap_rights_limit(struct thread *td, int fd, cap_rights_t *rights)
+{
+ struct filedesc *fdp;
+ int error;
+
+ fdp = td->td_proc->p_fd;
+ FILEDESC_XLOCK(fdp);
+ if (fget_locked(fdp, fd) == NULL) {
+ FILEDESC_XUNLOCK(fdp);
+ return (EBADF);
+ }
+ error = _cap_check(cap_rights(fdp, fd), rights, CAPFAIL_INCREASE);
+ if (error == 0) {
+ fdp->fd_ofiles[fd].fde_rights = *rights;
+ if (!cap_rights_is_set(rights, CAP_IOCTL)) {
+ free(fdp->fd_ofiles[fd].fde_ioctls, M_FILECAPS);
+ fdp->fd_ofiles[fd].fde_ioctls = NULL;
+ fdp->fd_ofiles[fd].fde_nioctls = 0;
+ }
+ if (!cap_rights_is_set(rights, CAP_FCNTL))
+ fdp->fd_ofiles[fd].fde_fcntls = 0;
+ }
+ FILEDESC_XUNLOCK(fdp);
+ return (error);
+}
+
/*
* System call to limit rights of the given capability.
*/
int
sys_cap_rights_limit(struct thread *td, struct cap_rights_limit_args *uap)
{
- struct filedesc *fdp;
cap_rights_t rights;
- int error, fd, version;
+ int error, version;
cap_rights_init(&rights);
@@ -252,30 +278,9 @@
ktrcaprights(&rights);
#endif
- fd = uap->fd;
-
- AUDIT_ARG_FD(fd);
+ AUDIT_ARG_FD(uap->fd);
AUDIT_ARG_RIGHTS(&rights);
-
- fdp = td->td_proc->p_fd;
- FILEDESC_XLOCK(fdp);
- if (fget_locked(fdp, fd) == NULL) {
- FILEDESC_XUNLOCK(fdp);
- return (EBADF);
- }
- error = _cap_check(cap_rights(fdp, fd), &rights, CAPFAIL_INCREASE);
- if (error == 0) {
- fdp->fd_ofiles[fd].fde_rights = rights;
- if (!cap_rights_is_set(&rights, CAP_IOCTL)) {
- free(fdp->fd_ofiles[fd].fde_ioctls, M_FILECAPS);
- fdp->fd_ofiles[fd].fde_ioctls = NULL;
- fdp->fd_ofiles[fd].fde_nioctls = 0;
- }
- if (!cap_rights_is_set(&rights, CAP_FCNTL))
- fdp->fd_ofiles[fd].fde_fcntls = 0;
- }
- FILEDESC_XUNLOCK(fdp);
- return (error);
+ return (kern_cap_rights_limit(td, uap->fd, &rights));
}
/*
Index: sys/sys/syscallsubr.h
===================================================================
--- sys/sys/syscallsubr.h
+++ sys/sys/syscallsubr.h
@@ -74,6 +74,7 @@
int kern_bindat(struct thread *td, int dirfd, int fd, struct sockaddr *sa);
int kern_cap_ioctls_limit(struct thread *td, int fd, u_long *cmds,
size_t ncmds);
+int kern_cap_rights_limit(struct thread *td, int fd, cap_rights_t *rights);
int kern_chdir(struct thread *td, char *path, enum uio_seg pathseg);
int kern_clock_getcpuclockid2(struct thread *td, id_t id, int which,
clockid_t *clk_id);

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 15, 2:05 AM (11 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25311641
Default Alt Text
D3314.id7700.diff (3 KB)

Event Timeline