Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARMv8 AES acceleration needs to be disabled on my Hikey (was Secure Stg blows chunks) #1305

Closed
lws-team opened this issue Jan 22, 2017 · 30 comments · Fixed by #1315
Closed

Comments

@lws-team
Copy link
Contributor

My TA works nicely. But if I try to start to use Secure Storage APIs, eg just this

		TEE_ObjectHandle o;
		int n;

		n = TEE_OpenPersistentObject(TEE_STORAGE_PRIVATE_REE,
					     (void *)"/client-cert.pem", 16,
					     TEE_DATA_FLAG_ACCESS_READ, &o);

We blow chunks

ERROR:   TEE-CORE: 
ERROR:   TEE-CORE: user TA prefetch-abort at address 0x0 (translation fault)
ERROR:   TEE-CORE:  esr 0x82000006  ttbr0 0x100003f0890c0   ttbr1 0x00000000   cidr 0x0
ERROR:   TEE-CORE:  cpu #6          cpsr 0x80000100
ERROR:   TEE-CORE: x0  0000000000000004 x1  0000000040007f80
ERROR:   TEE-CORE: x2  0000000000000000 x3  0000000040007f10
ERROR:   TEE-CORE: x4  0000000000000000 x5  00000000400d2ae0
ERROR:   TEE-CORE: x6  0000000000000003 x7  0000000000000000
ERROR:   TEE-CORE: x8  0000000000000000 x9  0000000000000003
ERROR:   TEE-CORE: x10 00000000400ad42c x11 000000003f06b670
ERROR:   TEE-CORE: x12 00000000400ba000 x13 00000000400087b0
ERROR:   TEE-CORE: x14 0000000000000000 x15 0000000000000000
ERROR:   TEE-CORE: x16 000000003f00ea68 x17 0000000000000000
ERROR:   TEE-CORE: x18 0000000000000000 x19 0000000000000004
ERROR:   TEE-CORE: x20 0000000040007f80 x21 00000000400e5027
ERROR:   TEE-CORE: x22 00000000400087b0 x23 0000000000000000
ERROR:   TEE-CORE: x24 000000003f095358 x25 0000000000000002
ERROR:   TEE-CORE: x26 0000000000000000 x27 0000000000000000
ERROR:   TEE-CORE: x28 000000003f06bb50 x29 0000000040007f30
ERROR:   TEE-CORE: x30 0000000040012194 elr 0000000000000000
ERROR:   TEE-CORE: sp_el0 0000000040007f30
ERROR:   TEE-CORE: Status of TA 703a6d12-eb3d-4975-8766-5a8aefd3a192 (0x3f06bd70) (active)
ERROR:   TEE-CORE: - load addr : 0x40009000    ctx-idr: 1
ERROR:   TEE-CORE: - stack: 0x40000000 34816
ERROR:   TEE-CORE: sect 0 : va 0x40000000 pa 0x3f615000 0x9000
ERROR:   TEE-CORE: sect 1 : va 0x40009000 pa 0x3f200000 0xb1000
ERROR:   TEE-CORE: sect 2 : va 0x400ba000 pa 0x3f2b1000 0x47000
ERROR:   TEE-CORE: sect 3 : va 0x40101000 pa 0x3f2f8000 0x31d000
ERROR:   TEE-CORE: sect 4 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 5 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 6 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 7 : va 0 pa 0 0
[aist_tb_client] caDo: TEEC_InvokeCommand failed (ffff3024), 168
Could not send command to Trusted Application.

I think the failed "command" is the one that inits my TA and runs the attempted Secure Storage code.

There is some init I missed out? I get the wrong idea about the API?

@lackan
Copy link

lackan commented Jan 22, 2017

I think you should use TEE_CreatePersistentObject before you invoke TEE_OpenPersistentObject.

@lws-team
Copy link
Contributor Author

Thanks... I'll try it later today and report back.

@lws-team
Copy link
Contributor Author

		static const char *payload = "hello";
		TEE_ObjectHandle o;
		int n;

		n = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE_REE,
        		(void *)"/client-cert.pem", 16,
			TEE_DATA_FLAG_ACCESS_WRITE |
				TEE_DATA_FLAG_ACCESS_READ,
			(TEE_ObjectHandle)(uintptr_t)
				TEE_DATA_FLAG_ACCESS_WRITE_META,
			payload, 5, &o);

gives...

ERROR:   USER-TA: Panic 0x0
ERROR:   TEE-CORE: TA panicked with code 0x0 usr_sp 0x400087b0 usr_lr 0x0

... it can't be a valid solution anyway because it has to support me asking for files that aren't there yet.

making o static doesn't change anything.

@lackan
Copy link

lackan commented Jan 22, 2017

What about

n = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE_REE,
        		(void *)"/client-cert.pem", 16,
			TEE_DATA_FLAG_ACCESS_WRITE |
				TEE_DATA_FLAG_ACCESS_READ,
			NULL,
			payload, 5, &o);

?

@lws-team
Copy link
Contributor Author

I found this

https://developer.trustonic.com/blog/secure-storage

he has some samples using his own proprietary TEE, but it's the same, presumably GlobalPlatform APIs. He has

    nResult = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE,
                                         IDNameObject,
                                         IDNameObjectsize,
                                         TEE_HANDLE_FLAG_PERSISTENT,
                                         NULL,
                                         initialData,
                                         sizeof(initialData),
                                         &object);

which is the same as your suggestion with NULL but this "TEE_HANDLE_FLAG_PERSISTENT".

		n = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE_REE,
        		(void *)"/client-cert.pem", 16,
			TEE_HANDLE_FLAG_PERSISTENT,
			NULL,
			payload, 5, &o);

