Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2461701yba; Mon, 15 Apr 2019 12:08:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4CkToaoNAVj2zSz9y+IYpqE4FVzuHk69O8jTkFc0CL849Cli9pgrT3JMEJQc+k2m5o58M X-Received: by 2002:a63:1548:: with SMTP id 8mr67204376pgv.277.1555355311532; Mon, 15 Apr 2019 12:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555355311; cv=none; d=google.com; s=arc-20160816; b=xeRBfXWRyR4JP/jooUptoYPfmNEKO8ydvIlQpF9uTeOyKwOrE+SkmOTRuFrJPDL0/m WB/63cpt7v+fvVZ7Pz8CJeRt6NRotPgJPQ7BGsUEs41XFfixswhV3omirli24NQXGnRq UL0EOcstrT6M4Oond883kOl+jgqyv0/cL5eN8ThvI7N2mUvNu3b8zgLpNZeDJHNazZte 6Xqk7wS2+Ad6Uy2vGyQEJyPqj9KdODqYAvbcFOP5KdZPPbEB9bgnQMyt8mJQl1O23hGA pOoRLyg+gt3W78LKHxFiH149Co4DKkJ3BBslLuXfgTxHCzKk3dMEB+ojXpLCpiGeu+ex sOow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=m1tO5RWJZ9jcCDntnsjzgJRJ0oZr1TkviaqccJlY45Y=; b=uMX8wez/Z2V3f4acy0RyBzrVZ58l1ODz8PZSSS3y2ZBFS38ci8ty45NEDuFxJIS4F1 763bGcsDSBwtrw2IQ+hTp2Cqn93X9g4Ry70nNXTjOKgsuI1wc+vAm0Vp6eN2xvfvpAS/ Dkkm3aUP3QQxJxYQN+NbTHcB38VgfQSJ1Ka4g8HH+3a11RaiQa41Y8lRe4wLD6S7kOrI fMG4uv316aT/MzBnynpAPVUkqPb1aDWRPJIq94th9ZsB1PgKo7NeFZAakXKmEEHdorYh iZaJoGa88tkCiz1Nrg+IPztgLKzTI1t/alp/XVW3Lmmic/W6ePq66ATFGvGcvzHGxEAj b2Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YBf9ifBm; 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 l2si23801128pgq.416.2019.04.15.12.08.15; Mon, 15 Apr 2019 12:08:31 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=YBf9ifBm; 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 S1730069AbfDOTGx (ORCPT + 99 others); Mon, 15 Apr 2019 15:06:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:41424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729549AbfDOTGt (ORCPT ); Mon, 15 Apr 2019 15:06:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9218B20880; Mon, 15 Apr 2019 19:06:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355209; bh=hOsCECJ07xbXv10S38bu15xNKvNguZNDQuM2QRopsNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YBf9ifBm/V7BhgCYdYS8pxoiWiR6YLVh/i1VWnZ3I6wUfciQGDG65p07ewmpi5y5n w1hvjpwYiwGLlSCrrEgEOygvDXd1cauciF6guYwk4QxtxnHzF4MnfhpZnu2dJi4hm+ 53VoMeSjwTXl2XP8Vu6xrxh+PAdwyBBKplueF1uo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aditya Pakki , Yuval Shaia , Saeed Mahameed , Sasha Levin Subject: [PATCH 4.19 034/101] net: mlx5: Add a missing check on idr_find, free buf Date: Mon, 15 Apr 2019 20:58:32 +0200 Message-Id: <20190415183742.266383913@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183740.341577907@linuxfoundation.org> References: <20190415183740.341577907@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 8e949363f017e2011464812a714fb29710fb95b4 ] idr_find() can return a NULL value to 'flow' which is used without a check. The patch adds a check to avoid potential NULL pointer dereference. In case of mlx5_fpga_sbu_conn_sendmsg() failure, free buf allocated using kzalloc. Fixes: ab412e1dd7db ("net/mlx5: Accel, add TLS rx offload routines") Signed-off-by: Aditya Pakki Reviewed-by: Yuval Shaia Signed-off-by: Saeed Mahameed Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c b/drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c index 5cf5f2a9d51f..8de64e88c670 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c @@ -217,15 +217,21 @@ int mlx5_fpga_tls_resync_rx(struct mlx5_core_dev *mdev, u32 handle, u32 seq, void *cmd; int ret; + rcu_read_lock(); + flow = idr_find(&mdev->fpga->tls->rx_idr, ntohl(handle)); + rcu_read_unlock(); + + if (!flow) { + WARN_ONCE(1, "Received NULL pointer for handle\n"); + return -EINVAL; + } + buf = kzalloc(size, GFP_ATOMIC); if (!buf) return -ENOMEM; cmd = (buf + 1); - rcu_read_lock(); - flow = idr_find(&mdev->fpga->tls->rx_idr, ntohl(handle)); - rcu_read_unlock(); mlx5_fpga_tls_flow_to_cmd(flow, cmd); MLX5_SET(tls_cmd, cmd, swid, ntohl(handle)); @@ -238,6 +244,8 @@ int mlx5_fpga_tls_resync_rx(struct mlx5_core_dev *mdev, u32 handle, u32 seq, buf->complete = mlx_tls_kfree_complete; ret = mlx5_fpga_sbu_conn_sendmsg(mdev->fpga->tls->conn, buf); + if (ret < 0) + kfree(buf); return ret; } -- 2.19.1