diff options
| author | John Baldwin <jhb@FreeBSD.org> | 2026-05-02 16:43:29 +0000 |
|---|---|---|
| committer | John Baldwin <jhb@FreeBSD.org> | 2026-06-23 16:06:19 +0000 |
| commit | d9df9b4d2aff2643e79903feae640b3575afb201 (patch) | |
| tree | 8a01e0747a209478e948e2f83f01910884e86e1c | |
| parent | f4e2f07f0cbc976e5a894ab4f3dbbccb15e06d46 (diff) | |
ctl_ioctl_frontend: Reject out-of-range initiator IDs
Various places in CTL assume that initiator IDs are not larger than
CTL_MAX_INIT_PER_PORT. Other IDs such as lun IDs are validated in
places such as ctl_scsiio_precheck, but initiator IDs submitted by
userland were not previously validated.
PR: 291059
Reported by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
Reviewed by: asomers
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D56628
(cherry picked from commit 6f8312bdff236ad64d1c15c239051359d8245a68)
| -rw-r--r-- | sys/cam/ctl/ctl_frontend_ioctl.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/sys/cam/ctl/ctl_frontend_ioctl.c b/sys/cam/ctl/ctl_frontend_ioctl.c index a93f6cd5a4c5..9ba0580283c7 100644 --- a/sys/cam/ctl/ctl_frontend_ioctl.c +++ b/sys/cam/ctl/ctl_frontend_ioctl.c @@ -589,7 +589,7 @@ ctl_ioctl_io(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td) { struct cfi_port *cfi; - union ctl_io *io; + union ctl_io *io, *user_io; void *pool_tmp, *sc_tmp; int retval = 0; @@ -607,6 +607,11 @@ ctl_ioctl_io(struct cdev *dev, u_long cmd, caddr_t addr, int flag, if ((cfi->port.status & CTL_PORT_STATUS_ONLINE) == 0) return (EPERM); + /* Reject out-of-range initiator IDs. */ + user_io = (void *)addr; + if (user_io->io_hdr.nexus.initid >= CTL_MAX_INIT_PER_PORT) + return (EINVAL); + io = ctl_alloc_io(cfi->port.ctl_pool_ref); /* @@ -615,7 +620,7 @@ ctl_ioctl_io(struct cdev *dev, u_long cmd, caddr_t addr, int flag, */ pool_tmp = io->io_hdr.pool; sc_tmp = CTL_SOFTC(io); - memcpy(io, (void *)addr, sizeof(*io)); + memcpy(io, user_io, sizeof(*io)); io->io_hdr.pool = pool_tmp; CTL_SOFTC(io) = sc_tmp; TAILQ_INIT(&io->io_hdr.blocked_queue); @@ -637,7 +642,7 @@ ctl_ioctl_io(struct cdev *dev, u_long cmd, caddr_t addr, int flag, retval = cfi_submit_wait(io); if (retval == 0) - memcpy((void *)addr, io, sizeof(*io)); + memcpy(user_io, io, sizeof(*io)); ctl_free_io(io); return (retval); |
