netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] mlx5: use after free in mlx5_cmd_comp_handler()
@ 2013-07-22  8:02 Dan Carpenter
  2013-07-24 16:35 ` Eli Cohen
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2013-07-22  8:02 UTC (permalink / raw)
  To: Eli Cohen
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

We can't dereference "ent" after passing it to free_cmd().

Signed-off-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 205753a..4037406 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -1113,7 +1113,13 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
 
 	for (i = 0; i < (1 << cmd->log_sz); i++) {
 		if (test_bit(i, &vector)) {
+			struct semaphore *sem;
+
 			ent = cmd->ent_arr[i];
+			if (ent->page_queue)
+				sem = &cmd->pages_sem;
+			else
+				sem = &cmd->sem;
 			ktime_get_ts(&ent->ts2);
 			memcpy(ent->out->first.data, ent->lay->out, sizeof(ent->lay->out));
 			dump_command(dev, ent, 0);
@@ -1136,10 +1142,7 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
 			} else {
 				complete(&ent->done);
 			}
-			if (ent->page_queue)
-				up(&cmd->pages_sem);
-			else
-				up(&cmd->sem);
+			up(sem);
 		}
 	}
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [patch] mlx5: use after free in mlx5_cmd_comp_handler()
  2013-07-22  8:02 [patch] mlx5: use after free in mlx5_cmd_comp_handler() Dan Carpenter
@ 2013-07-24 16:35 ` Eli Cohen
  2013-07-24 22:45   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Cohen @ 2013-07-24 16:35 UTC (permalink / raw)
  To: Dan Carpenter, moshel; +Cc: Eli Cohen, netdev, linux-rdma, kernel-janitors

This race has been spotted and fixed by Moshe Lazer two weeks ago.
Anyways,

Acked by Eli Cohen <eli@mellanox.com>

On Mon, Jul 22, 2013 at 11:02:01AM +0300, Dan Carpenter wrote:
> We can't dereference "ent" after passing it to free_cmd().
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> index 205753a..4037406 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> @@ -1113,7 +1113,13 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
>  
>  	for (i = 0; i < (1 << cmd->log_sz); i++) {
>  		if (test_bit(i, &vector)) {
> +			struct semaphore *sem;
> +
>  			ent = cmd->ent_arr[i];
> +			if (ent->page_queue)
> +				sem = &cmd->pages_sem;
> +			else
> +				sem = &cmd->sem;
>  			ktime_get_ts(&ent->ts2);
>  			memcpy(ent->out->first.data, ent->lay->out, sizeof(ent->lay->out));
>  			dump_command(dev, ent, 0);
> @@ -1136,10 +1142,7 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
>  			} else {
>  				complete(&ent->done);
>  			}
> -			if (ent->page_queue)
> -				up(&cmd->pages_sem);
> -			else
> -				up(&cmd->sem);
> +			up(sem);
>  		}
>  	}
>  }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] mlx5: use after free in mlx5_cmd_comp_handler()
  2013-07-24 16:35 ` Eli Cohen
@ 2013-07-24 22:45   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2013-07-24 22:45 UTC (permalink / raw)
  To: eli-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb
  Cc: dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA,
	moshel-VPRAkNaXOzVWk0Htik3J/w, eli-VPRAkNaXOzVWk0Htik3J/w,
	netdev-u79uwXL29TY76Z2rM5mHXA, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

From: Eli Cohen <eli-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
Date: Wed, 24 Jul 2013 19:35:44 +0300

> This race has been spotted and fixed by Moshe Lazer two weeks ago.
> Anyways,
> 
> Acked by Eli Cohen <eli-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-24 22:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-22  8:02 [patch] mlx5: use after free in mlx5_cmd_comp_handler() Dan Carpenter
2013-07-24 16:35 ` Eli Cohen
2013-07-24 22:45   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).