He blows a bit more energetically but basically the same

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERROR:   TEE-CORE: 
ERROR:   TEE-CORE: user TA prefetch-abort at address 0x0 (translation fault)
ERROR:   TEE-CORE:  esr 0x82000006  ttbr0 0x100003f089040   ttbr1 0x00000000   cidr 0x0
ERROR:   TEE-CORE:  cpu #2          cpsr 0x80000100
ERROR:   TEE-CORE: x0  0000000000000004 x1  0000000040007f60
ERROR:   TEE-CORE: x2  0000000000000000 x3  0000000040007ebd
ERROR:   TEE-CORE: x4  0000000040007ebd x5  00000000ffffffff
ERROR:   TEE-CORE: x6  0000000000000001 x7  0000000000000020
ERROR:   TEE-CORE: x8  0000000000000064 x9  0000000000000003
ERROR:   TEE-CORE: x10 0000000000000000 x11 000000003f06b670
ERROR:   TEE-CORE: x12 00000000400ba000 x13 00000000400087b0
ERROR:   TEE-CORE: x14 0000000000000000 x15 0000000000000000
ERROR:   TEE-CORE: x16 000000003f094f18 x17 0000000000000000
ERROR:   TEE-CORE: x18 0000000000000000 x19 0000000000000004
ERROR:   TEE-CORE: x20 0000000040007f60 x21 00000000400e503e
ERROR:   TEE-CORE: x22 00000000400087b0 x23 0000000000000000
ERROR:   TEE-CORE: x24 000000003f095358 x25 0000000000000002
ERROR:   TEE-CORE: x26 0000000000000000 x27 0000000000000000
ERROR:   TEE-CORE: x28 000000003f06bb50 x29 0000000040007f10
ERROR:   TEE-CORE: x30 0000000040012194 elr 0000000000000000
ERROR:   TEE-CORE: sp_el0 0000000040007f10
ERROR:   TEE-CORE: Status of TA 703a6d12-eb3d-4975-8766-5a8aefd3a192 (0x3f06bd70) (active)
ERROR:   TEE-CORE: - load addr : 0x40009000    ctx-idr: 1
ERROR:   TEE-CORE: - stack: 0x40000000 34816
ERROR:   TEE-CORE: sect 0 : va 0x40000000 pa 0x3f615000 0x9000
ERROR:   TEE-CORE: sect 1 : va 0x40009000 pa 0x3f200000 0xb1000
ERROR:   TEE-CORE: sect 2 : va 0x400ba000 pa 0x3f2b1000 0x47000
ERROR:   TEE-CORE: sect 3 : va 0x40101000 pa 0x3f2f8000 0x31d000
ERROR:   TEE-CORE: sect 4 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 5 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 6 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 7 : va 0 pa 0 0

This is being built on Linaro 6.2.1 toolchain now... but everything else is working OK.

@lackan
Copy link

lackan commented Jan 22, 2017

So what you try is:

n = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE_REE,
        		(void *)"/client-cert.pem", 16,
			TEE_HANDLE_FLAG_PERSISTENT,
			NULL,
			payload, 5, &o);

and get:

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1390] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERROR:   TEE-CORE: 
ERROR:   TEE-CORE: user TA prefetch-abort at address 0x0 (translation fault)
ERROR:   TEE-CORE:  esr 0x82000006  ttbr0 0x100003f089040   ttbr1 0x00000000   cidr 0x0
ERROR:   TEE-CORE:  cpu #2          cpsr 0x80000100
ERROR:   TEE-CORE: x0  0000000000000004 x1  0000000040007f60
ERROR:   TEE-CORE: x2  0000000000000000 x3  0000000040007ebd
ERROR:   TEE-CORE: x4  0000000040007ebd x5  00000000ffffffff
ERROR:   TEE-CORE: x6  0000000000000001 x7  0000000000000020
ERROR:   TEE-CORE: x8  0000000000000064 x9  0000000000000003
ERROR:   TEE-CORE: x10 0000000000000000 x11 000000003f06b670
ERROR:   TEE-CORE: x12 00000000400ba000 x13 00000000400087b0
ERROR:   TEE-CORE: x14 0000000000000000 x15 0000000000000000
ERROR:   TEE-CORE: x16 000000003f094f18 x17 0000000000000000
ERROR:   TEE-CORE: x18 0000000000000000 x19 0000000000000004
ERROR:   TEE-CORE: x20 0000000040007f60 x21 00000000400e503e
ERROR:   TEE-CORE: x22 00000000400087b0 x23 0000000000000000
ERROR:   TEE-CORE: x24 000000003f095358 x25 0000000000000002
ERROR:   TEE-CORE: x26 0000000000000000 x27 0000000000000000
ERROR:   TEE-CORE: x28 000000003f06bb50 x29 0000000040007f10
ERROR:   TEE-CORE: x30 0000000040012194 elr 0000000000000000
ERROR:   TEE-CORE: sp_el0 0000000040007f10
ERROR:   TEE-CORE: Status of TA 703a6d12-eb3d-4975-8766-5a8aefd3a192 (0x3f06bd70) (active)
ERROR:   TEE-CORE: - load addr : 0x40009000    ctx-idr: 1
ERROR:   TEE-CORE: - stack: 0x40000000 34816
ERROR:   TEE-CORE: sect 0 : va 0x40000000 pa 0x3f615000 0x9000
ERROR:   TEE-CORE: sect 1 : va 0x40009000 pa 0x3f200000 0xb1000
ERROR:   TEE-CORE: sect 2 : va 0x400ba000 pa 0x3f2b1000 0x47000
ERROR:   TEE-CORE: sect 3 : va 0x40101000 pa 0x3f2f8000 0x31d000
ERROR:   TEE-CORE: sect 4 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 5 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 6 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 7 : va 0 pa 0 0

?

@lws-team
Copy link
Contributor Author

Yeah.

But I just tried xtest as a compiler sanity check... xtest has lots of problems now.

Let me back up and try a different toolchain version that xtest is able to like.

Strange though because my stuff is working fine in OP-TEE with that toolchain without secure storage.

@lackan
Copy link

lackan commented Jan 22, 2017

But I don't think your code is right, IMO it should change to:

n = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE_REE,
        		(void *)"/client-cert.pem", 16,
			TEE_DATA_FLAG_ACCESS_WRITE |
				TEE_DATA_FLAG_ACCESS_READ |
                                TEE_DATA_FLAG_ACCESS_WRITE_META,
			NULL,
			payload, 5, &o);

And about the TEE_HANDLE_FLAG_PERSISTENT, it seems it's not to use here.

@lws-team
Copy link
Contributor Author

Yeah... there is no reason to think that code is correct. I dived into optee_test and dredged out of pieces that looked reasonable to try. And then I looked at someone else's TEE examples for a different TEE.

Even so though, the symptom I'm getting is not a legit response to some wrong flags.

		n = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE_REE,
        		(void *)"/client-cert.pem", 16,
			TEE_DATA_FLAG_ACCESS_WRITE |
				TEE_DATA_FLAG_ACCESS_READ |
                                TEE_DATA_FLAG_ACCESS_WRITE_META,
			NULL,
			payload, 5, &o);

gives

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERR [1389] TEES:tee_supp_param_to_va:770: tee_supp_param_to_va: 

