In plpks_gen_wrapping_key() and plpks_wrap_object(), strlen(var.name) is
used to initialize var.namelen within the same struct initializer. This
references a member of var before initialization of var is complete.

Use the compile-time length of PLPKS_WRAPKEY_NAME instead.

Reported-by: R Nageswara Sastry <[email protected]>
Fixes: 133aa79e211d ("pseries/plpks: add HCALLs for PowerVM Key Wrapping 
Module")
Cc: [email protected] # 7.0
Signed-off-by: Srish Srinivasan <[email protected]>
Tested-by: R Nageswara Sastry <[email protected]>
---
 arch/powerpc/platforms/pseries/plpks.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/plpks.c 
b/arch/powerpc/platforms/pseries/plpks.c
index b057e378a6b3..896eda3eb65f 100644
--- a/arch/powerpc/platforms/pseries/plpks.c
+++ b/arch/powerpc/platforms/pseries/plpks.c
@@ -939,7 +939,7 @@ int plpks_gen_wrapping_key(void)
        int rc = 0, pseries_status = 0;
        struct plpks_var var = {
                .name = PLPKS_WRAPKEY_NAME,
-               .namelen = strlen(var.name),
+               .namelen = sizeof(PLPKS_WRAPKEY_NAME) - 1,
                .policy = PLPKS_WRAPPINGKEY,
                .os = PLPKS_VAR_LINUX,
                .component = PLPKS_WRAPKEY_COMPONENT
@@ -1034,7 +1034,7 @@ int plpks_wrap_object(u8 **input_buf, u32 input_len, u16 
wrap_flags,
        bool sb_enforce_bit = wrap_flags & BIT(1);
        struct plpks_var var = {
                .name = PLPKS_WRAPKEY_NAME,
-               .namelen = strlen(var.name),
+               .namelen = sizeof(PLPKS_WRAPKEY_NAME) - 1,
                .os = PLPKS_VAR_LINUX,
                .component = PLPKS_WRAPKEY_COMPONENT
        };
-- 
2.52.0


Reply via email to