Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3333447imu; Sun, 11 Nov 2018 12:35:21 -0800 (PST) X-Google-Smtp-Source: AJdET5d9pU5DUU2tsUrDoi40/fDpolfTZvBYeITivlm48Oxa/Utx5e7CtArlGhPT9vB25qLr/rph X-Received: by 2002:a62:cf02:: with SMTP id b2-v6mr17572714pfg.224.1541968521414; Sun, 11 Nov 2018 12:35:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968521; cv=none; d=google.com; s=arc-20160816; b=L/h+KwH43tnRR77nNULWk1AN98xWvjMzPmHSX8DBh/EdLLOyaCOBEAeTNWFMa73Oz3 fxzQQf3vjW/z6urI9b5XllgehEMUtxW7IoKKYk+vdzzlRj7n/i2EVnaJ3HgvQwdHmkLU yKmh0PBSZ/UgCjsVRXDFIlWIsK/KcZwNM0JmaxwFMh41oxeDqfkepc6hLGovjesKfJcY Fd42sOfI5KY38eLpFuvbWryXpLFg/j4yy7rZ+pcbnPBuUrwpDmKySHdUBVyvINELxraz s8KD+HltGFwl50GvA/cbutTe4VIEbc93RRXebDj9ZcTSZBxmCU0oWYDH35EommYb+Uoh hU7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=iWsaTBTjLDI7Nxlo9A9gz5unO9EZRWaQlyIiNQBSQNQ=; b=flV67NJBj0a8Gec4Z1qf9rvWdzSzSmDIAgokGateihDpLLo81Vdd2+R0SIGjZ8IThC 7p+OTFATHi0jhzzhbDVMMdGMMlHEqEUkS7ILZ9cDU6tAideN0pXUDEmN7T3i7fKP8Ekg 5/4SqsVtzeqD1pxwmG9jLubjQ+pnDFUBpylhb4xtHrczZZCUcnYbS3tTzEbDgX2psZvY y7gNLw/LeVqlp5HP1q8U2ldGx/tIT6DcL8acxFKzNmZENtAaQSpFlGyZ54+Dv8oQSaTs M8ImWs5ZJtGEtKa/mt0UVXFAMfVlKRkKzeJSM3YVxG0crCv4YeOoqNPYQYe1GpTjOHVa hh8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si15833771plj.146.2018.11.11.12.35.06; Sun, 11 Nov 2018 12:35:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730233AbeKLFsO (ORCPT + 99 others); Mon, 12 Nov 2018 00:48:14 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:49906 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730184AbeKLFsN (ORCPT ); Mon, 12 Nov 2018 00:48:13 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsZ-0000l8-91; Sun, 11 Nov 2018 19:58:43 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsW-0001ie-6T; Sun, 11 Nov 2018 19:58:40 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Leon Romanovsky" , "Jason Gunthorpe" , "Kamal Heib" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 246/366] RDMA/mlx5: Fix memory leak in mlx5_ib_create_srq() error path In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Kamal Heib commit d63c46734c545ad0488761059004a65c46efdde3 upstream. Fix memory leak in the error path of mlx5_ib_create_srq() by making sure to free the allocated srq. Fixes: c2b37f76485f ("IB/mlx5: Fix integer overflows in mlx5_ib_create_srq") Signed-off-by: Kamal Heib Acked-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/infiniband/hw/mlx5/srq.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) --- a/drivers/infiniband/hw/mlx5/srq.c +++ b/drivers/infiniband/hw/mlx5/srq.c @@ -261,18 +261,24 @@ struct ib_srq *mlx5_ib_create_srq(struct desc_size = sizeof(struct mlx5_wqe_srq_next_seg) + srq->msrq.max_gs * sizeof(struct mlx5_wqe_data_seg); - if (desc_size == 0 || srq->msrq.max_gs > desc_size) - return ERR_PTR(-EINVAL); + if (desc_size == 0 || srq->msrq.max_gs > desc_size) { + err = -EINVAL; + goto err_srq; + } desc_size = roundup_pow_of_two(desc_size); desc_size = max_t(size_t, 32, desc_size); - if (desc_size < sizeof(struct mlx5_wqe_srq_next_seg)) - return ERR_PTR(-EINVAL); + if (desc_size < sizeof(struct mlx5_wqe_srq_next_seg)) { + err = -EINVAL; + goto err_srq; + } srq->msrq.max_avail_gather = (desc_size - sizeof(struct mlx5_wqe_srq_next_seg)) / sizeof(struct mlx5_wqe_data_seg); srq->msrq.wqe_shift = ilog2(desc_size); buf_size = srq->msrq.max * desc_size; - if (buf_size < desc_size) - return ERR_PTR(-EINVAL); + if (buf_size < desc_size) { + err = -EINVAL; + goto err_srq; + } if (pd->uobject) err = create_srq_user(pd, srq, &in, udata, buf_size, &inlen);