Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1674332ybt; Mon, 15 Jun 2020 06:40:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx556M1/IR8ggjGXeJFqGHV4ZgQrwzpTKSWstwB2z1wS6WMTIEaFPELL5TiqZ7abTXuvNw+ X-Received: by 2002:a17:906:1fcd:: with SMTP id e13mr25298054ejt.472.1592228413577; Mon, 15 Jun 2020 06:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592228413; cv=none; d=google.com; s=arc-20160816; b=Y0OpM2YEYSzD8tvCowVVNjdKVeauadQQsmvFVOVNnmSl5fJqJsmAqi2JWAZCFwo4Wj Ws399CVr0GmRGgc05+DzHaGOOSc2KIfnNIGuuyFMSAIYm9HW5i/LTEIJIxOfoAHzLsxe REU4E8Y3jYrqjvTrkcWP6LtUN8/GgtorJuPWry2pAKBhNKp7m5iiaG+flzgvbCLimE6Y fq7qIChEzPDzdW7GFDltztMC0+muR0pn/+pTsk0VcICSHNCmU5QuZy8QAprBHHC6r6h0 VUQwa7VQYJ4mmFe++rvpb2mf2kqdWz2UIB+vzYESWg1iFEuKZM+Tpay13gC6B37neO3y cyhg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject; bh=wpyxJv/PM1wE2X/LCvdaNR8aTZBt1o2wUTKPmTumIZU=; b=QO8r61VhyYMy80TzNS7XXnz2N94mJfg5H4NsxBqZZrQMrY0c62miQ0uSUxqRHUAdgp IVnW7r889TbqG8I38SC3lbqibbZ5T0gFnN20mAWaeaG10hx7Hx9vvM5mjhhe3p20/twB duzJQrYzy81+qsa/LqEsoeIUTRaZ0u9cSzfq6ws47rbTCavca5LxeL7hYf13oHzfqu/D 39MzGd+F53WfRL19R4delTQVBV+fcxp0HssKM6h3vJyiM4J8lw43HX6gOpIe/nVkHdOC Tnhobye5an6hzjPnClyrVGwHcy+8JUbub/csElTOXw6mEuu8SVQUwYd1l6X6ojEwooB9 Z9Cg== 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 op23si8362308ejb.354.2020.06.15.06.39.51; Mon, 15 Jun 2020 06:40:13 -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 S1730525AbgFONh7 (ORCPT + 99 others); Mon, 15 Jun 2020 09:37:59 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45888 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730167AbgFONh7 (ORCPT ); Mon, 15 Jun 2020 09:37:59 -0400 Received: by mail-pl1-f195.google.com with SMTP id d8so6818491plo.12; Mon, 15 Jun 2020 06:37:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=wpyxJv/PM1wE2X/LCvdaNR8aTZBt1o2wUTKPmTumIZU=; b=CSsXKd73Eu0wUabrIH+cLvboO+tmwivYcj1kgyWxe9rm8bqcfjaCIeCXJC35lTqBH6 WSVQiWXSsjjlrfcyapo1Vv7biiw12vJ0VPlfijiITfjG2ilAqvKrxYjEJ4KxPauiS/CJ uP6v096yyHIazQafmIhsjylYBMQb7OFMKX8Y/nNxIoBj+6SaOsAVaiKlGEbsgeVYwENJ qN/9BZV3b95KHTGCKw/FuOoqcrCSb1XXvPFHfZVR62LXfC+tJGpw2F6QaTxO+FA+uDhL A3vC2LJwIK9BBihD2OWxnFAB6Ru1tIp+SOXg+pF14YxsAGQdZvTTrHIjR3ofnHN51vUf tLow== X-Gm-Message-State: AOAM531MZuy3vCDbiOzBgsMXXtucnr32BJSDknEOzu3YXwjcoDZRRB3s WDopc4e1dOR7vQkCMjH5kIc8XTZf X-Received: by 2002:a17:902:eed4:: with SMTP id h20mr922321plb.134.1592228277890; Mon, 15 Jun 2020 06:37:57 -0700 (PDT) Received: from [192.168.50.147] (c-73-241-217-19.hsd1.ca.comcast.net. [73.241.217.19]) by smtp.gmail.com with ESMTPSA id e12sm14177046pfj.137.2020.06.15.06.37.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jun 2020 06:37:57 -0700 (PDT) Subject: Re: [PATCH] IB/srpt: Fix a potential null pointer dereference To: Jing Xiangfeng , dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20200615091220.6439-1-jingxiangfeng@huawei.com> From: Bart Van Assche Autocrypt: addr=bvanassche@acm.org; prefer-encrypt=mutual; keydata= mQENBFSOu4oBCADcRWxVUvkkvRmmwTwIjIJvZOu6wNm+dz5AF4z0FHW2KNZL3oheO3P8UZWr LQOrCfRcK8e/sIs2Y2D3Lg/SL7qqbMehGEYcJptu6mKkywBfoYbtBkVoJ/jQsi2H0vBiiCOy fmxMHIPcYxaJdXxrOG2UO4B60Y/BzE6OrPDT44w4cZA9DH5xialliWU447Bts8TJNa3lZKS1 AvW1ZklbvJfAJJAwzDih35LxU2fcWbmhPa7EO2DCv/LM1B10GBB/oQB5kvlq4aA2PSIWkqz4 3SI5kCPSsygD6wKnbRsvNn2mIACva6VHdm62A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bTJAUxiWIi1np0z3/RDnoVyfmfbbL1DY7zf2hYXLLzsJR mSsED/1nlJ9Oq5fALdNEPgDyPUerqHxcmIub+pF0AzJoYHK5punqpqfGmqPbjxrJLPJfHVKy goMj5DlBMoYqEgpbwdUYkH6QdizJJCur4icy8GUNbisFYABeoJ91pnD4IGei3MTdvINSZI5e Message-ID: <7366b608-4474-cfaa-c465-957fd2d2366d@acm.org> Date: Mon, 15 Jun 2020 06:37:56 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200615091220.6439-1-jingxiangfeng@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-15 02:12, Jing Xiangfeng wrote: > 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); > Please remove the (!sdev || !req) check instead of making the above change. It's easy to show that both pointers are always valid. Thanks, Bart.