svn commit: r359025 - stable/12/sys/dev/bnxt

Brooks Davis brooks at FreeBSD.org
Mon Mar 16 23:20:57 UTC 2020


Author: brooks
Date: Mon Mar 16 23:20:56 2020
New Revision: 359025
URL: https://svnweb.freebsd.org/changeset/base/359025

Log:
  MFC r358630:
  
  bnxt(4): Fix ioctls when user addresses are inaccessable.
  
  Check copyin's error code (differ adding copyout checks at this time).
  
  Don't directly access user memory in the switch statement.
  
  Since bnxt_ioctl_data isn't all that big, use a stack allocation.
  
  Reviewed by:	jhb
  Sponsored by:	DARPA
  Differential Revision:	https://reviews.freebsd.org/D23933

Modified:
  stable/12/sys/dev/bnxt/if_bnxt.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/dev/bnxt/if_bnxt.c
==============================================================================
--- stable/12/sys/dev/bnxt/if_bnxt.c	Mon Mar 16 23:15:20 2020	(r359024)
+++ stable/12/sys/dev/bnxt/if_bnxt.c	Mon Mar 16 23:20:56 2020	(r359025)
@@ -1638,25 +1638,26 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 {
 	struct bnxt_softc *softc = iflib_get_softc(ctx);
 	struct ifreq *ifr = (struct ifreq *)data;
-	struct ifreq_buffer *ifbuf = &ifr->ifr_ifru.ifru_buffer;
-	struct bnxt_ioctl_header *ioh =
-	    (struct bnxt_ioctl_header *)(ifbuf->buffer);
+	struct bnxt_ioctl_header *ioh;
+	size_t iol;
 	int rc = ENOTSUP;
-	struct bnxt_ioctl_data *iod = NULL;
+	struct bnxt_ioctl_data iod_storage, *iod = &iod_storage;
 
+
 	switch (command) {
 	case SIOCGPRIVATE_0:
 		if ((rc = priv_check(curthread, PRIV_DRIVER)) != 0)
 			goto exit;
 
-		iod = malloc(ifbuf->length, M_DEVBUF, M_NOWAIT | M_ZERO);
-		if (!iod) {
-			rc = ENOMEM;
+		ioh = ifr_buffer_get_buffer(ifr);
+		iol = ifr_buffer_get_length(ifr);
+		if (iol > sizeof(iod_storage))
+			return (EINVAL);
+
+		if ((rc = copyin(ioh, iod, iol)) != 0)
 			goto exit;
-		}
-		copyin(ioh, iod, ifbuf->length);
 
-		switch (ioh->type) {
+		switch (iod->hdr.type) {
 		case BNXT_HWRM_NVM_FIND_DIR_ENTRY:
 		{
 			struct bnxt_ioctl_hwrm_nvm_find_dir_entry *find =
@@ -1674,7 +1675,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1714,7 +1715,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 				remain -= csize;
 			}
 			if (iod->hdr.rc == 0)
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 
 			iflib_dma_free(&dma_data);
 			rc = 0;
@@ -1734,7 +1735,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1754,7 +1755,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1776,7 +1777,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1795,7 +1796,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1815,7 +1816,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1842,7 +1843,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 				copyout(dma_data.idi_vaddr, get->data,
 				    get->entry_length * get->entries);
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 			iflib_dma_free(&dma_data);
 
@@ -1863,7 +1864,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1885,7 +1886,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1904,7 +1905,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1925,7 +1926,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1946,7 +1947,7 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 			}
 			else {
 				iod->hdr.rc = 0;
-				copyout(iod, ioh, ifbuf->length);
+				copyout(iod, ioh, iol);
 			}
 
 			rc = 0;
@@ -1957,8 +1958,6 @@ bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t 
 	}
 
 exit:
-	if (iod)
-		free(iod, M_DEVBUF);
 	return rc;
 }
 


More information about the svn-src-all mailing list