public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: "lizhijian@fujitsu.com" <lizhijian@fujitsu.com>
To: "Daisuke Matsuda (Fujitsu)" <matsuda-daisuke@fujitsu.com>,
	"leonro@nvidia.com" <leonro@nvidia.com>,
	"jgg@nvidia.com" <jgg@nvidia.com>,
	"zyjzyj2000@gmail.com" <zyjzyj2000@gmail.com>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>
Subject: Re: [PATCH v2] RDMA/rxe: Implement packet length validation on responder
Date: Tue, 8 Nov 2022 09:00:32 +0000	[thread overview]
Message-ID: <b4dfa189-7b07-ad97-05c2-cd81aa1bbede@fujitsu.com> (raw)
In-Reply-To: <20221107055338.357184-1-matsuda-daisuke@fujitsu.com>



On 07/11/2022 13:53, Daisuke Matsuda wrote:
> The function check_length() is supposed to check the length of inbound
> packets on responder, but it actually has been a stub since the driver was
> born. Let it check the payload length and the DMA length.
> 
> Signed-off-by: Daisuke Matsuda <matsuda-daisuke@fujitsu.com>

Looks good to me

Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>




> ---
> FOR REVIEWERS
>    I referred to IB Specification Vol 1-Revision-1.5 to create this patch.
>    Please see 9.7.4.1.6 (page.330).
> 
> v2: Fixed the conditional for 'last' packets. Thanks, Zhijian.
> 
>   drivers/infiniband/sw/rxe/rxe_resp.c | 34 ++++++++++++++++++++++------
>   1 file changed, 27 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c
> index c32bc12cc82f..382d2053db43 100644
> --- a/drivers/infiniband/sw/rxe/rxe_resp.c
> +++ b/drivers/infiniband/sw/rxe/rxe_resp.c
> @@ -393,16 +393,36 @@ static enum resp_states check_resource(struct rxe_qp *qp,
>   static enum resp_states check_length(struct rxe_qp *qp,
>   				     struct rxe_pkt_info *pkt)
>   {
> -	switch (qp_type(qp)) {
> -	case IB_QPT_RC:
> -		return RESPST_CHK_RKEY;
> +	int mtu = qp->mtu;
> +	u32 payload = payload_size(pkt);
> +	u32 dmalen = reth_len(pkt);
>   
> -	case IB_QPT_UC:
> -		return RESPST_CHK_RKEY;
> +	/* RoCEv2 packets do not have LRH.
> +	 * Let's skip checking it.
> +	 */
>   
> -	default:
> -		return RESPST_CHK_RKEY;
> +	if ((pkt->opcode & RXE_START_MASK) &&
> +	    (pkt->opcode & RXE_END_MASK)) {
> +		/* "only" packets */
> +		if (payload > mtu)
> +			return RESPST_ERR_LENGTH;
> +	} else if ((pkt->opcode & RXE_START_MASK) ||
> +		   (pkt->opcode & RXE_MIDDLE_MASK)) {
> +		/* "first" or "middle" packets */
> +		if (payload != mtu)
> +			return RESPST_ERR_LENGTH;
> +	} else if (pkt->opcode & RXE_END_MASK) {
> +		/* "last" packets */
> +		if ((payload == 0) || (payload > mtu))
> +			return RESPST_ERR_LENGTH;
> +	}
> +
> +	if (pkt->opcode & (RXE_WRITE_MASK | RXE_READ_MASK)) {
> +		if (dmalen > (1 << 31))
> +			return RESPST_ERR_LENGTH;
>   	}
> +
> +	return RESPST_CHK_RKEY;
>   }
>   
>   static enum resp_states check_rkey(struct rxe_qp *qp,

  parent reply	other threads:[~2022-11-08  9:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07  5:53 [PATCH v2] RDMA/rxe: Implement packet length validation on responder Daisuke Matsuda
2022-11-07  6:16 ` Zhu Yanjun
2022-11-08  9:00 ` lizhijian [this message]
2022-11-09 17:57 ` Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b4dfa189-7b07-ad97-05c2-cd81aa1bbede@fujitsu.com \
    --to=lizhijian@fujitsu.com \
    --cc=jgg@nvidia.com \
    --cc=leonro@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=matsuda-daisuke@fujitsu.com \
    --cc=zyjzyj2000@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox