Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1514445ybt; Mon, 15 Jun 2020 02:13:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwS3wIdFYoo0xFvCKxgYafWFl4tL5K4jxkbpL4i0vyWISgcmMmtBZ3l6OXHnpb6xPjSsQL+ X-Received: by 2002:a17:906:a387:: with SMTP id k7mr26055170ejz.408.1592212394951; Mon, 15 Jun 2020 02:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592212394; cv=none; d=google.com; s=arc-20160816; b=C9X8VeIwROQMu7Xx+w8ceT+p5SVqrP8ZPd3vPWrvp7EmRoa8KIgYksRkNNMH7yzOqc QrWHCKhiZAdNNMCktRmdtjwyuBohXK9ioQGUcW6SEvskcbNU/rNEFV+OAi5DeltNYGle 5Ag/yOCek3wBv0LmDLXUaMzYrazZenFh/PkYoYCqFpQVwExQQdURdIffdLkQEh5KZBTV sd3oPVqXekE3Op8rVwXZs7X5NIufmYw7OVnuyKShap5uepx2hJRoGp+49Ln+8Vr5FsGs oBZYURIJMO8/QLWPurWcnyV7FcVfwJcFK3tk9P+Sp7/l1vqoQRk5MVkod7SMce41nCtm 7qyw== 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 :message-id:date:subject:cc:to:from; bh=sHzEPoBnq5xbCVHZF/sgFZUFS90jZWXjWV39v64i3bg=; b=XL3HjFchueSz9OW9x4gGl+hqb5DCXNm3Ng0oglSPm7D0daAdceytl4JzC2gp+F70Uu EPZglcRrFDSvhcL+LhXthMemrhczTvjqPYVIIRCyXx+Z8NHsWcKjIk13WrlfHtCjTWDZ Ogbfkg3Hqw1r+/EY4576Y5/RtAymGxJSVymyzPton9XSashpkW98HZyqAw+pFHKxdJiC OmMfRiQqgA8UiyTNnrmlWyf4eszTAQWWq+RTJLF/HW236szK2tkBvYTRZGfRLp/jo8r6 yz9MeuZP4BhwZ9vbI+S7PM5AnjrQTUb9wFWGXe4em1eLFZBmvF8Nyjui4Xbs9mmdfBgp 6rhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n15si8651853ejd.527.2020.06.15.02.12.51; Mon, 15 Jun 2020 02:13:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729307AbgFOJJF (ORCPT + 99 others); Mon, 15 Jun 2020 05:09:05 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5891 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728411AbgFOJJE (ORCPT ); Mon, 15 Jun 2020 05:09:04 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E0CBB22AA912C8934AB8; Mon, 15 Jun 2020 17:09:01 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Mon, 15 Jun 2020 17:08:53 +0800 From: Jing Xiangfeng To: , , CC: , , , , Subject: [PATCH] IB/srpt: Fix a potential null pointer dereference Date: Mon, 15 Jun 2020 17:12:20 +0800 Message-ID: <20200615091220.6439-1-jingxiangfeng@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In srpt_cm_req_recv(), it is possible that sdev is NULL, so we should test sdev before using it. Signed-off-by: Jing Xiangfeng --- drivers/infiniband/ulp/srpt/ib_srpt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index 98552749d71c..72053254bf84 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -2143,7 +2143,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev, const struct srp_login_req *req, const char *src_addr) { - struct srpt_port *sport = &sdev->port[port_num - 1]; + struct srpt_port *sport; struct srpt_nexus *nexus; struct srp_login_rsp *rsp = NULL; struct srp_login_rej *rej = NULL; @@ -2162,6 +2162,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev, if (WARN_ON(!sdev || !req)) return -EINVAL; + sport = &sdev->port[port_num - 1]; it_iu_len = be32_to_cpu(req->req_it_iu_len); pr_info("Received SRP_LOGIN_REQ with i_port_id %pI6, t_port_id %pI6 and it_iu_len %d on port %d (guid=%pI6); pkey %#04x\n", -- 2.17.1