Skip to contentSkip to conversation

infiniband: ulp: srpt: Use flex array destination for memcpy()

PATCH Applied Hangyu Hua 4 participants 4 messages Sep 9, 2022 – Sep 20, 2022

Subsystems (3)
lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 infiniband: ulp: srpt: Use flex array destination for memcpy()

In preparation for FORTIFY_SOURCE performing run-time destination buffer bounds checking for memcpy(), specify the destination output buffer explicitly, instead of asking memcpy() to write past the end of what looked like a fixed-size object.

Notice that srp_rsp[] is a pointer to a structure that contains flexible-array member data[]:

struct srp_rsp {
	...
	__be32	sense_data_len;
	__be32	resp_data_len;
	u8	data[];
};
---
 drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +1 -1
index 21cbe30d526f..8c29e14150d3 100644
@@ -1421,7 +1421,7 @@ static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch,
 
 		srp_rsp->flags |= SRP_RSP_FLAG_SNSVALID;
 		srp_rsp->sense_data_len = cpu_to_be32(sense_data_len);
-		memcpy(srp_rsp + 1, sense_data, sense_data_len);
+		memcpy(srp_rsp->data, sense_data, sense_data_len);
 	}
 
 	return sizeof(*srp_rsp) + sense_data_len;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Hangyu Hua

In preparation for FORTIFY_SOURCE performing run-time destination buffer bounds checking for memcpy(), specify the destination output buffer explicitly, instead of asking memcpy() to write past the end of what looked like a fixed-size object.

Notice that srp_rsp[] is a pointer to a structure that contains flexible-array member data[]:

struct srp_rsp {
	...
	__be32	sense_data_len;
	__be32	resp_data_len;
	u8	data[];
};
Quoted 2 lines

Thanks
--
Gustavo

Quoted 20 lines
---
 drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +1 -1
index 21cbe30d526f..8c29e14150d3 100644
@@ -1421,7 +1421,7 @@ static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch,
 
 		srp_rsp->flags |= SRP_RSP_FLAG_SNSVALID;
 		srp_rsp->sense_data_len = cpu_to_be32(sense_data_len);
-		memcpy(srp_rsp + 1, sense_data, sense_data_len);
+		memcpy(srp_rsp->data, sense_data, sense_data_len);
 	}
 
 	return sizeof(*srp_rsp) + sense_data_len;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Hangyu Hua
Quoted 4 lines · Hangyu Hua

In preparation for FORTIFY_SOURCE performing run-time destination buffer bounds checking for memcpy(), specify the destination output buffer explicitly, instead of asking memcpy() to write past the end of what looked like a fixed-size object.

#3 lore raw
In reply to Hangyu Hua
Quoted 9 lines · Hangyu Hua

In preparation for FORTIFY_SOURCE performing run-time destination buffer bounds checking for memcpy(), specify the destination output buffer explicitly, instead of asking memcpy() to write past the end of what looked like a fixed-size object.

Notice that srp_rsp[] is a pointer to a structure that contains flexible-array member data[]:

[...]

Applied, thanks!

[1/1] infiniband: ulp: srpt: Use flex array destination for memcpy()

      https://git.kernel.org/rdma/rdma/c/4b46a6079d2f8a

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>