diff mbox series

[2/3] libfc: check fc_frame_payload_get() return value for null

Message ID 20181007083537.89131-3-hare@suse.de (mailing list archive)
State Accepted
Headers show
Series libfc state machine fixes | expand

Commit Message

Hannes Reinecke Oct. 7, 2018, 8:35 a.m. UTC
From: Thomas Abraham <tabraham@suse.com>

We should not assume the payload of a PRLI or PLOGI
respons is always present.

Signed-off-by: Thomas Abraham <tabraham@suse.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/libfc/fc_rport.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Easi, Arun Oct. 8, 2018, 7:43 a.m. UTC | #1
On Sun, 7 Oct 2018, 1:35am, Hannes Reinecke wrote:

> External Email
> 
> From: Thomas Abraham <tabraham@suse.com>
> 
> We should not assume the payload of a PRLI or PLOGI
> respons is always present.
> 
> Signed-off-by: Thomas Abraham <tabraham@suse.com>
> Reviewed-by: Hannes Reinecke <hare@suse.com>
> ---
>  drivers/scsi/libfc/fc_rport.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
> index 372387a450df..e400783ebb87 100644
> --- a/drivers/scsi/libfc/fc_rport.c
> +++ b/drivers/scsi/libfc/fc_rport.c
> @@ -1038,8 +1038,11 @@ static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
>                 struct fc_els_ls_rjt *rjt;
> 
>                 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
> -               FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
> -                            rjt->er_reason, rjt->er_explan);
> +               if (!rjt)
> +                       FC_RPORT_DBG(rdata, "PLOGI bad response\n");
> +               else
> +                       FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
> +                                    rjt->er_reason, rjt->er_explan);
>                 fc_rport_error_retry(rdata, -FC_EX_ELS_RJT);
>         }
>  out:
> @@ -1211,8 +1214,11 @@ static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
> 
>         } else {
>                 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
> -               FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
> -                            rjt->er_reason, rjt->er_explan);
> +               if (!rjt)
> +                       FC_RPORT_DBG(rdata, "PRLI bad response\n");
> +               else
> +                       FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
> +                                    rjt->er_reason, rjt->er_explan);
>                 fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
>         }

It would be a good idea to explicitly mention in the header message 
that this fixes a crash. The changes by themselves look good to me.

Reviewed-by: Arun Easi <arun.easi@cavium.com>

Regards,
-Arun

> 
> --
> 2.16.4
> 
>
diff mbox series

Patch

diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index 372387a450df..e400783ebb87 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -1038,8 +1038,11 @@  static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
 		struct fc_els_ls_rjt *rjt;
 
 		rjt = fc_frame_payload_get(fp, sizeof(*rjt));
-		FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
-			     rjt->er_reason, rjt->er_explan);
+		if (!rjt)
+			FC_RPORT_DBG(rdata, "PLOGI bad response\n");
+		else
+			FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
+				     rjt->er_reason, rjt->er_explan);
 		fc_rport_error_retry(rdata, -FC_EX_ELS_RJT);
 	}
 out:
@@ -1211,8 +1214,11 @@  static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
 
 	} else {
 		rjt = fc_frame_payload_get(fp, sizeof(*rjt));
-		FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
-			     rjt->er_reason, rjt->er_explan);
+		if (!rjt)
+			FC_RPORT_DBG(rdata, "PRLI bad response\n");
+		else
+			FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
+				     rjt->er_reason, rjt->er_explan);
 		fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
 	}