Retire code added to support CloudABI

CloudABI was removed in cf0ee8738e
This commit is contained in:
Mateusz Guzik 2021-04-28 22:55:03 +02:00
parent 880aec7361
commit a0558fe90d
7 changed files with 14 additions and 187 deletions

View File

@ -906,7 +906,7 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new)
FILEDESC_XLOCK(fdp);
if (fget_locked(fdp, old) == NULL)
goto unlock;
if ((mode == FDDUP_FIXED || mode == FDDUP_MUSTREPLACE) && old == new) {
if (mode == FDDUP_FIXED && old == new) {
td->td_retval[0] = new;
if (flags & FDDUP_FLAG_CLOEXEC)
fdp->fd_ofiles[new].fde_flags |= UF_EXCLOSE;
@ -932,13 +932,6 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new)
goto unlock;
}
break;
case FDDUP_MUSTREPLACE:
/* Target file descriptor must exist. */
if (fget_locked(fdp, new) == NULL) {
fdrop(oldfp, td);
goto unlock;
}
break;
case FDDUP_FIXED:
if (new >= fdp->fd_nfiles) {
/*
@ -2320,14 +2313,6 @@ pdunshare(struct thread *td)
p->p_pd = pdp;
}
void
fdinstall_remapped(struct thread *td, struct filedesc *fdp)
{
fdescfree(td);
td->td_proc->p_fd = fdp;
}
/*
* Copy a filedesc structure. A NULL pointer in returns a NULL reference,
* this is to ease callers, not catch errors.
@ -2380,66 +2365,6 @@ pdcopy(struct pwddesc *pdp)
return (newpdp);
}
/*
* Copies a filedesc structure, while remapping all file descriptors
* stored inside using a translation table.
*
* File descriptors are copied over to the new file descriptor table,
* regardless of whether the close-on-exec flag is set.
*/
int
fdcopy_remapped(struct filedesc *fdp, const int *fds, size_t nfds,
struct filedesc **ret)
{
struct filedesc *newfdp;
struct filedescent *nfde, *ofde;
int error, i, lastfile;
MPASS(fdp != NULL);
newfdp = fdinit(fdp, true, &lastfile);
if (nfds > lastfile + 1) {
/* New table cannot be larger than the old one. */
error = E2BIG;
goto bad;
}
/* Copy all passable descriptors (i.e. not kqueue). */
newfdp->fd_freefile = nfds;
for (i = 0; i < nfds; ++i) {
if (fds[i] < 0 || fds[i] > lastfile) {
/* File descriptor out of bounds. */
error = EBADF;
goto bad;
}
ofde = &fdp->fd_ofiles[fds[i]];
if (ofde->fde_file == NULL) {
/* Unused file descriptor. */
error = EBADF;
goto bad;
}
if ((ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) == 0) {
/* File descriptor cannot be passed. */
error = EINVAL;
goto bad;
}
if (!fhold(ofde->fde_file)) {
error = EBADF;
goto bad;
}
nfde = &newfdp->fd_ofiles[i];
*nfde = *ofde;
filecaps_copy(&ofde->fde_caps, &nfde->fde_caps, true);
fdused_init(newfdp, i);
}
FILEDESC_SUNLOCK(fdp);
*ret = newfdp;
return (0);
bad:
FILEDESC_SUNLOCK(fdp);
fdescfree_remapped(newfdp);
return (error);
}
/*
* Clear POSIX style locks. This is only used when fdp looses a reference (i.e.
* one of processes using it exits) and the table used to be shared.
@ -2526,7 +2451,7 @@ fdclearlocks(struct thread *td)
* Release a filedesc structure.
*/
static void
fdescfree_fds(struct thread *td, struct filedesc *fdp, bool needclose)
fdescfree_fds(struct thread *td, struct filedesc *fdp)
{
struct filedesc0 *fdp0;
struct freetable *ft, *tft;
@ -2551,10 +2476,7 @@ fdescfree_fds(struct thread *td, struct filedesc *fdp, bool needclose)
fp = fde->fde_file;
if (fp != NULL) {
fdefree_last(fde);
if (needclose)
(void) closef(fp, td);
else
fdrop(fp, td);
(void) closef(fp, td);
}
}
@ -2598,7 +2520,7 @@ fdescfree(struct thread *td)
if (refcount_release(&fdp->fd_refcnt) == 0)
return;
fdescfree_fds(td, fdp, 1);
fdescfree_fds(td, fdp);
}
void
@ -2621,17 +2543,6 @@ pdescfree(struct thread *td)
pddrop(pdp);
}
void
fdescfree_remapped(struct filedesc *fdp)
{
#ifdef INVARIANTS
/* fdescfree_fds() asserts that fd_refcnt == 0. */
if (!refcount_release(&fdp->fd_refcnt))
panic("%s: fd table %p has extra references", __func__, fdp);
#endif
fdescfree_fds(curthread, fdp, 0);
}
/*
* For setugid programs, we don't want to people to use that setugidness
* to generate error messages which write to a file which otherwise would

View File

@ -704,21 +704,14 @@ do_execve(struct thread *td, struct image_args *args, struct mac *mac_p,
goto exec_fail_dealloc;
}
if (args->fdp != NULL) {
/* Install a brand new file descriptor table. */
fdinstall_remapped(td, args->fdp);
args->fdp = NULL;
} else {
/*
* Keep on using the existing file descriptor table. For
* security and other reasons, the file descriptor table
* cannot be shared after an exec.
*/
fdunshare(td);
pdunshare(td);
/* close files on exec */
fdcloseexec(td);
}
/*
* For security and other reasons, the file descriptor table cannot be
* shared after an exec.
*/
fdunshare(td);
pdunshare(td);
/* close files on exec */
fdcloseexec(td);
/*
* Malloc things before we need locks.
@ -1239,69 +1232,6 @@ exec_copyin_args(struct image_args *args, const char *fname,
return (error);
}
int
exec_copyin_data_fds(struct thread *td, struct image_args *args,
const void *data, size_t datalen, const int *fds, size_t fdslen)
{
struct filedesc *ofdp;
const char *p;
int *kfds;
int error;
memset(args, '\0', sizeof(*args));
ofdp = td->td_proc->p_fd;
if (datalen >= ARG_MAX || fdslen >= ofdp->fd_nfiles)
return (E2BIG);
error = exec_alloc_args(args);
if (error != 0)
return (error);
args->begin_argv = args->buf;
args->stringspace = ARG_MAX;
if (datalen > 0) {
/*
* Argument buffer has been provided. Copy it into the
* kernel as a single string and add a terminating null
* byte.
*/
error = copyin(data, args->begin_argv, datalen);
if (error != 0)
goto err_exit;
args->begin_argv[datalen] = '\0';
args->endp = args->begin_argv + datalen + 1;
args->stringspace -= datalen + 1;
/*
* Traditional argument counting. Count the number of
* null bytes.
*/
for (p = args->begin_argv; p < args->endp; ++p)
if (*p == '\0')
++args->argc;
} else {
/* No argument buffer provided. */
args->endp = args->begin_argv;
}
/* Create new file descriptor table. */
kfds = malloc(fdslen * sizeof(int), M_TEMP, M_WAITOK);
error = copyin(fds, kfds, fdslen * sizeof(int));
if (error != 0) {
free(kfds, M_TEMP);
goto err_exit;
}
error = fdcopy_remapped(ofdp, kfds, fdslen, &args->fdp);
free(kfds, M_TEMP);
if (error != 0)
goto err_exit;
return (0);
err_exit:
exec_free_args(args);
return (error);
}
struct exec_args_kva {
vm_offset_t addr;
u_int gen;
@ -1438,8 +1368,6 @@ exec_free_args(struct image_args *args)
free(args->fname_buf, M_TEMP);
args->fname_buf = NULL;
}
if (args->fdp != NULL)
fdescfree_remapped(args->fdp);
}
/*

View File

@ -597,8 +597,7 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread *
* been preserved.
*/
p2->p_flag |= p1->p_flag & P_SUGID;
td2->td_pflags |= (td->td_pflags & (TDP_ALTSTACK |
TDP_SIGFASTBLOCK)) | TDP_FORKING;
td2->td_pflags |= (td->td_pflags & (TDP_ALTSTACK | TDP_SIGFASTBLOCK));
SESS_LOCK(p1->p_session);
if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)
p2->p_flag |= P_CONTROLT;
@ -1100,7 +1099,6 @@ fork_exit(void (*callout)(void *, struct trapframe *), void *arg,
if (p->p_sysent->sv_schedtail != NULL)
(p->p_sysent->sv_schedtail)(td);
td->td_pflags &= ~TDP_FORKING;
}
/*

View File

@ -215,8 +215,6 @@ syscallret(struct thread *td)
ksiginfo_t ksi;
int traced;
KASSERT((td->td_pflags & TDP_FORKING) == 0,
("fork() did not clear TDP_FORKING upon completion"));
KASSERT(td->td_errno != ERELOOKUP,
("ERELOOKUP not consumed syscall %d", td->td_sa.code));

View File

@ -203,7 +203,6 @@ enum {
FDDUP_NORMAL, /* dup() behavior. */
FDDUP_FCNTL, /* fcntl()-style errors. */
FDDUP_FIXED, /* Force fixed allocation. */
FDDUP_MUSTREPLACE, /* Target must exist. */
FDDUP_LASTMODE,
};
@ -250,12 +249,8 @@ void fdclose(struct thread *td, struct file *fp, int idx);
void fdcloseexec(struct thread *td);
void fdsetugidsafety(struct thread *td);
struct filedesc *fdcopy(struct filedesc *fdp);
int fdcopy_remapped(struct filedesc *fdp, const int *fds, size_t nfds,
struct filedesc **newfdp);
void fdinstall_remapped(struct thread *td, struct filedesc *fdp);
void fdunshare(struct thread *td);
void fdescfree(struct thread *td);
void fdescfree_remapped(struct filedesc *fdp);
int fdlastfile(struct filedesc *fdp);
int fdlastfile_single(struct filedesc *fdp);
struct filedesc *fdinit(struct filedesc *fdp, bool prepfiles, int *lastfile);