ERROR:   TEE-CORE: 
ERROR:   TEE-CORE: user TA prefetch-abort at address 0x0 (translation fault)
ERROR:   TEE-CORE:  esr 0x82000006  ttbr0 0x100003f0890a0   ttbr1 0x00000000   cidr 0x0
ERROR:   TEE-CORE:  cpu #5          cpsr 0x80000100
ERROR:   TEE-CORE: x0  0000000000000004 x1  0000000040007f60
ERROR:   TEE-CORE: x2  0000000000000000 x3  0000000040007ebd
ERROR:   TEE-CORE: x4  0000000040007ebd x5  00000000ffffffff
ERROR:   TEE-CORE: x6  0000000000000001 x7  0000000000000020
ERROR:   TEE-CORE: x8  0000000000000064 x9  0000000000000003
ERROR:   TEE-CORE: x10 0000000000000000 x11 000000003f06b670
ERROR:   TEE-CORE: x12 00000000400ba000 x13 00000000400087b0
ERROR:   TEE-CORE: x14 0000000000000000 x15 0000000000000000
ERROR:   TEE-CORE: x16 000000003f094f18 x17 0000000000000000
ERROR:   TEE-CORE: x18 0000000000000000 x19 0000000000000004
ERROR:   TEE-CORE: x20 0000000040007f60 x21 00000000400e5036
ERROR:   TEE-CORE: x22 00000000400087b0 x23 0000000000000000
ERROR:   TEE-CORE: x24 000000003f095358 x25 0000000000000002
ERROR:   TEE-CORE: x26 0000000000000000 x27 0000000000000000
ERROR:   TEE-CORE: x28 000000003f06bb50 x29 0000000040007f10
ERROR:   TEE-CORE: x30 0000000040012194 elr 0000000000000000
ERROR:   TEE-CORE: sp_el0 0000000040007f10
ERROR:   TEE-CORE: Status of TA 703a6d12-eb3d-4975-8766-5a8aefd3a192 (0x3f06bd70) (active)
ERROR:   TEE-CORE: - load addr : 0x40009000    ctx-idr: 1
ERROR:   TEE-CORE: - stack: 0x40000000 34816
ERROR:   TEE-CORE: sect 0 : va 0x40000000 pa 0x3f615000 0x9000
ERROR:   TEE-CORE: sect 1 : va 0x40009000 pa 0x3f200000 0xb1000
ERROR:   TEE-CORE: sect 2 : va 0x400ba000 pa 0x3f2b1000 0x47000
ERROR:   TEE-CORE: sect 3 : va 0x40101000 pa 0x3f2f8000 0x31d000
ERROR:   TEE-CORE: sect 4 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 5 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 6 : va 0 pa 0 0
ERROR:   TEE-CORE: sect 7 : va 0 pa 0 0

and as I say xtest is broken here atm. So I think it's an "unnatural situation" and my problem is at a deeper than the Secure Storage example. I just downloaded gcc 5.2, let me see what happens there.

I can't use 4.9.3 because it breaks BoringSSL ECC code.

@lackan
Copy link

lackan commented Jan 22, 2017

Yeah, your problem seems not related much to the Secure Storage example...

@lws-team
Copy link
Contributor Author

I agree, but the whole stack is working if I don't call that API (barring xtest...). Anyway let's see what gcc 5.2 does.

@lws-team
Copy link
Contributor Author

Hum doesn't obviously seem related to gcc version... 4.9, 5.3 and 6.2.1 give the same results.

  • rolling back optee_os to current master and no changes didn't help

  • rolling back optee_client (tee-supplicant) didn't help

  • my TA doesn't even get loaded with these tests

  • checked tee-supplicant and libteec* are binding correctly with ldd

Most of the tests are OK but then

o XTEST_TEE_4003_NO_XTS.10 Cipher case 9 algo 0x10000110 line 2258
/projects/aist-tb/optee_test/host/xtest/xtest_4000.c:2451: out has an unexpected content:
Got
  43:69:70:68 65:72:20:62 6C:6F:63:6B 20:63:68:61  Cipher block cha
  69:6E:69:6E 67:20:28:43 42:43:29:20 69:73:20:61  ining (CBC) is a
  20:63:6F:6D 6D:6F:6E:20 63:68:61:69 6E:69:6E:67   common chaining
  20:6D:6F:64 65:20:69:6E 20:77:68:69 63:68:20:74   mode in which t
  68:65:20:70 72:65:76:69 6F:75:73:20 62:6C:6F:63  he previous bloc
  6B:27:73:20 63:69:70:68 65:72:74:65 78:74:20:69  k's ciphertext i
  73:20:78:6F 72:65:64:20 77:69:74:68 20:74:68:65  s xored with the
  20:63:75:72 72:65:6E:74 20:62:6C:6F 63:6B:27:73   current block's
  20:70:6C:61 69:6E:74:65 78:74:20:62 65:66:6F:72   plaintext befor
  3F:A0:47:A2 76:AD:C1:41 0B:5E:72:B2 61:FF:A4:F3  ?.G.v..A.^r.a...
Expected
  43:69:70:68 65:72:20:62 6C:6F:63:6B 20:63:68:61  Cipher block cha
  69:6E:69:6E 67:20:28:43 42:43:29:20 69:73:20:61  ining (CBC) is a
  20:63:6F:6D 6D:6F:6E:20 63:68:61:69 6E:69:6E:67   common chaining
  20:6D:6F:64 65:20:69:6E 20:77:68:69 63:68:20:74   mode in which t
  68:65:20:70 72:65:76:69 6F:75:73:20 62:6C:6F:63  he previous bloc
  6B:27:73:20 63:69:70:68 65:72:74:65 78:74:20:69  k's ciphertext i
  73:20:78:6F 72:65:64:20 77:69:74:68 20:74:68:65  s xored with the
  20:63:75:72 72:65:6E:74 20:62:6C:6F 63:6B:27:73   current block's
  20:70:6C:61 69:6E:74:65 78:74:20:62 65:66:6F:72   plaintext befor
  65:20:65:6E 63:72:79:70 74:69:6F:6E 2E:2E:2E:2E  e encryption....
  XTEST_TEE_4003_NO_XTS.10 FAILED

The corrupted last 16 bytes are always the same.

another strange failure is

