Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1524775img; Tue, 19 Mar 2019 09:25:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwganJzhD0dDBlY3iKTIZz8BBrfLZju+mBuMWbcRxZt4fv+lQ/F9rxXCfEY16gqwfg5uQrF X-Received: by 2002:a17:902:f095:: with SMTP id go21mr25797210plb.199.1553012740380; Tue, 19 Mar 2019 09:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553012740; cv=none; d=google.com; s=arc-20160816; b=YiTr7pWQ8XYnc9/nxzNvCDcaLRmFZWDG4MiTDaGrcQeLs2LtXUX0QHmcO3NSb+ECog yi8AKielbc5Wc4QuKsQ48WJ4S6eKkc8ukYUY1p31Ux/QhEOY3zvnqaJfL1pCl299+Sfi Ba5KN87k8DBaeIn50NDZ0j64Emd4OAs5ZLYRcqRCsJy/01bfrVyZdprmKdpwexmhHtF6 veDKxZ4d7dDpNXoQNt0QNWucatNMRZo6SoElkg2DRfyc/Cz1OjDHStyKQCOChM1TDxHA 73ivC5Qb19q4O6I8QqzzeV3Hh80q9rcW3NJg5oRcCqKKi1qpeP3bAPg+6uD3bMyCW2xf r/cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=0R6wmKmuCV/v68BfRZs1XhLMkHB4bEg8KvGWPZiRy/s=; b=x+I37zpbmKlGiNhLMkl1w23NfyVosNHJbXmfFgERmNd1gq3h7o4f6uf5HBVhn/zCOw WiUDYp8FKmKFM7jqY+g/vSlzB6c8w9a8MEvGhDopmu9uNyYB33JcCb45guqyszHS2G9S ZQV1IXTG5k9FtZqxHtiKlxH6bXM1W3N2gsg4Hh7pHMlcCFGAA+FbFP6fqpurBKcGM2FV +f1h2k0LcvRcbq7yhA39bPv0k1JHQykUCqRVQ8dBje/TFPxb0ftatddNCplY218EC4+c i+/vVZvHfJtgyILb9bHmFd4wzwpe94gLwbU8hBetjRVtwuqN4lXY078g44VvH4juxUU4 VeAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=HI+uK3Ue; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2si12000992plo.272.2019.03.19.09.25.25; Tue, 19 Mar 2019 09:25:40 -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=@umn.edu header.s=google header.b=HI+uK3Ue; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727918AbfCSQYP (ORCPT + 99 others); Tue, 19 Mar 2019 12:24:15 -0400 Received: from mta-p8.oit.umn.edu ([134.84.196.208]:34666 "EHLO mta-p8.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727810AbfCSQYN (ORCPT ); Tue, 19 Mar 2019 12:24:13 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p8.oit.umn.edu (Postfix) with ESMTP id 263D0150 for ; Tue, 19 Mar 2019 16:24:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p8.oit.umn.edu ([127.0.0.1]) by localhost (mta-p8.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nXEXkEGM6-ES for ; Tue, 19 Mar 2019 11:24:12 -0500 (CDT) Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p8.oit.umn.edu (Postfix) with ESMTPS id F265313D for ; Tue, 19 Mar 2019 11:24:11 -0500 (CDT) Received: by mail-io1-f72.google.com with SMTP id z6so16142180ioh.16 for ; Tue, 19 Mar 2019 09:24:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=0R6wmKmuCV/v68BfRZs1XhLMkHB4bEg8KvGWPZiRy/s=; b=HI+uK3Uej3cavH6sZzy2MyPaxX5RirHln3IcweIr6ct1TmoKvd+yW8ppLNgR+IAVVu BdPFrIU5K8foCNEBX3Vuaji4ZFpUN0GK4EjXsVoQCGcOp79sWvJSjnWG7bMP3XDEiOt9 D7ycAQqYICY6eW0teK3/zEP9DXNkw1sAtMHS8clQHujt++EFAfYC6Jz1ChU4k1A29Sgn RcinQQGsn0EuyrD8LBHz0iez1WD9PZt2y+ewtuXnjaMwKs6PDU59xRpJkrJ2mVrbZoqO VRvwT17JiszwGqsDmwWPHluIJrseArWXrMwsHNda1mdfT51XU75L8WueFO7FERrqMrL8 vInw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0R6wmKmuCV/v68BfRZs1XhLMkHB4bEg8KvGWPZiRy/s=; b=gxTUJImbmU8ult1NvQHoYJQFmYo2OOqFoux4AKprnGHh91zf46+D55SqXPAiVQZFGz Gzp9+0Nth52hEWgKdLC+Nf75tOH08RMZVRbixlvATIjpZHG1tC6WJ+/9H3sk0qmnWj9F MMWkne8MC9pY94pArCZEShnbcFVLkWVGtpA7czYXlWwJRxJ8HPqSrXj5P+7kuV1d78FV c7oa73Qy9qRKPdCF/mkEpsWNi5vP9NZdRqg35LmpvWqsvs+UngPldYVSxUDE7dHp/TEd DgM9/DKqqWssYuwWY/Xw8AoPyVAivc7whzEvrUx1erT5x2Ey7Ksbz0NncJ7e50laYzcJ xVqQ== X-Gm-Message-State: APjAAAXqwBFzTV3W6Du+CPLJZqhC2ojSTLz3/bptSKUyXlWks6+i+Gz8 finW9670yoYky2a9suf5L91aaxtQ/hRORyANdq49olWMdC/WCCfTCqZPa5/lXH1zkhEvlri/vCH ShBjo1rJRG8mpzZwo9hwU5o7pY0bv X-Received: by 2002:a24:678f:: with SMTP id u137mr1809098itc.126.1553012650823; Tue, 19 Mar 2019 09:24:10 -0700 (PDT) X-Received: by 2002:a24:678f:: with SMTP id u137mr1809082itc.126.1553012650647; Tue, 19 Mar 2019 09:24:10 -0700 (PDT) Received: from cs-u-syssec1.dtc.umn.edu (cs-u-syssec1.cs.umn.edu. [128.101.106.66]) by smtp.gmail.com with ESMTPSA id p79sm1707330itb.7.2019.03.19.09.24.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Mar 2019 09:24:09 -0700 (PDT) From: Aditya Pakki To: pakki001@umn.edu Cc: kjlu@umn.edu, Boris Pismenny , Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Ilya Lesokhin , Wei Yongjun , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] net: mlx5: Add a missing check on idr_find, free buf Date: Tue, 19 Mar 2019 11:24:02 -0500 Message-Id: <20190319162406.7525-1-pakki001@umn.edu> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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') v2: failure to return in case of flow failure. v1: Failed to free buf in case of flow failure. Signed-off-by: Aditya Pakki --- drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c b/drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c index 5cf5f2a9d51f..224e0d7f6489 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c @@ -226,6 +226,11 @@ int mlx5_fpga_tls_resync_rx(struct mlx5_core_dev *mdev, u32 handle, u32 seq, 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"); + kfree(buf); + return -EINVAL; + } mlx5_fpga_tls_flow_to_cmd(flow, cmd); MLX5_SET(tls_cmd, cmd, swid, ntohl(handle)); @@ -238,6 +243,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.17.1