View File

@ -55,7 +55,6 @@ struct image_args {
int argc; /* count of argument strings */
int envc; /* count of environment strings */
int fd; /* file descriptor of the executable */
struct filedesc *fdp; /* new file descriptor table */
};
struct image_params {
@ -120,8 +119,6 @@ void exec_setregs(struct thread *, struct image_params *, uintptr_t);
int exec_shell_imgact(struct image_params *);
int exec_copyin_args(struct image_args *, const char *, enum uio_seg,
char **, char **);
int exec_copyin_data_fds(struct thread *, struct image_args *, const void *,
size_t, const int *, size_t);
void exec_stackgap(struct image_params *imgp, uintptr_t *dp);
int pre_execve(struct thread *td, struct vmspace **oldvmspace);
void post_execve(struct thread *td, int error, struct vmspace *oldvmspace);

View File

@ -524,7 +524,7 @@ do { \
#define TDP_RESETSPUR 0x04000000 /* Reset spurious page fault history. */
#define TDP_NERRNO 0x08000000 /* Last errno is already in td_errno */
#define TDP_UIOHELD 0x10000000 /* Current uio has pages held in td_ma */
#define TDP_FORKING 0x20000000 /* Thread is being created through fork() */
#define TDP_UNUSED0 0x20000000 /* UNUSED */
#define TDP_EXECVMSPC 0x40000000 /* Execve destroyed old vmspace */
#define TDP_SIGFASTPENDING 0x80000000 /* Pending signal due to sigfastblock */