* XTEST_TEE_6003 Test TEE_ReadObjectData
o XTEST_TEE_6003.1 Storage id: 00000001
/projects/aist-tb/optee_test/host/xtest/xtest_6000.c:766: fs_create(&sess, file_02, sizeof(file_02), 0x00000002, 0, data_01, sizeof(data_01), &obj, storage_id) has an unexpected value: 0xffff0003 = TEEC_ERROR_ACCESS_CONFLICT, expected 0x0 = TEEC_SUCCESS
  XTEST_TEE_6003.1 FAILED

ACCESS_CONFLICT seems related to permissions... the permissions down /data are a bit strange

root@hikey1:~# ls -l `find /data`
-rwsr-S--- 1 root root 8660 Jan 22 13:27 /data/tee/9E271E73FBAA7545A77138CAA6F0CCA6/021102
--wxr-S--- 1 root root 8660 Jan 22 13:09 /data/tee/9E271E73FBAA7545A77138CAA6F0CCA6/66696C655F310000
--wxr-S--- 1 root root 8660 Jan 22 13:09 /data/tee/9E271E73FBAA7545A77138CAA6F0CCA6/66696C655F320000
--wxr-S--- 1 root root 8660 Jan 22 13:09 /data/tee/9E271E73FBAA7545A77138CAA6F0CCA6/66696C655F330000
-r-------- 1 root root 8660 Jan 22 23:34 /data/tee/A7F289B6DF8A7A479F9932E90C0AD0A2/021102
-r-------- 1 root root 8660 Jan 22 23:34 /data/tee/A7F289B6DF8A7A479F9932E90C0AD0A2/66696C655F300000
-rwx------ 1 root root 8660 Jan 22 13:27 /data/tee/A7F289B6DF8A7A479F9932E90C0AD0A2/66696C655F310000
-rwsr-S--- 1 root root 8660 Jan 22 13:27 /data/tee/A7F289B6DF8A7A479F9932E90C0AD0A2/66696C655F320000
-rwsr-S--- 1 root root 8660 Jan 22 13:27 /data/tee/A7F289B6DF8A7A479F9932E90C0AD0A2/66696C655F330000

/data:
total 4
drwx------ 4 root root 4096 Jan 22 13:27 tee

/data/tee:
total 8
drwx------ 2 root root 4096 Jan 22 13:27 9E271E73FBAA7545A77138CAA6F0CCA6
drwx------ 2 root root 4096 Jan 23 02:13 A7F289B6DF8A7A479F9932E90C0AD0A2

/data/tee/9E271E73FBAA7545A77138CAA6F0CCA6:
total 48
-rwsr-S--- 1 root root 8660 Jan 22 13:27 021102
--wxr-S--- 1 root root 8660 Jan 22 13:09 66696C655F310000
--wxr-S--- 1 root root 8660 Jan 22 13:09 66696C655F320000
--wxr-S--- 1 root root 8660 Jan 22 13:09 66696C655F330000

/data/tee/A7F289B6DF8A7A479F9932E90C0AD0A2:
total 60
-r-------- 1 root root 8660 Jan 22 23:34 021102
-r-------- 1 root root 8660 Jan 22 23:34 66696C655F300000
-rwx------ 1 root root 8660 Jan 22 13:27 66696C655F310000
-rwsr-S--- 1 root root 8660 Jan 22 13:27 66696C655F320000
-rwsr-S--- 1 root root 8660 Jan 22 13:27 66696C655F330000
root@hikey1:~# 

@vchong
Copy link
Contributor

vchong commented Jan 23, 2017

For test 4000/4003, there were some possibly related patches from 3 days ago. Do your repos have them?
#1301
OP-TEE/optee_test#166

@lws-team
Copy link
Contributor Author

Thanks... I updated the optee_os one, but I didn't update the optee_test one because I have seen it work with no errors.

I'll try it, but the original issue is we die strangely using the fs api without xtest involved at all. So I don't think the root cause can be related to xtest, it's something else on my system that changed.

Since I rolled back optee_os and tee_supplicant to be unpatched upstream, the only other big change is I removed UEFI, a ROMFS with the kernel + dtb + initramfs is now BL33. I patched a-t-f to parse the ROMFS and boot into the kernel directly, and to adapt the DTB at runtime, detect the extra 1GB of memory etc. Linux boots well, my TA functions well in optee... but something broken somewhere it seems.

@lws-team
Copy link
Contributor Author

The fun is still going on with this one... I reverted all my patches-on-top except the elimination of UEFI and rebased it to clean pieces from earlier today. On GCC4.9, or GCC6.2.1, optee_test feels the same way, only these errors

regression_4003_NO_XTS.10 FAILED first error at /projects/aist-tb/optee_test/host/xtest/xtest_4000.c:2392
regression_4003_NO_XTS FAILED
regression_4003_XTS.37 FAILED first error at /projects/aist-tb/optee_test/host/xtest/xtest_4000.c:2544
regression_4003_XTS.38 FAILED first error at /projects/aist-tb/optee_test/host/xtest/xtest_4000.c:2544
regression_4003_XTS FAILED

The problem is the same, consistent corruption at the end

o regression_4003_NO_XTS.10 Cipher case 9 algo 0x10000110 line 2195
actual out side 0
actual out size final 160
/projects/aist-tb/optee_test/host/xtest/xtest_4000.c:2392: out has an unexpected content:
Got
  43:69:70:68 65:72:20:62 6C:6F:63:6B 20:63:68:61  Cipher block cha
  69:6E:69:6E 67:20:28:43 42:43:29:20 69:73:20:61  ining (CBC) is a
  20:63:6F:6D 6D:6F:6E:20 63:68:61:69 6E:69:6E:67   common chaining
  20:6D:6F:64 65:20:69:6E 20:77:68:69 63:68:20:74   mode in which t
  68:65:20:70 72:65:76:69 6F:75:73:20 62:6C:6F:63  he previous bloc
  6B:27:73:20 63:69:70:68 65:72:74:65 78:74:20:69  k's ciphertext i
  73:20:78:6F 72:65:64:20 77:69:74:68 20:74:68:65  s xored with the
  20:63:75:72 72:65:6E:74 20:62:6C:6F 63:6B:27:73   current block's
  20:70:6C:61 69:6E:74:65 78:74:20:62 65:66:6F:72   plaintext befor
  3F:A0:47:A2 76:AD:C1:41 0B:5E:72:B2 61:FF:A4:F3  ?.G.v..A.^r.a...
