From patchwork Fri Oct 8 14:25:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 241411 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o98EQBM2016866 for ; Fri, 8 Oct 2010 14:26:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754938Ab0JHO0J (ORCPT ); Fri, 8 Oct 2010 10:26:09 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:38060 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757899Ab0JHO0I (ORCPT ); Fri, 8 Oct 2010 10:26:08 -0400 Received: by wyb28 with SMTP id 28so1135269wyb.19 for ; Fri, 08 Oct 2010 07:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=UAGO2+ZBZwEY5HgjQoh9yvf8/Y2s8R+NwY/XFTsF+DU=; b=wfyl0Bn4MyrSiq4H8yBAAPE4NaG98gLxKHmT1g7NYXnu2XVRWY22xqtEnC+y/AF0gG MA2jvlEUS+uJxb1Ioh89qO1YOhVtgEKeCNgmYBu1xoMxaPPZTWLniGhZJ4U/0FHKSBl3 FoyN6bGqw/VcEDtRRjBz9k+iQanuOPcBqbNhI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=c6Z+89aLB+8vTJFXWDNob1WrrABZdvTKXbMQrTaEh/frutv+uyRTYzbDgLTaPPQzLN QxMHQwikfoaxQgVGNP7HoSjh07xrnqxLroaX8UUtzkylarRkALMtGarbl63fDJ7FuNpw NRKjFpdbkjAmR+WNfzZPrWWxIWcY5li8WwBx4= Received: by 10.216.165.77 with SMTP id d55mr2330305wel.23.1286547966727; Fri, 08 Oct 2010 07:26:06 -0700 (PDT) Received: from bicker ([41.191.79.62]) by mx.google.com with ESMTPS id p45sm2290765weq.21.2010.10.08.07.26.03 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 08 Oct 2010 07:26:06 -0700 (PDT) Date: Fri, 8 Oct 2010 16:25:58 +0200 From: Dan Carpenter To: Nicolas Palix Cc: Jason Gunthorpe , Roland Dreier , Sean Hefty , Hal Rosenstock , linux-rdma , kernel-janitors Subject: [patch v2] infiniband: uverbs: limit the number of entries Message-ID: <20101008142557.GP11681@bicker> References: <20101007071610.GC11681@bicker> <20101007161649.GD21206@obsidianresearch.com> <20101007165947.GD11681@bicker> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 08 Oct 2010 14:26:12 +0000 (UTC) diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h --- a/drivers/infiniband/core/uverbs.h +++ b/drivers/infiniband/core/uverbs.h @@ -162,6 +162,7 @@ void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr); void ib_uverbs_event_handler(struct ib_event_handler *handler, struct ib_event *event); +#define UVERBS_MAX_NUM_ENTRIES 500 #define IB_UVERBS_DECLARE_CMD(name) \ ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \ const char __user *buf, int in_len, \ diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -906,12 +906,15 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; + if (cmd.ne > UVERBS_MAX_NUM_ENTRIES) + cmd.ne = UVERBS_MAX_NUM_ENTRIES; + - wc = kmalloc(cmd.ne * sizeof *wc, GFP_KERNEL); + wc = kcalloc(cmd.ne, sizeof *wc, GFP_KERNEL); if (!wc) return -ENOMEM; rsize = sizeof *resp + cmd.ne * sizeof(struct ib_uverbs_wc); - resp = kmalloc(rsize, GFP_KERNEL); + resp = kzalloc(rsize, GFP_KERNEL); if (!resp) { ret = -ENOMEM; goto out_wc;