| 416 | } |
| 417 | |
| 418 | int |
| 419 | kern_cap_ioctls_limit(struct thread *td, int fd, u_long *cmds, size_t ncmds) |
| 420 | { |
| 421 | struct filedesc *fdp; |
| 422 | struct filedescent *fdep; |
| 423 | u_long *ocmds; |
| 424 | int error; |
| 425 | |
| 426 | AUDIT_ARG_FD(fd); |
| 427 | |
| 428 | if (ncmds > IOCTLS_MAX_COUNT) { |
| 429 | error = EINVAL; |
| 430 | goto out_free; |
| 431 | } |
| 432 | |
| 433 | fdp = td->td_proc->p_fd; |
| 434 | FILEDESC_XLOCK(fdp); |
| 435 | |
| 436 | fdep = fdeget_locked(fdp, fd); |
| 437 | if (fdep == NULL) { |
| 438 | error = EBADF; |
| 439 | goto out; |
| 440 | } |
| 441 | |
| 442 | error = cap_ioctl_limit_check(fdep, cmds, ncmds); |
| 443 | if (error != 0) |
| 444 | goto out; |
| 445 | |
| 446 | ocmds = fdep->fde_ioctls; |
| 447 | seqc_write_begin(&fdep->fde_seqc); |
| 448 | fdep->fde_ioctls = cmds; |
| 449 | fdep->fde_nioctls = ncmds; |
| 450 | seqc_write_end(&fdep->fde_seqc); |
| 451 | |
| 452 | cmds = ocmds; |
| 453 | error = 0; |
| 454 | out: |
| 455 | FILEDESC_XUNLOCK(fdp); |
| 456 | out_free: |
| 457 | free(cmds, M_FILECAPS); |
| 458 | return (error); |
| 459 | } |
| 460 | |
| 461 | int |
| 462 | sys_cap_ioctls_limit(struct thread *td, struct cap_ioctls_limit_args *uap) |
no test coverage detected