Expected
  43:69:70:68 65:72:20:62 6C:6F:63:6B 20:63:68:61  Cipher block cha
  69:6E:69:6E 67:20:28:43 42:43:29:20 69:73:20:61  ining (CBC) is a
  20:63:6F:6D 6D:6F:6E:20 63:68:61:69 6E:69:6E:67   common chaining
  20:6D:6F:64 65:20:69:6E 20:77:68:69 63:68:20:74   mode in which t
  68:65:20:70 72:65:76:69 6F:75:73:20 62:6C:6F:63  he previous bloc
  6B:27:73:20 63:69:70:68 65:72:74:65 78:74:20:69  k's ciphertext i
  73:20:78:6F 72:65:64:20 77:69:74:68 20:74:68:65  s xored with the
  20:63:75:72 72:65:6E:74 20:62:6C:6F 63:6B:27:73   current block's
  20:70:6C:61 69:6E:74:65 78:74:20:62 65:66:6F:72   plaintext befor
  65:20:65:6E 63:72:79:70 74:69:6F:6E 2E:2E:2E:2E  e encryption....
  regression_4003_NO_XTS.10 FAILED

and

o regression_4003_XTS.37 Cipher case 36 algo 0x10000410 line 2260
/projects/aist-tb/optee_test/host/xtest/xtest_4000.c:2544: out has an unexpected content:
Got
  38:B4:58:12 EF:43:A0:5B D9:57:E5:45 90:7E:22:3B  8.X..C.[.W.E.~";
  95:4A:B4:AA F0:88:30:3A D9:10:EA:DF 14:B4:2B:E6  .J....0:......+.
  8B:24:61:14 9D:8C:8B:A8 5F:99:2B:E9 70:BC:62:1F  .$a....._.+.p.b.
  1B:06:57:3F 63:E8:67:BF 58:75:AC:AF A0:4E:42:CC  ..W?c.g.Xu...NB.
  BD:7B:D3:C2 A0:FB:1F:FF 79:1E:C5:EC 36:C6:6A:E4  .{......y...6.j.
  AC:1E:80:6D 81:FB:F7:09 DB:E2:9E:47 1F:AD:38:54  ...m.......G..8T
  9C:8E:66:F5 34:5D:7C:1E B9:4F:40:5D 1E:C7:85:CC  ..f.4]|..O@]....
  6F:6A:68:F6 25:4D:D8:33 9F:9D:84:05 7E:01:A1:77  ojh.%M.3....~..w
  41:99:04:82 99:95:16:B5 61:1A:38:F4 1B:B6:47:8E  A.......a.8...G.
  6F:17:3F:32 08:05:DD:71 B1:93:2F:C3 33:CB:9E:E3  o.?2...q../.3...
  99:36:BE:EA 9A:D9:6F:A1 0F:B4:11:2B 90:17:34:DD  .6....o....+..4.
  AD:40:BC:18 78:99:5F:8E 11:AE:E7:D1 41:A2:F5:D4  [email protected]._.....A...
  8B:7A:4E:1E 7F:0B:2C:04 83:0E:69:A4 FD:13:78:41  .zN...,...i...xA
  1C:2F:28:7E DF:48:C6:C4 E5:C2:47:A1 96:80:F7:FE  ./(~.H....G.....
  41:CE:FB:D4 9B:58:21:06 E3:61:6C:BB E4:DF:B2:34  A....X!..al....4
  4B:2A:E9:51 93:91:F3:E0 FB:49:22:25 4B:1D:6D:2D  K*.Q.....I"%K.m-
  19:C6:D4:D5 37:B3:A2:6F 3B:CC:51:58 8B:32:F3:EC  ....7..o;.QX.2..
  A0:82:9B:6A 5A:C7:25:78 FB:81:4F:B4 3C:F8:0D:64  ...jZ.%x..O.<..d
  A2:33:E3:F9 97:A3:F0:26 83:34:2F:2B 33:D2:5B:49  .3.....&.4/+3.[I
  25:36:B9:3B EC:B2:F5:E1 A8:B8:2F:5B 88:33:42:72  %6.;....../[.3Br
  9E:8A:E0:9D 16:93:88:41 A2:1A:97:FB 54:3E:EA:3B  .......A....T>.;
  BF:F5:9F:13 C1:A1:84:49 E3:98:70:1C 1A:D5:16:48  .......I..p....H
  34:6C:BC:04 C2:7B:B2:DA 3B:93:A1:37 2C:CA:E5:48  4l...{..;..7,..H
  FB:53:BE:E4 76:F9:E9:C9 17:73:B1:BB 19:82:83:94  .S..v....s......
  D5:5D:3E:1A 20:ED:69:11 3A:86:0B:68 29:FF:A8:47  .]>. .i.:..h)..G
  22:46:04:43 50:70:22:1B 25:7E:8D:FF 78:36:15:D2  "F.CPp".%~..x6..
  CA:E4:80:3A 93:AA:43:34 AB:48:2A:0A FA:C9:C0:AE  ...:..C4.H*.....
  DA:70:B4:5A 48:1D:F5:DE C5:DF:8C:C0 F4:23:C7:7A  .p.ZH........#.z
  5F:D4:6C:D3 12:02:1D:4B 43:88:62:41 9A:79:1B:E0  _.l....KC.bA.y..
  3B:B4:D9:7C 0E:59:57:85 42:53:1B:A4 66:A8:3B:AF  ;..|.YW.BS..f.;.
  D7:7F:F9:BD 21:94:4D:82 4D:16:74:61 30:43:E3:D3  ....!.M.M.ta0C..
  59:3A:1B:D1 03:E6:E9:19 53:18:2E:17 1C:7E:15:3F  Y:......S....~.?
Expected
  38:B4:58:12 EF:43:A0:5B D9:57:E5:45 90:7E:22:3B  8.X..C.[.W.E.~";
  95:4A:B4:AA F0:88:30:3A D9:10:EA:DF 14:B4:2B:E6  .J....0:......+.
  8B:24:61:14 9D:8C:8B:A8 5F:99:2B:E9 70:BC:62:1F  .$a....._.+.p.b.
  1B:06:57:3F 63:E8:67:BF 58:75:AC:AF A0:4E:42:CC  ..W?c.g.Xu...NB.
  BD:7B:D3:C2 A0:FB:1F:FF 79:1E:C5:EC 36:C6:6A:E4  .{......y...6.j.
  AC:1E:80:6D 81:FB:F7:09 DB:E2:9E:47 1F:AD:38:54  ...m.......G..8T
  9C:8E:66:F5 34:5D:7C:1E B9:4F:40:5D 1E:C7:85:CC  ..f.4]|..O@]....
  6F:6A:68:F6 25:4D:D8:33 9F:9D:84:05 7E:01:A1:77  ojh.%M.3....~..w
  41:99:04:82 99:95:16:B5 61:1A:38:F4 1B:B6:47:8E  A.......a.8...G.
  6F:17:3F:32 08:05:DD:71 B1:93:2F:C3 33:CB:9E:E3  o.?2...q../.3...
  99:36:BE:EA 9A:D9:6F:A1 0F:B4:11:2B 90:17:34:DD  .6....o....+..4.
  AD:40:BC:18 78:99:5F:8E 11:AE:E7:D1 41:A2:F5:D4  [email protected]._.....A...
  8B:7A:4E:1E 7F:0B:2C:04 83:0E:69:A4 FD:13:78:41  .zN...,...i...xA
  1C:2F:28:7E DF:48:C6:C4 E5:C2:47:A1 96:80:F7:FE  ./(~.H....G.....
  41:CE:FB:D4 9B:58:21:06 E3:61:6C:BB E4:DF:B2:34  A....X!..al....4
  4B:2A:E9:51 93:91:F3:E0 FB:49:22:25 4B:1D:6D:2D  K*.Q.....I"%K.m-
  19:C6:D4:D5 37:B3:A2:6F 3B:CC:51:58 8B:32:F3:EC  ....7..o;.QX.2..
  A0:82:9B:6A 5A:C7:25:78 FB:81:4F:B4 3C:F8:0D:64  ...jZ.%x..O.<..d
  A2:33:E3:F9 97:A3:F0:26 83:34:2F:2B 33:D2:5B:49  .3.....&.4/+3.[I
  25:36:B9:3B EC:B2:F5:E1 A8:B8:2F:5B 88:33:42:72  %6.;....../[.3Br
  9E:8A:E0:9D 16:93:88:41 A2:1A:97:FB 54:3E:EA:3B  .......A....T>.;
  BF:F5:9F:13 C1:A1:84:49 E3:98:70:1C 1A:D5:16:48  .......I..p....H
  34:6C:BC:04 C2:7B:B2:DA 3B:93:A1:37 2C:CA:E5:48  4l...{..;..7,..H
  FB:53:BE:E4 76:F9:E9:C9 17:73:B1:BB 19:82:83:94  .S..v....s......
  D5:5D:3E:1A 20:ED:69:11 3A:86:0B:68 29:FF:A8:47  .]>. .i.:..h)..G
  22:46:04:43 50:70:22:1B 25:7E:8D:FF 78:36:15:D2  "F.CPp".%~..x6..
  CA:E4:80:3A 93:AA:43:34 AB:48:2A:0A FA:C9:C0:AE  ...:..C4.H*.....
  DA:70:B4:5A 48:1D:F5:DE C5:DF:8C:C0 F4:23:C7:7A  .p.ZH........#.z
  5F:D4:6C:D3 12:02:1D:4B 43:88:62:41 9A:79:1B:E0  _.l....KC.bA.y..
  3B:B4:D9:7C 0E:59:57:85 42:53:1B:A4 66:A8:3B:AF  ;..|.YW.BS..f.;.
  92:CE:FC:15 1B:5C:C1:61 1A:16:78:93 81:9B:63:FB  .....\.a..x...c.
  8A:6B:18:E8 6D:E6:02:90 FA:72:B7:97 B0:CE:59:F3  .k..m....r....Y.
  regression_4003_XTS.37 FAILED
o regression_4003_XTS.38 Cipher case 37 algo 0x10000410 line 2260
/projects/aist-tb/optee_test/host/xtest/xtest_4000.c:2544: out has an unexpected content:
Got
  00:01:02:03 04:05:06:07 08:09:0A:0B 0C:0D:0E:0F  ................
  10:11:12:13 14:15:16:17 18:19:1A:1B 1C:1D:1E:1F  ................
  20:21:22:23 24:25:26:27 28:29:2A:2B 2C:2D:2E:2F   !"#$%&'()*+,-./
  30:31:32:33 34:35:36:37 38:39:3A:3B 3C:3D:3E:3F  0123456789:;<=>?
  40:41:42:43 44:45:46:47 48:49:4A:4B 4C:4D:4E:4F  @ABCDEFGHIJKLMNO
  50:51:52:53 54:55:56:57 58:59:5A:5B 5C:5D:5E:5F  PQRSTUVWXYZ[\]^_
  60:61:62:63 64:65:66:67 68:69:6A:6B 6C:6D:6E:6F  `abcdefghijklmno
  70:71:72:73 74:75:76:77 78:79:7A:7B 7C:7D:7E:7F  pqrstuvwxyz{|}~.
  80:81:82:83 84:85:86:87 88:89:8A:8B 8C:8D:8E:8F  ................
  90:91:92:93 94:95:96:97 98:99:9A:9B 9C:9D:9E:9F  ................
  A0:A1:A2:A3 A4:A5:A6:A7 A8:A9:AA:AB AC:AD:AE:AF  ................
  B0:B1:B2:B3 B4:B5:B6:B7 B8:B9:BA:BB BC:BD:BE:BF  ................
  C0:C1:C2:C3 C4:C5:C6:C7 C8:C9:CA:CB CC:CD:CE:CF  ................
  D0:D1:D2:D3 D4:D5:D6:D7 D8:D9:DA:DB DC:DD:DE:DF  ................
  E0:E1:E2:E3 E4:E5:E6:E7 E8:E9:EA:EB EC:ED:EE:EF  ................
  F0:F1:F2:F3 F4:F5:F6:F7 F8:F9:FA:FB FC:FD:FE:FF  ................
  00:01:02:03 04:05:06:07 08:09:0A:0B 0C:0D:0E:0F  ................
  10:11:12:13 14:15:16:17 18:19:1A:1B 1C:1D:1E:1F  ................
  20:21:22:23 24:25:26:27 28:29:2A:2B 2C:2D:2E:2F   !"#$%&'()*+,-./
  30:31:32:33 34:35:36:37 38:39:3A:3B 3C:3D:3E:3F  0123456789:;<=>?
  40:41:42:43 44:45:46:47 48:49:4A:4B 4C:4D:4E:4F  @ABCDEFGHIJKLMNO
  50:51:52:53 54:55:56:57 58:59:5A:5B 5C:5D:5E:5F  PQRSTUVWXYZ[\]^_
  60:61:62:63 64:65:66:67 68:69:6A:6B 6C:6D:6E:6F  `abcdefghijklmno
  70:71:72:73 74:75:76:77 78:79:7A:7B 7C:7D:7E:7F  pqrstuvwxyz{|}~.
  80:81:82:83 84:85:86:87 88:89:8A:8B 8C:8D:8E:8F  ................
  90:91:92:93 94:95:96:97 98:99:9A:9B 9C:9D:9E:9F  ................
  A0:A1:A2:A3 A4:A5:A6:A7 A8:A9:AA:AB AC:AD:AE:AF  ................
  B0:B1:B2:B3 B4:B5:B6:B7 B8:B9:BA:BB BC:BD:BE:BF  ................
  C0:C1:C2:C3 C4:C5:C6:C7 C8:C9:CA:CB CC:CD:CE:CF  ................
  D0:D1:D2:D3 D4:D5:D6:D7 D8:D9:DA:DB DC:DD:DE:DF  ................
  02:67:EF:11 24:AD:72:0F 70:BF:1E:E8 92:6B:1A:E9  .g..$.r.p....k..
  E1:60:74:D8 68:FE:74:D2 C0:CC:42:8B AB:01:95:E8  .`t.h.t...B.....
Expected
  00:01:02:03 04:05:06:07 08:09:0A:0B 0C:0D:0E:0F  ................
  10:11:12:13 14:15:16:17 18:19:1A:1B 1C:1D:1E:1F  ................
  20:21:22:23 24:25:26:27 28:29:2A:2B 2C:2D:2E:2F   !"#$%&'()*+,-./
  30:31:32:33 34:35:36:37 38:39:3A:3B 3C:3D:3E:3F  0123456789:;<=>?
  40:41:42:43 44:45:46:47 48:49:4A:4B 4C:4D:4E:4F  @ABCDEFGHIJKLMNO
  50:51:52:53 54:55:56:57 58:59:5A:5B 5C:5D:5E:5F  PQRSTUVWXYZ[\]^_
  60:61:62:63 64:65:66:67 68:69:6A:6B 6C:6D:6E:6F  `abcdefghijklmno
  70:71:72:73 74:75:76:77 78:79:7A:7B 7C:7D:7E:7F  pqrstuvwxyz{|}~.
  80:81:82:83 84:85:86:87 88:89:8A:8B 8C:8D:8E:8F  ................
  90:91:92:93 94:95:96:97 98:99:9A:9B 9C:9D:9E:9F  ................
  A0:A1:A2:A3 A4:A5:A6:A7 A8:A9:AA:AB AC:AD:AE:AF  ................
  B0:B1:B2:B3 B4:B5:B6:B7 B8:B9:BA:BB BC:BD:BE:BF  ................
  C0:C1:C2:C3 C4:C5:C6:C7 C8:C9:CA:CB CC:CD:CE:CF  ................
  D0:D1:D2:D3 D4:D5:D6:D7 D8:D9:DA:DB DC:DD:DE:DF  ................
  E0:E1:E2:E3 E4:E5:E6:E7 E8:E9:EA:EB EC:ED:EE:EF  ................
  F0:F1:F2:F3 F4:F5:F6:F7 F8:F9:FA:FB FC:FD:FE:FF  ................
  00:01:02:03 04:05:06:07 08:09:0A:0B 0C:0D:0E:0F  ................
  10:11:12:13 14:15:16:17 18:19:1A:1B 1C:1D:1E:1F  ................
  20:21:22:23 24:25:26:27 28:29:2A:2B 2C:2D:2E:2F   !"#$%&'()*+,-./
  30:31:32:33 34:35:36:37 38:39:3A:3B 3C:3D:3E:3F  0123456789:;<=>?
  40:41:42:43 44:45:46:47 48:49:4A:4B 4C:4D:4E:4F  @ABCDEFGHIJKLMNO
  50:51:52:53 54:55:56:57 58:59:5A:5B 5C:5D:5E:5F  PQRSTUVWXYZ[\]^_
  60:61:62:63 64:65:66:67 68:69:6A:6B 6C:6D:6E:6F  `abcdefghijklmno
  70:71:72:73 74:75:76:77 78:79:7A:7B 7C:7D:7E:7F  pqrstuvwxyz{|}~.
  80:81:82:83 84:85:86:87 88:89:8A:8B 8C:8D:8E:8F  ................
  90:91:92:93 94:95:96:97 98:99:9A:9B 9C:9D:9E:9F  ................
  A0:A1:A2:A3 A4:A5:A6:A7 A8:A9:AA:AB AC:AD:AE:AF  ................
  B0:B1:B2:B3 B4:B5:B6:B7 B8:B9:BA:BB BC:BD:BE:BF  ................
  C0:C1:C2:C3 C4:C5:C6:C7 C8:C9:CA:CB CC:CD:CE:CF  ................
  D0:D1:D2:D3 D4:D5:D6:D7 D8:D9:DA:DB DC:DD:DE:DF  ................
  E0:E1:E2:E3 E4:E5:E6:E7 E8:E9:EA:EB EC:ED:EE:EF  ................
  F0:F1:F2:F3 F4:F5:F6:F7 F8:F9:FA:FB FC:FD:FE:FF  ................
  regression_4003_XTS.38 FAILED
  regression_4003_XTS FAILED

it's 16 or 32 bytes at the end each time. With no better idea I'll try to study where the corruption occurs in the TA, assuming that's the source.

@MannyWang
Copy link

MannyWang commented Jan 24, 2017

BTW,

I have the same problem....

this is my code

char oms_rsa_keypair_id[] = "oms_rsa_keypair_object_id";
                                                                                                                                                                   
ret = TEE_AllocateTransientObject(TEE_TYPE_RSA_KEYPAIR, BYTES2BITS(SIZE_RSA_MODULO), &rsa_keypair);                                                                                                                      

ret = TEE_GenerateKey(rsa_keypair, BYTES2BITS(SIZE_RSA_MODULO), NULL, 0);                                                                                                                             

ret = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE,
                                            oms_rsa_keypair_id, sizeof(oms_rsa_keypair_id),
                                            0, rsa_keypair, 0, 0, &oms_RSA_keypair_object);

When run the "TEE_CreatePersistentObject", TA report the info blew.

[ta log] utee_storage_obj_create result : ffff0006 <---------------tee_api_objects.c
ERROR:   USER-TA: Panic 0x0[
ERROR:   TEE-CORE: TA panicked with code 0x0 usr_sp 0x40000fb0 usr_lr 0x0

It's work on op-tee v2.1.0, but v2.3.0 is not.

@lws-team
Copy link
Contributor Author

Wow... thanks for sharing... I was pretty sure this was going to be "just me".

Is this on Hikey? How are you booting the normal world?

@MannyWang
Copy link

Yes, it's Android 7.1.1 on Hikey board.

I execute "tee-supplicant" first, and execute my ca.

Finally, look the error message.

@lws-team
Copy link
Contributor Author

@MannyWang Have you tried xtest recently?

@MannyWang
Copy link

MannyWang commented Jan 24, 2017

yes, it's bad result.

22504 subtests of which 170 failed
70 test cases of which 30 failed

There are a lot of same panic error.

@lws-team
Copy link
Contributor Author

If I leave OP-TEE alone (don't give it my TA) and run xtest, I get the specific 3 errors on xtest I mentioned. If I run my TA (which runs OK), then xtest after blows many more problems. So it feels like something corrupted in OP-TEE side, but no evidence yet.

I thought it might be my boot procedure missed something, since I don't use UEFI any more. But if you also find similar problems using the original boot path, I will stop looking at my boot action and go back to looking at the exact corruption in xtest.

@lws-team
Copy link
Contributor Author

Just FYI my xtest repeatably ends like this (when I don't give it any TA before)... the details of the failing cases are listed above on this issue.

23572 subtests of which 3 failed
70 test cases of which 2 failed
0 test case was skipped
TEE test application done!

@MannyWang
Copy link

@lws-team thank you very much.

I will look for the same issues, and figure it out(if I can).

@lws-team
Copy link
Contributor Author

@MannyWang certainly feels better not just in the dark on my own ^^

My failing xtest elements are AES, specifically AES_CBC_NOPAD

... and the secure storage FEK stuff happens to use AES, specifically

core/tee/tee_fs_key_manager.c:  uint32_t algo = TEE_ALG_AES_CBC_NOPAD;

So maybe these issues are related by one issue in AES.

@lws-team
Copy link
Contributor Author

ええええええええ.... disabling the ARMv8 accelerated AES buys me this:

23572 subtests of which 0 failed
70 test cases of which 0 failed
0 test case was skipped
TEE test application done!

Please try this on optee_os

diff --git a/core/arch/arm/plat-hikey/conf.mk b/core/arch/arm/plat-hikey/conf.mk
index a4fde51..b7e8b89 100644
--- a/core/arch/arm/plat-hikey/conf.mk
+++ b/core/arch/arm/plat-hikey/conf.mk
@@ -10,6 +10,7 @@ $(call force,CFG_PL011,y)
 $(call force,CFG_PM_STUBS,y)
 $(call force,CFG_SECURE_TIME_SOURCE_CNTPCT,y)
 $(call force,CFG_WITH_ARM_TRUSTED_FW,y)
+$(call force,CFG_CRYPTO_AES_ARM64_CE,n)
 
 ta-targets = ta_arm32

You'll need to delete ./out or maybe make clean now and recook / reflash...

@lws-team
Copy link
Contributor Author

There are two separate issues here mixed together, at least for me.

  1. Ending up at PC=0x0 was my own fault.... putting logging before I initialized the emit function for the log (I stuck this at the top of my TA as a quick test). Making sure my log stuff is initialized first, I can call CreatePersistentObject OK. Whatever causes @MannyWang's similar symptom is unrelated.

  2. Accelerated AES has problems on my Hikey that show up with 3 specific failures on xtest... if I disable it like RPi 3 does and use the soft version I don't have problems with xtest.

@MannyWang
Copy link

@lws-team Thank you for sharing....but it is not work...T_________T

@lws-team
Copy link
Contributor Author

@MannyWang yeah... your problem is caused by something else. In my case I had a function pointer that defaulted to NULL, and I jumped to it. It was not directly caused by the call to CreatePersistentObject but my trying to show the result of the call.

I had lots of problems coming before when the different projects (optee_os, optee_client and optee_test) were not all at the same version.... you might want to confirm it and check that the binaries on the rootfs are updated.

Another time I had problems because the rootfs already had tee-supplicant and libteec.so.* in different paths, so I was not running what I thought I was.

@lws-team lws-team changed the title Secure Storage api blows chunks ARMv8 AES acceleration needs to be disabled on my Hikey (was Secure Stg blows chunks) Jan 24, 2017
@jforissier
Copy link
Contributor

@lws-team I can reproduce the AES issue with my setup. The culprit is b1ecda7 ("libutee: fix off-by-one error in tee_buffer_update()"). I don't know why yet.

jforissier added a commit to jforissier/optee_os that referenced this issue Jan 25, 2017
Ad-hoc fix for regressions introduced by [1].
Tested on HiKey using latest optee_test including GlobalPlatform tests
(32/64-bit TEE core, 32/64-bit libutee, with/without ARMv8 CE
acceleration).

Fixes: b1ecda7 ("libutee: fix off-by-one error in tee_buffer_update()") [1]
Fixes: OP-TEE#1305
Signed-off-by: Jerome Forissier <[email protected]>
@lws-team
Copy link
Contributor Author

This is solved by the workaround patch above, so closing.

jforissier added a commit to jforissier/optee_os that referenced this issue Jan 26, 2017
Ad-hoc fix for regressions introduced by [1].
Tested on HiKey using latest optee_test including GlobalPlatform tests
(32/64-bit TEE core, 32/64-bit libutee, with/without ARMv8 CE
acceleration).

Fixes: b1ecda7 ("libutee: fix off-by-one error in tee_buffer_update()") [1]
Fixes: OP-TEE#1305
Signed-off-by: Jerome Forissier <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
jforissier added a commit to jforissier/optee_os that referenced this issue Jan 26, 2017
Ad-hoc fix for regressions introduced by [1].
Tested on HiKey using latest optee_test including GlobalPlatform tests
(32/64-bit TEE core, 32/64-bit libutee, with/without ARMv8 CE
acceleration).

Fixes: b1ecda7 ("libutee: fix off-by-one error in tee_buffer_update()") [1]
Fixes: OP-TEE#1305
Signed-off-by: Jerome Forissier <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
takuya-sakata pushed a commit to renesas-rcar/optee_os that referenced this issue Dec 22, 2017
Ad-hoc fix for regressions introduced by [1].
Tested on HiKey using latest optee_test including GlobalPlatform tests
(32/64-bit TEE core, 32/64-bit libutee, with/without ARMv8 CE
acceleration).

Fixes: b1ecda7 ("libutee: fix off-by-one error in tee_buffer_update()") [1]
Fixes: OP-TEE/optee_os#1305
Signed-off-by: Jerome Forissier <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants