Skip to contentSkip to conversation

cxl: fortify string fixups

PATCH Applied Dan Williams 3 participants 9 messages May 19 – Jun 2 CXL

lore
Share & tools
lore

Dan Williams

author maintainer
#0 lore raw

cover cxl: fortify string fixups

It seems nobody is running cxl_test with CONFIG_FORTIFY_SOURCE=y. A couple instances of __fortify_panic can be triggered.

Move some counted_by initialization before associated buffer / object-array access so that it does not falsely assume a buffer overflow is occurring.

Dan Williams (2):
cxl/fwctl: Fix __fortify_panic
cxl/test: Fix __fortify_panic

 drivers/cxl/core/features.c            | 2 +-
 tools/testing/cxl/test/cxl_translate.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8

Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 1/2 cxl/fwctl: Fix __fortify_panic

Fix a runtime assertion in cxlctl_get_supported_features(). Fortify complains that it is potentially overflowing the entries array per __counted_by_le(num_entries). Quiet the false positive by initializing @num_entries earlier.

memcpy: detected buffer overflow: 48 byte write of buffer size 0

 WARNING: lib/string_helpers.c:1036 at __fortify_report+0x4d/0xa0, CPU#7: fwctl/1398
 RIP: 0010:__fortify_report+0x50/0xa0
 Call Trace:
  __fortify_panic+0xd/0xf
  cxlctl_get_supported_features.cold+0x23/0x35 [cxl_core]
Fixes 4d1c09cef2c2 ("cxl: Add support for fwctl RPC command to enable CXL feature commands")
---
 drivers/cxl/core/features.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/features.c +1 -1
index 3435db9ea6b1..85185af46b72 100644
@@ -423,6 +423,7 @@ static void *cxlctl_get_supported_features(struct cxl_features_state *cxlfs,
 
 	rpc_out->size = struct_size(feat_out, ents, requested);
 	feat_out = &rpc_out->get_sup_feats_out;
+	feat_out->num_entries = cpu_to_le16(requested);
 
 	for (i = start, pos = &feat_out->ents[0];
 	     i < cxlfs->entries->num_features; i++, pos++) {
@@ -444,7 +445,6 @@ static void *cxlctl_get_supported_features(struct cxl_features_state *cxlfs,
 		}
 	}
 
-	feat_out->num_entries = cpu_to_le16(requested);
 	feat_out->supported_feats = cpu_to_le16(cxlfs->entries->num_features);
 	rpc_out->retval = CXL_MBOX_CMD_RC_SUCCESS;
 	*out_len = out_size;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] cxl/fwctl: Fix __fortify_panic

Quoted 6 lines · Dan Williams

Fix a runtime assertion in cxlctl_get_supported_features(). Fortify complains that it is potentially overflowing the entries array per __counted_by_le(num_entries). Quiet the false positive by initializing @num_entries earlier.

memcpy: detected buffer overflow: 48 byte write of buffer size 0

Quoted 8 lines
 WARNING: lib/string_helpers.c:1036 at __fortify_report+0x4d/0xa0, CPU#7: fwctl/1398
 RIP: 0010:__fortify_report+0x50/0xa0
 Call Trace:
  __fortify_panic+0xd/0xf
  cxlctl_get_supported_features.cold+0x23/0x35 [cxl_core]
Fixes 4d1c09cef2c2 ("cxl: Add support for fwctl RPC command to enable CXL feature commands")
Quoted 24 lines
---
 drivers/cxl/core/features.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/features.c +1 -1
index 3435db9ea6b1..85185af46b72 100644
@@ -423,6 +423,7 @@ static void *cxlctl_get_supported_features(struct cxl_features_state *cxlfs,
 
 	rpc_out->size = struct_size(feat_out, ents, requested);
 	feat_out = &rpc_out->get_sup_feats_out;
+	feat_out->num_entries = cpu_to_le16(requested);
 
 	for (i = start, pos = &feat_out->ents[0];
 	     i < cxlfs->entries->num_features; i++, pos++) {
@@ -444,7 +445,6 @@ static void *cxlctl_get_supported_features(struct cxl_features_state *cxlfs,
 		}
 	}
 
-	feat_out->num_entries = cpu_to_le16(requested);
 	feat_out->supported_feats = cpu_to_le16(cxlfs->entries->num_features);
 	rpc_out->retval = CXL_MBOX_CMD_RC_SUCCESS;
 	*out_len = out_size;
maintainer Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] cxl/fwctl: Fix __fortify_panic

In reply to Dan Williams
Quoted 5 lines · Dan Williams

Fix a runtime assertion in cxlctl_get_supported_features(). Fortify complains that it is potentially overflowing the entries array per __counted_by_le(num_entries). Quiet the false positive by initializing @num_entries earlier.

