Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178224277
D60333.1796280754.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
D60333.1796280754.diff
View Options
Index: sys/dev/mpi3mr/mpi3mr_app.c
===================================================================
--- sys/dev/mpi3mr/mpi3mr_app.c
+++ sys/dev/mpi3mr/mpi3mr_app.c
@@ -374,7 +374,7 @@
if (bus_dma_tag_create(sc->mpi3mr_parent_dmat, /* parent */
4, 0, /* algnmnt, boundary */
sc->dma_loaddr, /* lowaddr */
- BUS_SPACE_MAXADDR, /* highaddr */
+ sc->dma_hiaddr, /* highaddr */
NULL, NULL, /* filter, filterarg */
dev_pgsz, /* maxsize */
1, /* nsegments */
@@ -577,11 +577,11 @@
+ */
static int mpi3mr_map_data_buffer_dma(struct mpi3mr_softc *sc,
struct mpi3mr_ioctl_mpt_dma_buffer *dma_buffers,
- U8 desc_count)
+ U16 desc_count)
{
U16 i, needed_desc = (dma_buffers->kern_buf_len / MPI3MR_IOCTL_SGE_SIZE);
U32 buf_len = dma_buffers->kern_buf_len, copied_len = 0;
- int error;
+ int error = 0;
if (dma_buffers->kern_buf_len % MPI3MR_IOCTL_SGE_SIZE)
needed_desc++;
@@ -597,7 +597,6 @@
if (!dma_buffers->dma_desc)
return -1;
- error = 0;
for (i = 0; i < needed_desc; i++, desc_count++) {
dma_buffers->dma_desc[i].addr = sc->ioctl_sge[desc_count].addr;
@@ -620,9 +619,11 @@
copied_len += dma_buffers->dma_desc[i].size;
}
}
+
if (error != 0) {
printf("%s: DMA copyin error %d\n", __func__, error);
free(dma_buffers->dma_desc, M_MPI3MR);
+ dma_buffers->dma_desc = NULL;
return -1;
}
@@ -795,6 +796,7 @@
/**
* mpi3mr_app_mptcmds - MPI Pass through IOCTL handler
+ * @sc: Adapter reference, already resolved by the caller
* @dev: char device
* @cmd: IOCTL command
* @arg: User data payload buffer for the IOCTL
@@ -815,8 +817,8 @@
* Return: 0 on success and proper error codes on failure
*/
static long
-mpi3mr_app_mptcmds(struct cdev *dev, u_long cmd, void *uarg,
- int flag, struct thread *td)
+mpi3mr_app_mptcmds(struct mpi3mr_softc *sc, struct cdev *dev, u_long cmd,
+ void *uarg, int flag, struct thread *td)
{
long rval = EINVAL;
U8 count, bufcnt = 0, is_rmcb = 0, is_rmrb = 0, din_cnt = 0, dout_cnt = 0;
@@ -829,7 +831,6 @@
Mpi3RequestHeader_t *mpi_header = NULL;
Mpi3PELReqActionGetCount_t *pel = NULL;
Mpi3StatusReplyDescriptor_t *status_desc = NULL;
- struct mpi3mr_softc *sc = NULL;
struct mpi3mr_ioctl_buf_entry_list *buffer_list = NULL;
struct mpi3mr_buf_entry *buf_entries = NULL;
struct mpi3mr_ioctl_mpt_dma_buffer *dma_buffers = NULL, *dma_buff = NULL;
@@ -838,11 +839,6 @@
struct mpi3mr_target *tgtdev = NULL;
Mpi3SCSITaskMgmtRequest_t *tm_req = NULL;
-
- sc = mpi3mr_app_get_adp_instance(karg->mrioc_id);
- if (!sc)
- return ENODEV;
-
if (!sc->ioctl_sges_allocated) {
printf("%s: DMA memory was not allocated\n", __func__);
return ENOMEM;
@@ -891,6 +887,12 @@
rval = EFAULT;
goto out;
}
+ if (karg->buf_entry_list_size < sizeof(struct mpi3mr_ioctl_buf_entry_list)) {
+ printf(IOCNAME "%s:%d buf_entry_list_size %u too small for header\n",
+ sc->name, __func__, __LINE__, karg->buf_entry_list_size);
+ rval = EINVAL;
+ goto out;
+ }
if (!buffer_list->num_of_buf_entries) {
printf(IOCNAME "%s:%d Invalid IOCTL parameters passed\n", sc->name,
__func__, __LINE__);
@@ -898,6 +900,13 @@
goto out;
}
bufcnt = buffer_list->num_of_buf_entries;
+ if (karg->buf_entry_list_size < (sizeof(struct mpi3mr_ioctl_buf_entry_list) +
+ (U32)(bufcnt - 1) * sizeof(struct mpi3mr_buf_entry))) {
+ printf(IOCNAME "%s:%d buf_entry_list_size %u too small for %u entries\n",
+ sc->name, __func__, __LINE__, karg->buf_entry_list_size, bufcnt);
+ rval = EINVAL;
+ goto out;
+ }
dma_buffers = malloc((sizeof(*dma_buffers) * bufcnt), M_MPI3MR, M_NOWAIT | M_ZERO);
if (!dma_buffers) {
printf(IOCNAME "%s: memory allocation failed for dma_buffers\n", sc->name,
@@ -1710,8 +1719,7 @@
return EAGAIN;
}
- if ((data_out_sz != sizeof(pel_enable) ||
- (pel_enable.pel_class > MPI3_PEL_CLASS_FAULT))) {
+ if (data_out_sz != sizeof(pel_enable)) {
printf(IOCNAME "%s: Invalid user pel_enable buffer size %u\n",
sc->name, __func__, data_out_sz);
goto out;
@@ -1927,12 +1935,12 @@
struct mpi3mr_cam_softc *cam_sc = sc->cam_sc;
struct mpi3mr_ioctl_all_tgtinfo *all_tgtinfo = (struct mpi3mr_ioctl_all_tgtinfo *)data_in_buf;
- if (data_in_sz < sizeof(uint32_t)) {
+ if (data_in_sz < offsetof(struct mpi3mr_ioctl_all_tgtinfo, dmi)) {
printf(IOCNAME "failure at %s:%d/%s()!\n", sc->name, __FILE__,
__LINE__, __func__);
goto out;
}
- if (data_in_sz == sizeof(uint32_t))
+ if (data_in_sz == offsetof(struct mpi3mr_ioctl_all_tgtinfo, dmi))
get_count = 1;
if (TAILQ_EMPTY(&cam_sc->tgt_list)) {
@@ -1965,7 +1973,7 @@
if (i < num_devices) {
devmap_info[i].handle = tgtdev->dev_handle;
devmap_info[i].per_id = tgtdev->per_id;
- /*n
+ /*
* For hidden/ugood device the target_id and bus_id should be 0xFFFFFFFF and 0xFF
*/
if (!tgtdev->exposed_to_os) {
@@ -1988,7 +1996,8 @@
rval = EFAULT;
goto out;
}
- user_entrylen = (data_in_sz - sizeof(uint32_t))/sizeof(*devmap_info);
+ user_entrylen = (data_in_sz - offsetof(struct mpi3mr_ioctl_all_tgtinfo, dmi)) /
+ sizeof(*devmap_info);
user_entrylen *= sizeof(*devmap_info);
min_entrylen = min(user_entrylen, kern_entrylen);
if (min_entrylen && (copyout(devmap_info, &all_tgtinfo->dmi, min_entrylen))) {
@@ -2164,6 +2173,7 @@
}
/**
* mpi3mr_app_drvrcmds - Driver IOCTL handler
+ * @sc: Adapter reference, already resolved by the caller
* @dev: char device
* @cmd: IOCTL command
* @arg: User data payload buffer for the IOCTL
@@ -2178,17 +2188,12 @@
*/
static int
-mpi3mr_app_drvrcmds(struct cdev *dev, u_long cmd,
+mpi3mr_app_drvrcmds(struct mpi3mr_softc *sc, struct cdev *dev, u_long cmd,
void *uarg, int flag, struct thread *td)
{
long rval = EINVAL;
- struct mpi3mr_softc *sc = NULL;
struct mpi3mr_ioctl_drvcmd *karg = (struct mpi3mr_ioctl_drvcmd *)uarg;
- sc = mpi3mr_app_get_adp_instance(karg->mrioc_id);
- if (!sc)
- return ENODEV;
-
mtx_lock(&sc->ioctl_cmds.completion.lock);
switch (karg->opcode) {
case MPI3MR_DRVRIOCTL_OPCODE_ADPINFO:
@@ -2252,11 +2257,11 @@
switch (cmd) {
case MPI3MRDRVCMD:
- rval = mpi3mr_app_drvrcmds(dev, cmd, arg, flag, td);
+ rval = mpi3mr_app_drvrcmds(sc, dev, cmd, arg, flag, td);
break;
case MPI3MRMPTCMD:
mtx_lock(&sc->ioctl_cmds.completion.lock);
- rval = mpi3mr_app_mptcmds(dev, cmd, arg, flag, td);
+ rval = mpi3mr_app_mptcmds(sc, dev, cmd, arg, flag, td);
mtx_unlock(&sc->ioctl_cmds.completion.lock);
break;
default:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 3, 6:52 AM (20 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42174606
Default Alt Text
D60333.1796280754.diff (6 KB)
Attached To
Mode
D60333: mpi3mr: Validate buffer entry sizes and descriptor counts in MPT IOCTLs
Attached
Detach File
Event Timeline