From patchwork Tue Mar 12 11:03:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 2255271 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 3205BDF23A for ; Tue, 12 Mar 2013 11:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755235Ab3CLLEq (ORCPT ); Tue, 12 Mar 2013 07:04:46 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:33194 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754512Ab3CLLEq (ORCPT ); Tue, 12 Mar 2013 07:04:46 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r2CB4eVX027845 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Mar 2013 11:04:41 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r2CB4eD0017681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 12 Mar 2013 11:04:40 GMT Received: from abhmt108.oracle.com (abhmt108.oracle.com [141.146.116.60]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r2CB4ev8027779; Tue, 12 Mar 2013 06:04:40 -0500 Received: from longonot.mountain (/41.202.240.13) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 12 Mar 2013 04:04:39 -0700 Date: Tue, 12 Mar 2013 14:03:07 +0300 From: Dan Carpenter To: Mike Marciniszyn Cc: Roland Dreier , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] IB/ipath: add a range check before bumping the stats Message-ID: <20130312110307.GA22921@longonot.mountain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org My static checker complains that this could corrupt memory. It seems valid to add a range check here. Signed-off-by: Dan Carpenter --- I can't test this. -- 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 diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c index 439c35d..f15dd70 100644 --- a/drivers/infiniband/hw/ipath/ipath_verbs.c +++ b/drivers/infiniband/hw/ipath/ipath_verbs.c @@ -621,6 +621,10 @@ void ipath_ib_rcv(struct ipath_ibdev *dev, void *rhdr, void *data, } opcode = be32_to_cpu(ohdr->bth[0]) >> 24; + if (opcode >= ARRAY_SIZE(dev->opstats)) { + dev->rcv_errors++; + goto bail; + } dev->opstats[opcode].n_bytes += tlen; dev->opstats[opcode].n_packets++;