ndctl/lib: move nd_cmd_pkg with a flex array to end of structures
Alison Schofield
maintainerPATCH 1/1 ndctl/lib: move nd_cmd_pkg with a flex array to end of structures
Placing nd_cmd_pkg anywhere but at the end of a structure can lead to undefined behavior for the flex array member. Move nd_cmd_pkg to the end of all affected structures.
Reproduce using Clang:
~/git/ndctl$ rm -rf build
~/git/ndctl$ CC=clang meson setup build
~/git/ndctl$ meson compile -C build
../ndctl/lib/hpe1.h:324:20: warning: field 'gen' with variable sized type 'struct nd_cmd_pkg' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
--- ndctl/lib/hpe1.h | 2 +- ndctl/lib/hyperv.h | 2 +- ndctl/lib/intel.h | 2 +- ndctl/lib/msft.h | 2 +- ndctl/lib/papr.h | 2 +- ndctl/libndctl-nfit.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
ndctl/lib/hpe1.h +1 -1
@@ -321,8 +321,8 @@ union ndn_hpe1_cmd { };struct ndn_pkg_hpe1 { -struct nd_cmd_pkg gen;union ndn_hpe1_cmd u; +struct nd_cmd_pkg gen; } __attribute__((packed));#define NDN_IOCTL_HPE1_PASSTHRU _IOWR(ND_IOCTL, ND_CMD_CALL, \
ndctl/lib/hyperv.h +1 -1
@@ -31,8 +31,8 @@ union nd_hyperv_cmd { } __attribute__((packed));struct nd_pkg_hyperv { -struct nd_cmd_pkg gen;union nd_hyperv_cmd u; +struct nd_cmd_pkg gen; } __attribute__((packed));#endif /* __NDCTL_HYPERV_H__ */
ndctl/lib/intel.h +1 -1
@@ -141,7 +141,6 @@ struct nd_intel_lss { } __attribute__((packed));struct nd_pkg_intel { -struct nd_cmd_pkg gen;union {struct nd_intel_smart smart;struct nd_intel_smart_inject inject;
@@ -154,6 +153,7 @@ struct nd_pkg_intel {struct nd_intel_fw_finish_query fquery;struct nd_intel_lss lss; }; +struct nd_cmd_pkg gen; };#define ND_INTEL_STATUS_MASK 0xffff
ndctl/lib/msft.h +1 -1
@@ -41,8 +41,8 @@ union ndn_msft_cmd { } __attribute__((packed));struct ndn_pkg_msft { -struct nd_cmd_pkg gen;union ndn_msft_cmd u; +struct nd_cmd_pkg gen; } __attribute__((packed));#define NDN_MSFT_STATUS_MASK 0xffff
ndctl/lib/papr.h +1 -1
@@ -8,8 +8,8 @@/* Wraps a nd_cmd generic header with pdsm header */ struct nd_pkg_papr { -struct nd_cmd_pkg gen;struct nd_pkg_pdsm pdsm; +struct nd_cmd_pkg gen; };#endif /* __PAPR_H__ */
ndctl/libndctl-nfit.h +1 -1
@@ -77,13 +77,13 @@ struct nd_cmd_ars_err_inj_stat { } __attribute__((packed));struct nd_cmd_bus { -struct nd_cmd_pkg gen;union {struct nd_cmd_ars_err_inj_stat err_inj_stat;struct nd_cmd_ars_err_inj_clr err_inj_clr;struct nd_cmd_ars_err_inj err_inj;struct nd_cmd_translate_spa xlat_spa; }; +struct nd_cmd_pkg gen; };int ndctl_bus_is_nfit_cmd_supported (struct ndctl_bus *bus,int cmd);
Signature · 1 line
2.37.3
Quoted 9 lines · Alison Schofield
Placing
nd_cmd_pkganywhere but at the end of a structure can lead to undefined behavior for the flex array member. Movend_cmd_pkgto the end of all affected structures.Reproduce using Clang:
~/git/ndctl$ rm -rf build
~/git/ndctl$ CC=clang meson setup build
~/git/ndctl$ meson compile -C build
Quoted 5 lines
../ndctl/lib/hpe1.h:324:20: warning: field 'gen' with variable sized type 'structnd_cmd_pkg' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]Reported-by Cristian Rodriguez <[email protected]>Signed-off-by Alison Schofield <[email protected]>
I wonder if a comment needs to be inserted to the definition of 'nd_cmd_pkg' to warn users that the struct should never be placed anywhere besides the end when used as a member of another struct.
Quoted 104 lines
--- ndctl/lib/hpe1.h | 2 +- ndctl/lib/hyperv.h | 2 +- ndctl/lib/intel.h | 2 +- ndctl/lib/msft.h | 2 +- ndctl/lib/papr.h | 2 +- ndctl/libndctl-nfit.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)ndctl/lib/hpe1.h +1
-1@@ -321,8 +321,8 @@ union ndn_hpe1_cmd { };struct ndn_pkg_hpe1 { -struct nd_cmd_pkg gen;union ndn_hpe1_cmd u; +struct nd_cmd_pkg gen; } __attribute__((packed));#define NDN_IOCTL_HPE1_PASSTHRU _IOWR(ND_IOCTL, ND_CMD_CALL, \ndctl/lib/hyperv.h +1
-1@@ -31,8 +31,8 @@ union nd_hyperv_cmd { } __attribute__((packed));struct nd_pkg_hyperv { -struct nd_cmd_pkg gen;union nd_hyperv_cmd u; +struct nd_cmd_pkg gen; } __attribute__((packed));#endif /* __NDCTL_HYPERV_H__ */ ndctl/lib/intel.h +1
-1@@ -141,7 +141,6 @@ struct nd_intel_lss { } __attribute__((packed));struct nd_pkg_intel { -struct nd_cmd_pkg gen;union {struct nd_intel_smart smart;struct nd_intel_smart_inject inject;@@ -154,6 +153,7 @@ struct nd_pkg_intel {struct nd_intel_fw_finish_query fquery;struct nd_intel_lss lss; }; +struct nd_cmd_pkg gen; };#define ND_INTEL_STATUS_MASK 0xffffndctl/lib/msft.h +1
-1@@ -41,8 +41,8 @@ union ndn_msft_cmd { } __attribute__((packed));struct ndn_pkg_msft { -struct nd_cmd_pkg gen;union ndn_msft_cmd u; +struct nd_cmd_pkg gen; } __attribute__((packed));#define NDN_MSFT_STATUS_MASK 0xffffndctl/lib/papr.h +1
-1@@ -8,8 +8,8 @@/* Wraps a nd_cmd generic header with pdsm header */ struct nd_pkg_papr { -struct nd_cmd_pkg gen;struct nd_pkg_pdsm pdsm; +struct nd_cmd_pkg gen; };#endif /* __PAPR_H__ */ ndctl/libndctl-nfit.h +1
-1@@ -77,13 +77,13 @@ struct nd_cmd_ars_err_inj_stat { } __attribute__((packed));struct nd_cmd_bus { -struct nd_cmd_pkg gen;union {struct nd_cmd_ars_err_inj_stat err_inj_stat;struct nd_cmd_ars_err_inj_clr err_inj_clr;struct nd_cmd_ars_err_inj err_inj;struct nd_cmd_translate_spa xlat_spa; }; +struct nd_cmd_pkg gen; };int ndctl_bus_is_nfit_cmd_supported (struct ndctl_bus *bus,int cmd);
Alison Schofield
maintainerQuoted 14 lines · Dave Jiang
Quoted 11 lines · Alison Schofield
Placing
nd_cmd_pkganywhere but at the end of a structure can lead to undefined behavior for the flex array member. Movend_cmd_pkgto the end of all affected structures.Reproduce using Clang:
~/git/ndctl$ rm -rf build
~/git/ndctl$ CC=clang meson setup build
~/git/ndctl$ meson compile -C build
../ndctl/lib/hpe1.h:324:20: warning: field 'gen' with variable sized type 'structnd_cmd_pkg' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
Quoted 7 lines
Quoted 3 lines
Reported-by Cristian Rodriguez <[email protected]>Signed-off-by Alison Schofield <[email protected]>Reviewed-by Dave Jiang <[email protected]>I wonder if a comment needs to be inserted to the definition of '
nd_cmd_pkg' to warn users that the struct should never be placed anywhere besides the end when used as a member of another struct.
Yes, a comment will be useful.
I'll add it upon applying if I don't rev for anything else. Thanks for the review!