cxl: fortify string fixups
Dan Williams
maintainercover 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
Dan Williams
maintainerPATCH 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]
--- drivers/cxl/core/features.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/features.c +1 -1
@@ -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
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")Signed-off-by Dan Williams <[email protected]>
Quoted 24 lines
--- drivers/cxl/core/features.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cxl/core/features.c +1
-1@@ -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;
Re: [PATCH 1/2] cxl/fwctl: Fix __fortify_panic
In reply to Dan WilliamsQuoted 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]
Dan Williams
maintainerPATCH 2/2 cxl/test: Fix __fortify_panic
In reply to Dan WilliamsFix 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]
--- tools/testing/cxl/test/cxl_translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/cxl/test/cxl_translate.c +1 -1
@@ -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
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")Signed-off-by Dan Williams <[email protected]>
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@@ -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 ; }
Re: [PATCH 2/2] cxl/test: Fix __fortify_panic
In reply to Dan WilliamsQuoted 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]
Alison Schofield
maintainerQuoted 1 line · Dan Williams
It seems nobody is running
cxl_testwithCONFIG_FORTIFY_SOURCE=y. A
Added now:
ci-base.cfg: enable CONFIG_FORTIFY_SOURCE
https://github.com/pmem/ndctl-test-runner/commit/7b4e823
Quoted 11 lines · Dan Williams
It seems nobody is running
cxl_testwithCONFIG_FORTIFY_SOURCE=y. A couple instances of__fortify_paniccan be triggered.Move some
counted_byinitialization 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.
b882b0ca9bf85c00984479bb