Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1500725img; Tue, 19 Mar 2019 08:56:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqylk8FaL5dHeSF+MP/AM78X2pZKKk8S5DUxhVqFizz/wVstzmTl6wm0pFSHlJXBclKVTIUW X-Received: by 2002:a63:6903:: with SMTP id e3mr23661445pgc.147.1553011012075; Tue, 19 Mar 2019 08:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553011012; cv=none; d=google.com; s=arc-20160816; b=jWUFK++VDkoXJajQs3nQBLh74A/9DRknJgY6rRsf780vDCp4kDkfTcD2n9ALahCna+ lcFrc1tZ3IYgoTzfRuD/0ZJyqp+cSuomIjnREU+C3tqsCqND04Dyro1erguxEZ3A5e1g w3TxHE6WtImhhXzEcW0BtEhOFmJxw3rxxbAUh05pSVvhcJk6WoRUv5o4Yg6KZIAiHayl 7A07NaoqLx3lTX4UmH2AHSJ9A80QcBP6MopFGzWvwf6ETbS35o6JBb+371GYFVPyRDWk VZWx9MbqE4JZU/Nco0LY1KiN6MC5SAN1g9Ot4yE7uFUoRD0YgMoWdsPdbJ+LNZcdF5GT gXLA== 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=B1QWfeXYOX77KfMW/kAokzeu80UhNz+WjOFEKWzCLx8=; b=CWnXUnqjsDcN6tKrPFWXFg6rlMpTGf5jcrGttOhR0gOnHFXOf8RMqpsQs3RrkRFL6m kZFfd84/5WO+/51Vz8L+9ZwxvdLXjLt3TYPr5aHxh3icT+p39gcoT4Ak2AhdYj2JGNmX YDupmcTSjbKsGDa+FBqZbbZ07KEQnk6zsiSZZGBuwCieAI4cjXm7QIRB7jfUB9a5Zq77 qGasaUt+Q4MHhHre3l/aM+4A7hQtVqrxdtNLrg6CX5Hoz44Yd6EXdMD3+QaT0ZqJdKtk u0yI3+IquyFvODptitxrGYQZvqdHizdOYhPpnq698sIr7UfK59YTFAyAe9iiewY644MX 43jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=YhMPNTI4; 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 k33si11259786pld.388.2019.03.19.08.56.36; Tue, 19 Mar 2019 08:56:52 -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=YhMPNTI4; 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 S1727857AbfCSPzb (ORCPT + 99 others); Tue, 19 Mar 2019 11:55:31 -0400 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:44038 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726857AbfCSPzb (ORCPT ); Tue, 19 Mar 2019 11:55:31 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id BD88DCF4 for ; Tue, 19 Mar 2019 15:55:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dXiBHsRaUFqI for ; Tue, 19 Mar 2019 10:55:29 -0500 (CDT) Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p6.oit.umn.edu (Postfix) with ESMTPS id 63518CDE for ; Tue, 19 Mar 2019 10:55:29 -0500 (CDT) Received: by mail-io1-f70.google.com with SMTP id z6so16052666ioh.16 for ; Tue, 19 Mar 2019 08:55:29 -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=B1QWfeXYOX77KfMW/kAokzeu80UhNz+WjOFEKWzCLx8=; b=YhMPNTI4nsTmhGrb/SqkRcW/ergOzpf35r33GQjEkHH463SZcpWdg98CoM3mmiZyRJ yn+2OcdbfdR0zOO6mym2zMmlLF7ImYPNRNzhGo0tg4H5zzNUi7rAjH4rP3ok4XdyeAG+ bDbtDbTj3q1A3vd1BagbgxEqxgE+6pICuuRLCxVgGxSkwkNA/aF64KiuNa/bavi/CWNm T/xzdg+P1eY9yJaG3cglVe2Q1J9EqMi6JPiMzkQBVE7rNpszEQ9d365ciRPjFtBjjePj F/bq4wQTdgga7I3gxK/YwDqvt3m+WdEYI14MlyvZpJ50Ls+8nNMmc1dGzqStBVYenkyq PRRA== 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=B1QWfeXYOX77KfMW/kAokzeu80UhNz+WjOFEKWzCLx8=; b=NpPY9f4YHBZPsooKh7FP+DwYStFAy6Hm+PtgPqy5KsRw8ate4YiCRncyIbC4vcGeqG swAjk9rPdw7uqEfycMLoEJVgifIwm6KvWJRj/5ZXJeEP7+ufIranIPWhmZidHXo7QUfv uxPlQQh2hpjzn4zcoP4G9Cg/qWyIptkufNfIR9LFbm8PLaCw1uARx3a47yFRGEIZWL4D 1rKTlPpJg+kvWR/fZPILurjxdg0P1SJ6AAOqUeFE80Dp7FUocY7/F9T1kB0lE5JPOxfX ytCUryhfp+5iiJJYT5vOG/cYYdoe5GGSQC6GARnionIhyKsOtXLNvcXhcZTyUTMBfPOh ZzmA== X-Gm-Message-State: APjAAAWhH0oTdPdsvWfsN4ci4BPi+nAxoU2PC7fXb1pGCNfyuGbCexyw XgLI1zkA0LEhhzk8CajfIZyMARZACOFc56sEfMGPTwpQSvofLQ/MnpgwKUczApERERBS2uiQF1+ WplZ1uIa73WXxb0R4i/dU3C7SSRL1 X-Received: by 2002:a6b:6b1a:: with SMTP id g26mr1968403ioc.211.1553010929050; Tue, 19 Mar 2019 08:55:29 -0700 (PDT) X-Received: by 2002:a6b:6b1a:: with SMTP id g26mr1968382ioc.211.1553010928884; Tue, 19 Mar 2019 08:55:28 -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 k2sm6187954ion.11.2019.03.19.08.55.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Mar 2019 08:55:28 -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 10:55:20 -0500 Message-Id: <20190319155524.6978-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. --- 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