Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1508250img; Tue, 19 Mar 2019 09:05:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqw23PyQydENyD49SygzLLSmLTi/voDZcODxIDFvJ0RM03oMlPw/0MEhn4WaESBBpDX6WPHL X-Received: by 2002:aa7:8102:: with SMTP id b2mr2657785pfi.69.1553011544001; Tue, 19 Mar 2019 09:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553011543; cv=none; d=google.com; s=arc-20160816; b=aRZJZ8qIJq/ZjddXtOESS8xM3ISf5Zf7twdNlOul6vgP2Wzi1mfmoVPc74mMfuk3Zl oWqxUfD8lt4TmuEsi+/5EuIDnR+jlESek4PypXl5HbGeg4DJXI23j84BJMqOJRpKgV2d mBzxrSvdaM8K3BEhEF91LrqVM6EZTRfV9L5hhDNK9JRaZIxTJnWxIZDp8a1EO5bH65lh CkT/8nZTaOoOCbx7IUqJwnGjvty9CF20TZCzLE/zXA0u1hBxYOh1uTQS3+5cqDAyUdIn Ia1xECOZqPVPStKOuq3twJt8aMpRPvbWyiQt/BKmcI1iGUGGpLiJ4XaQaV3CwaenxSlU /W6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lb5giPa1Sd/Qqs3+kni8GnIuu+vGgS6p9PNicv18ZW0=; b=MDTX/iEKYfhR45sp7Yv4yBJJhFk9xlatK1JmrmVLrAQrBz6G1nYWxYTFof2AmE3fj8 XDtkBTj7v/HEY9spJIUcnxf6s57zyT0uSdBN6TqzekBuFbdzbMSIv7atxXQmU+l6oDag aqYX/qbB21T3a/FOhxAdusJdGs/cr9ZD/1AnHLcLY8wVDw7s0CPgIkSntUGJ67/HXwxR AKidI9YaclTPvEMQAjrtaafDa8Kj+LYufJzip3ZQBZwFs8svhUAhpeKW1NDJQ0DwBReh R8n+eKFBNoAsiBO39Q3IzCc5/wRWDngUALaAvH/ZKTGYqZ8VLNLhzbQo+rrJkmSDPIgH CXYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Xf3BI9r4; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si11953623pge.14.2019.03.19.09.05.27; Tue, 19 Mar 2019 09:05:43 -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=@oracle.com header.s=corp-2018-07-02 header.b=Xf3BI9r4; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727899AbfCSQE1 (ORCPT + 99 others); Tue, 19 Mar 2019 12:04:27 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:53666 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbfCSQEX (ORCPT ); Tue, 19 Mar 2019 12:04:23 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2JG3mdt128300; Tue, 19 Mar 2019 16:04:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=lb5giPa1Sd/Qqs3+kni8GnIuu+vGgS6p9PNicv18ZW0=; b=Xf3BI9r40nYmd1EgOhV8TABoO99+BuPGi6kV5Uba7gYrD9C8eVjdfYxS/I6O+2oRYTM2 +P/CfCUZ6L83th8DXoSYJ/+swErfRTpdXArMyP2fFDfp206F4/h7D4vcZfF3uXe3feAB 66c2n9hhVXF7DF7jX3/hNoT+6d4obDwrti4ztTD0Nbyy/Aw6w9q+IBirN7QI9UX6q5Ng yRv4zVoohY4S0BhlrfI8KGzToWjQF/Ii+MaVqh7PokPOhKmkeYUlYKvsLSUix9+e1mt9 KiG48sybcNcbP9QPxRLYjx9aHk+yCQ/cdUvJBVK792urreGAsNqYwnzldTxtqjuQsHBP 1w== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2r8rjunrb3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2019 16:04:08 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x2JG47eH001201 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2019 16:04:07 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x2JG46or006834; Tue, 19 Mar 2019 16:04:06 GMT Received: from lap1 (/77.138.186.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 19 Mar 2019 09:04:06 -0700 Date: Tue, 19 Mar 2019 18:03:59 +0200 From: Yuval Shaia To: Aditya Pakki 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: Re: [PATCH v3] net: mlx5: Add a missing check on idr_find, free buf Message-ID: <20190319160359.GD32657@lap1> References: <20190319155524.6978-1-pakki001@umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190319155524.6978-1-pakki001@umn.edu> User-Agent: Mutt/1.11.3 (2019-02-01) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9200 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903190117 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 19, 2019 at 10:55:20AM -0500, Aditya Pakki wrote: > 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; Reviewed-by: Yuval Shaia > } > -- > 2.17.1 >