common: avb_verify: prevent opening incorrect session
PATCH 1/1 common: avb_verify: prevent opening incorrect session
The arg->session is not valid if arg->ret != NULL, so can't be assigned. Leave retry for just "ret" error to save same behaviour.
--- common/avb_verify.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
common/avb_verify.c +8 -4
@@ -619,10 +619,14 @@ static int get_open_session(struct AvbOpsData *ops_data)memset (&arg,0 ,sizeof (arg));tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); rc =tee_open_session (tee, &arg,0 ,NULL ); -if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } +if (rc) +continue ; + +if (arg.ret) +return AVB_IO_RESULT_ERROR_IO ; + + ops_data->tee = tee; + ops_data->session = arg.session; }return 0 ;
Signature · 1 line
2.34.1
Quoted 16 lines · Ivan Khoronzhuk
The
arg->sessionis not valid ifarg->ret!= NULL, so can't be assigned. Leave retry for just "ret" error to save same behaviour.Signed-off-by Ivan Khoronzhuk <[email protected]>--- common/avb_verify.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)common/avb_verify.c +0
-0@@ -619,10 +619,14 @@ static int get_open_session(struct AvbOpsData *ops_data)memset (&arg,0 ,sizeof (arg));tee_optee_ta_uuid_to_octets (arg.uuid, &uuid);
common/avb_verify.c static int get_open_session(struct AvbOpsData *ops_data) · line 626
Quoted 10 lines
common/avb_verify.c +5
-4rc =tee_open_session (tee, &arg,0 ,NULL ); -if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } +if (rc) +continue ; + +if (arg.ret) +return AVB_IO_RESULT_ERROR_IO ;
This should probably be an errno define instead since that's what is used above.
Cheers,
Jens
Quoted 9 lines
common/avb_verify.c +3
-1+ + ops_data->tee = tee; + ops_data->session = arg.session; }return 0 ; --2.34.1
PATCH v2 1/1 common: avb_verify: prevent opening incorrect session
In reply to Ivan KhoronzhukThe arg->session is not valid if arg->ret != NULL, so can't be assigned. Leave retry for just "ret" error to save same behaviour.
--- common/avb_verify.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
common/avb_verify.c +8 -4
@@ -619,10 +619,14 @@ static int get_open_session(struct AvbOpsData *ops_data)memset (&arg,0 ,sizeof (arg));tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); rc =tee_open_session (tee, &arg,0 ,NULL ); -if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } +if (rc) +continue ; + +if (arg.ret) +return -EIO ; + + ops_data->tee = tee; + ops_data->session = arg.session; }return 0 ;
Signature · 1 line
2.34.1
Quoted 21 lines · Ivan Khoronzhuk
The
arg->sessionis not valid ifarg->ret!= NULL, so can't be assigned. Leave retry for just "ret" error to save same behaviour.Signed-off-by Ivan Khoronzhuk <[email protected]>--- common/avb_verify.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)common/avb_verify.c +1
-4@@ -619,10 +619,14 @@ static int get_open_session(struct AvbOpsData *ops_data)memset (&arg,0 ,sizeof (arg));tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); rc =tee_open_session (tee, &arg,0 ,NULL ); -if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } +if (rc)
common/avb_verify.c static int get_open_session(struct AvbOpsData *ops_data) · line 632
Quoted 10 lines
common/avb_verify.c +7
-0+continue ; + +if (arg.ret) +return -EIO ; + + ops_data->tee = tee; + ops_data->session = arg.session; }return 0 ;
It looks like this function is still slightly broken. The function should, if I understand it correctly, return usable tee and session pointers on success, else return an error code. The unconditional return 0 at the end doesn't seem right.
Thanks,
Jens
Quoted 38 lines · Jens Wiklander
Quoted 21 lines · Ivan Khoronzhuk
The
arg->sessionis not valid ifarg->ret!= NULL, so can't be assigned. Leave retry for just "ret" error to save same behaviour.Signed-off-by Ivan Khoronzhuk <[email protected]>--- common/avb_verify.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)common/avb_verify.c +1
-4@@ -619,10 +619,14 @@ static int get_open_session(struct AvbOpsData *ops_data)memset (&arg,0 ,sizeof (arg));tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); rc =tee_open_session (tee, &arg,0 ,NULL ); -if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } +if (rc)common/avb_verify.c static int get_open_session(struct AvbOpsData *ops_data) · line 632
Quoted 10 lines
common/avb_verify.c +7
-0+continue ; + +if (arg.ret) +return -EIO ; + + ops_data->tee = tee; + ops_data->session = arg.session; }return 0 ;It looks like this function is still slightly broken. The function should, if I understand it correctly, return usable tee and session pointers on success, else return an error code. The unconditional return 0 at the end doesn't seem right.
Quoted 2 lines
Thanks,
Jens
It doesn't return, it loops infinitely...
Yes, it looks so, but it's how it works. I don't see a reason why the function must loop trying to open the session that potentially never will be opened. But this is how it's implemented and I didn't wont to change this behaviour that can have some "sacral" roots, only add a fix I bother, I've mentioned it in the comment. Better would be drop this loop ofc and add the following:
+ if (ret || arg.ret)
+ return -EIO;
I can do this in v3 if you don't mind.
Signature · 2 lines
Regards, Ivan Khoronzhuk
Quoted 40 lines · Ivan Khoronzhuk
Quoted 38 lines · Jens Wiklander
Quoted 21 lines · Ivan Khoronzhuk
The
arg->sessionis not valid ifarg->ret!= NULL, so can't be assigned. Leave retry for just "ret" error to save same behaviour.Signed-off-by Ivan Khoronzhuk <[email protected]>--- common/avb_verify.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)common/avb_verify.c +1
-4@@ -619,10 +619,14 @@ static int get_open_session(struct AvbOpsData *ops_data)memset (&arg,0 ,sizeof (arg));tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); rc =tee_open_session (tee, &arg,0 ,NULL ); -if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } +if (rc)common/avb_verify.c static int get_open_session(struct AvbOpsData *ops_data) · line 632
Quoted 10 lines
common/avb_verify.c +7
-0+continue ; + +if (arg.ret) +return -EIO ; + + ops_data->tee = tee; + ops_data->session = arg.session; }return 0 ;It looks like this function is still slightly broken. The function should, if I understand it correctly, return usable tee and session pointers on success, else return an error code. The unconditional return 0 at the end doesn't seem right.
Quoted 8 lines
Quoted 2 lines
Thanks,
JensIt doesn't return, it loops infinitely...
Yes, it looks so, but it's how it works. I don't see a reason why the function must loop trying to open the session that potentially never will be opened. But this is how it's implemented and I didn't wont to change this behaviour that can have some "sacral" roots, only add a fix I bother, I've
No worries, no need to be bug compatible here. :-)
Review
Quoted 5 lines
mentioned it in the comment. Better would be drop this loop ofc and add the following:
(quoted diff) +2
-0+ if (ret || arg.ret) + return -EIO;
A loop is needed to find the TEE device. Right now I guess there's only one and it will be found in the first round.
Quoted 2 lines
I can do this in v3 if you don't mind.
Yes, please fix the function to return an error if a session can't be found.
Thanks,
Jens
PATCH v3 1/1 common: avb_verify: prevent opening incorrect session
In reply to Ivan KhoronzhukThe arg->session is not valid if arg->ret != NULL, so can't be assigned, correct this. Also remove "while" loop as there is no reason for looping till correct session is opened.
--- common/avb_verify.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
common/avb_verify.c +19 -19
@@ -605,26 +605,26 @@ static AvbIOResult validate_vbmeta_public_key(AvbOps *ops,#ifdef CONFIG_OPTEE_TA_AVB static int get_open_session (struct AvbOpsData *ops_data) { -struct udevice *tee =NULL ; - -while (!ops_data->tee) { -const struct tee_optee_ta_uuid uuid =TA_AVB_UUID ; -struct tee_open_session_arg arg; -int rc; - - tee =tee_find_device (tee,NULL ,NULL ,NULL ); -if (!tee) -return -ENODEV ; - -memset (&arg,0 ,sizeof (arg)); -tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); - rc =tee_open_session (tee, &arg,0 ,NULL ); -if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } - } +const struct tee_optee_ta_uuid uuid =TA_AVB_UUID ; +struct tee_open_session_arg arg; +struct udevice *tee; +int rc; + +if (ops_data->tee) +return 0 ; + + tee =tee_find_device (NULL ,NULL ,NULL ,NULL ); +if (!tee) +return -ENODEV ; + +memset (&arg,0 ,sizeof (arg)); +tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); + rc =tee_open_session (tee, &arg,0 ,NULL ); +if (rc || arg.ret) +return -EIO ; + ops_data->tee = tee; + ops_data->session = arg.session;return 0 ; }
Signature · 1 line
2.34.1
Ignore this version please, will send v4.
Skipped previous comment unintentionally.
Signature · 2 lines
Regards, Ivan Khoronzhuk
PATCH v4 1/1 common: avb_verify: prevent opening incorrect session
In reply to Ivan KhoronzhukThe arg->session is not valid if arg->ret != NULL, so can't be assigned, correct this.
--- common/avb_verify.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
common/avb_verify.c +5 -4
@@ -619,10 +619,11 @@ static int get_open_session(struct AvbOpsData *ops_data)memset (&arg,0 ,sizeof (arg));tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); rc =tee_open_session (tee, &arg,0 ,NULL ); -if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } +if (rc || arg.ret) +continue ; + + ops_data->tee = tee; + ops_data->session = arg.session; }return 0 ;
Signature · 1 line
2.34.1
Any comments to this patch?
Signature · 2 lines
Regards, Ivan Khoronzhuk
Quoted 8 lines · Ivan Khoronzhuk
The
arg->sessionis not valid ifarg->ret!= NULL, so can't be assigned, correct this.Signed-off-by Ivan Khoronzhuk <[email protected]>--- common/avb_verify.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Thanks,
Jens
Quoted 24 lines
common/avb_verify.c +5
-5@@ -619,10 +619,11 @@ static int get_open_session(struct AvbOpsData *ops_data)memset (&arg,0 ,sizeof (arg));tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); rc =tee_open_session (tee, &arg,0 ,NULL ); -if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } +if (rc || arg.ret) +continue ; + + ops_data->tee = tee; + ops_data->session = arg.session; }return 0 ; --2.34.1
Quoted 5 lines · Ivan Khoronzhuk
The
arg->sessionis not valid ifarg->ret!= NULL, so can't be assigned, correct this.Signed-off-by Ivan Khoronzhuk <[email protected]>Reviewed-by Jens Wiklander <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom