vfio: fix read-after-free on getting container fd

Message ID 20181025104911.137496-1-dariusz.stojaczyk@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series vfio: fix read-after-free on getting container fd |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Stojaczyk, Dariusz Oct. 25, 2018, 10:49 a.m. UTC
  We were reading some memory just after freeing it.

Fixes: 83a73c5fef66 ("vfio: use generic multi-process channel")
Cc: jianfeng.tan@intel.com
Cc: anatoly.burakov@intel.com
Cc: stable@dpdk.org

Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_vfio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Anatoly Burakov Oct. 26, 2018, 2:04 p.m. UTC | #1
On 25-Oct-18 11:49 AM, Darek Stojaczyk wrote:
> We were reading some memory just after freeing it.
> 
> Fixes: 83a73c5fef66 ("vfio: use generic multi-process channel")
> Cc: jianfeng.tan@intel.com
> Cc: anatoly.burakov@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
> ---
>   lib/librte_eal/linuxapp/eal/eal_vfio.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> index d7268e4ce..fc3c7b870 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> @@ -1034,8 +1034,9 @@ rte_vfio_get_container_fd(void)
>   		mp_rep = &mp_reply.msgs[0];
>   		p = (struct vfio_mp_param *)mp_rep->param;
>   		if (p->result == SOCKET_OK && mp_rep->num_fds == 1) {
> +			vfio_container_fd = mp_rep->fds[0];
>   			free(mp_reply.msgs);
> -			return mp_rep->fds[0];
> +			return vfio_container_fd;
>   		}
>   		free(mp_reply.msgs);
>   	}
> 

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
Thomas Monjalon Oct. 29, 2018, 12:46 a.m. UTC | #2
26/10/2018 16:04, Burakov, Anatoly:
> On 25-Oct-18 11:49 AM, Darek Stojaczyk wrote:
> > We were reading some memory just after freeing it.
> > 
> > Fixes: 83a73c5fef66 ("vfio: use generic multi-process channel")
> > Cc: jianfeng.tan@intel.com
> > Cc: anatoly.burakov@intel.com
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
> 
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
index d7268e4ce..fc3c7b870 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -1034,8 +1034,9 @@  rte_vfio_get_container_fd(void)
 		mp_rep = &mp_reply.msgs[0];
 		p = (struct vfio_mp_param *)mp_rep->param;
 		if (p->result == SOCKET_OK && mp_rep->num_fds == 1) {
+			vfio_container_fd = mp_rep->fds[0];
 			free(mp_reply.msgs);
-			return mp_rep->fds[0];
+			return vfio_container_fd;
 		}
 		free(mp_reply.msgs);
 	}