From patchwork Mon Oct 25 12:56:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Cohen X-Patchwork-Id: 69093 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5C1DDB6F14 for ; Mon, 25 Oct 2010 23:56:29 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755465Ab0JYM4X (ORCPT ); Mon, 25 Oct 2010 08:56:23 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:56298 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755263Ab0JYM4W (ORCPT ); Mon, 25 Oct 2010 08:56:22 -0400 Received: by bwz11 with SMTP id 11so2312106bwz.19 for ; Mon, 25 Oct 2010 05:56:19 -0700 (PDT) Received: by 10.204.49.208 with SMTP id w16mr5232081bkf.35.1288011379335; Mon, 25 Oct 2010 05:56:19 -0700 (PDT) Received: from localhost ([82.166.227.17]) by mx.google.com with ESMTPS id t10sm4798471bkj.16.2010.10.25.05.56.17 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 25 Oct 2010 05:56:18 -0700 (PDT) Date: Mon, 25 Oct 2010 14:56:47 +0200 From: Eli Cohen To: davem@davemloft.net, yevgenyp@mellanox.co.il Cc: Roland Dreier , RDMA list , netdev@vger.kernel.org Subject: [PATCH] mlx4_en: Fix out of bounds array access Message-ID: <20101025125647.GA7710@mtldesk30> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When searching for a free entry in either mlx4_register_vlan() or mlx4_register_mac(), and there is no free entry, the loop terminates without updating the local variable free thus causing out of array bounds access. Fix this by adding a proper check outside the loop. Signed-off-by: Eli Cohen --- drivers/net/mlx4/port.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/drivers/net/mlx4/port.c b/drivers/net/mlx4/port.c index 56371ef..4513395 100644 --- a/drivers/net/mlx4/port.c +++ b/drivers/net/mlx4/port.c @@ -111,6 +111,12 @@ int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac, int *index) goto out; } } + + if (free < 0) { + err = -ENOMEM; + goto out; + } + mlx4_dbg(dev, "Free MAC index is %d\n", free); if (table->total == table->max) { @@ -224,6 +230,11 @@ int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index) } } + if (free < 0) { + err = -ENOMEM; + goto out; + } + if (table->total == table->max) { /* No free vlan entries */ err = -ENOSPC;