Quoted 7 lines

memcpy: detected buffer overflow: 48 byte write of buffer size 0

 WARNING: lib/string_helpers.c:1036 at __fortify_report+0x4d/0xa0, CPU#7: fwctl/1398
 RIP: 0010:__fortify_report+0x50/0xa0
 Call Trace:
  __fortify_panic+0xd/0xf
  cxlctl_get_supported_features.cold+0x23/0x35 [cxl_core]
author maintainer
#4 lore raw

PATCH 2/2 cxl/test: Fix __fortify_panic

In reply to Dan Williams

Fix a runtime assertion in setup_xor_mapping(). Fortify complains that it is potentially overflowing the xormaps array per __counted_by(nr_maps). Quiet the false positive by initializing @nr_entries earlier.

memcpy: detected buffer overflow: 32 byte write of buffer size 0

 WARNING: lib/string_helpers.c:1036 at __fortify_report+0x4d/0xa0, CPU#8: modprobe/2728
 Call Trace:
  __fortify_panic+0xd/0xf
  setup_xor_mapping+0x6c/0xa0 [cxl_translate]
Fixes 06377c54a133 ("cxl/test: Add cxl_translate module for address translation testing")
---
 tools/testing/cxl/test/cxl_translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/cxl/test/cxl_translate.c +1 -1
index 16328b2112b2..25a27e01ac21 100644
@@ -236,8 +236,8 @@ static int setup_xor_mapping(void)
 	if (!cximsd)
 		return -ENOMEM;
 
-	memcpy(cximsd->xormaps, xormaps, nr_maps * sizeof(*cximsd->xormaps));
 	cximsd->nr_maps = nr_maps;
+	memcpy(cximsd->xormaps, xormaps, nr_maps * sizeof(*cximsd->xormaps));
 
 	return 0;
 }
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] cxl/test: Fix __fortify_panic

Quoted 3 lines · Dan Williams

Fix a runtime assertion in setup_xor_mapping(). Fortify complains that it is potentially overflowing the xormaps array per __counted_by(nr_maps). Quiet the false positive by initializing @nr_entries earlier.

@nr_maps?

Quoted 9 lines

memcpy: detected buffer overflow: 32 byte write of buffer size 0

 WARNING: lib/string_helpers.c:1036 at __fortify_report+0x4d/0xa0, CPU#8: modprobe/2728
 Call Trace:
  __fortify_panic+0xd/0xf
  setup_xor_mapping+0x6c/0xa0 [cxl_translate]
Fixes 06377c54a133 ("cxl/test: Add cxl_translate module for address translation testing")
Quoted 18 lines
---
 tools/testing/cxl/test/cxl_translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/cxl/test/cxl_translate.c +1 -1
index 16328b2112b2..25a27e01ac21 100644
@@ -236,8 +236,8 @@ static int setup_xor_mapping(void)
 	if (!cximsd)
 		return -ENOMEM;
 
-	memcpy(cximsd->xormaps, xormaps, nr_maps * sizeof(*cximsd->xormaps));
 	cximsd->nr_maps = nr_maps;
+	memcpy(cximsd->xormaps, xormaps, nr_maps * sizeof(*cximsd->xormaps));
 
 	return 0;
 }
maintainer Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] cxl/test: Fix __fortify_panic

In reply to Dan Williams
Quoted 9 lines · Dan Williams

Fix a runtime assertion in setup_xor_mapping(). Fortify complains that it is potentially overflowing the xormaps array per __counted_by(nr_maps). Quiet the false positive by initializing @nr_entries earlier.

memcpy: detected buffer overflow: 32 byte write of buffer size 0

 WARNING: lib/string_helpers.c:1036 at __fortify_report+0x4d/0xa0, CPU#8: modprobe/2728
 Call Trace:
  __fortify_panic+0xd/0xf
  setup_xor_mapping+0x6c/0xa0 [cxl_translate]
maintainer Applied
#8 lore raw
In reply to Dan Williams
Quoted 11 lines · Dan Williams

It seems nobody is running cxl_test with CONFIG_FORTIFY_SOURCE=y. A couple instances of __fortify_panic can be triggered.

Move some counted_by initialization before associated buffer / object-array access so that it does not falsely assume a buffer overflow is occurring.

Dan Williams (2):
cxl/fwctl: Fix __fortify_panic
cxl/test: Fix __fortify_panic

Quoted 6 lines
 drivers/cxl/core/features.c            | 2 +-
 tools/testing/cxl/test/cxl_translate.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8

Applied to cxl/next with commit 2 commit log fixed up.

b882b0ca9bf8
5c00984479bb