Commit 0f318cba authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-fixes-5.8-rc5' of...

Merge tag 'linux-kselftest-fixes-5.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest fixes from Shuah Khan:
 "TPM2 test changes to run on python3 and kselftest framework fix to
  incorrect return type"

* tag 'linux-kselftest-fixes-5.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  kselftest: ksft_test_num return type should be unsigned
  selftests: tpm: upgrade TPM2 tests from Python 2 to Python 3
parents a581387e 3c01655a
...@@ -36,7 +36,7 @@ struct ksft_count { ...@@ -36,7 +36,7 @@ struct ksft_count {
static struct ksft_count ksft_cnt; static struct ksft_count ksft_cnt;
static unsigned int ksft_plan; static unsigned int ksft_plan;
static inline int ksft_test_num(void) static inline unsigned int ksft_test_num(void)
{ {
return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail + return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail +
ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass + ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass +
......
...@@ -6,5 +6,5 @@ ksft_skip=4 ...@@ -6,5 +6,5 @@ ksft_skip=4
[ -e /dev/tpm0 ] || exit $ksft_skip [ -e /dev/tpm0 ] || exit $ksft_skip
python -m unittest -v tpm2_tests.SmokeTest python3 -m unittest -v tpm2_tests.SmokeTest
python -m unittest -v tpm2_tests.AsyncTest python3 -m unittest -v tpm2_tests.AsyncTest
...@@ -6,4 +6,4 @@ ksft_skip=4 ...@@ -6,4 +6,4 @@ ksft_skip=4
[ -e /dev/tpmrm0 ] || exit $ksft_skip [ -e /dev/tpmrm0 ] || exit $ksft_skip
python -m unittest -v tpm2_tests.SpaceTest python3 -m unittest -v tpm2_tests.SpaceTest
...@@ -247,14 +247,14 @@ class ProtocolError(Exception): ...@@ -247,14 +247,14 @@ class ProtocolError(Exception):
class AuthCommand(object): class AuthCommand(object):
"""TPMS_AUTH_COMMAND""" """TPMS_AUTH_COMMAND"""
def __init__(self, session_handle=TPM2_RS_PW, nonce='', session_attributes=0, def __init__(self, session_handle=TPM2_RS_PW, nonce=bytes(),
hmac=''): session_attributes=0, hmac=bytes()):
self.session_handle = session_handle self.session_handle = session_handle
self.nonce = nonce self.nonce = nonce
self.session_attributes = session_attributes self.session_attributes = session_attributes
self.hmac = hmac self.hmac = hmac
def __str__(self): def __bytes__(self):
fmt = '>I H%us B H%us' % (len(self.nonce), len(self.hmac)) fmt = '>I H%us B H%us' % (len(self.nonce), len(self.hmac))
return struct.pack(fmt, self.session_handle, len(self.nonce), return struct.pack(fmt, self.session_handle, len(self.nonce),
self.nonce, self.session_attributes, len(self.hmac), self.nonce, self.session_attributes, len(self.hmac),
...@@ -268,11 +268,11 @@ class AuthCommand(object): ...@@ -268,11 +268,11 @@ class AuthCommand(object):
class SensitiveCreate(object): class SensitiveCreate(object):
"""TPMS_SENSITIVE_CREATE""" """TPMS_SENSITIVE_CREATE"""
def __init__(self, user_auth='', data=''): def __init__(self, user_auth=bytes(), data=bytes()):
self.user_auth = user_auth self.user_auth = user_auth
self.data = data self.data = data
def __str__(self): def __bytes__(self):
fmt = '>H%us H%us' % (len(self.user_auth), len(self.data)) fmt = '>H%us H%us' % (len(self.user_auth), len(self.data))
return struct.pack(fmt, len(self.user_auth), self.user_auth, return struct.pack(fmt, len(self.user_auth), self.user_auth,
len(self.data), self.data) len(self.data), self.data)
...@@ -296,8 +296,9 @@ class Public(object): ...@@ -296,8 +296,9 @@ class Public(object):
return '>HHIH%us%usH%us' % \ return '>HHIH%us%usH%us' % \
(len(self.auth_policy), len(self.parameters), len(self.unique)) (len(self.auth_policy), len(self.parameters), len(self.unique))
def __init__(self, object_type, name_alg, object_attributes, auth_policy='', def __init__(self, object_type, name_alg, object_attributes,
parameters='', unique=''): auth_policy=bytes(), parameters=bytes(),
unique=bytes()):
self.object_type = object_type self.object_type = object_type
self.name_alg = name_alg self.name_alg = name_alg
self.object_attributes = object_attributes self.object_attributes = object_attributes
...@@ -305,7 +306,7 @@ class Public(object): ...@@ -305,7 +306,7 @@ class Public(object):
self.parameters = parameters self.parameters = parameters
self.unique = unique self.unique = unique
def __str__(self): def __bytes__(self):
return struct.pack(self.__fmt(), return struct.pack(self.__fmt(),
self.object_type, self.object_type,
self.name_alg, self.name_alg,
...@@ -343,7 +344,7 @@ def get_algorithm(name): ...@@ -343,7 +344,7 @@ def get_algorithm(name):
def hex_dump(d): def hex_dump(d):
d = [format(ord(x), '02x') for x in d] d = [format(ord(x), '02x') for x in d]
d = [d[i: i + 16] for i in xrange(0, len(d), 16)] d = [d[i: i + 16] for i in range(0, len(d), 16)]
d = [' '.join(x) for x in d] d = [' '.join(x) for x in d]
d = os.linesep.join(d) d = os.linesep.join(d)
...@@ -401,7 +402,7 @@ class Client: ...@@ -401,7 +402,7 @@ class Client:
pcrsel_len = max((i >> 3) + 1, 3) pcrsel_len = max((i >> 3) + 1, 3)
pcrsel = [0] * pcrsel_len pcrsel = [0] * pcrsel_len
pcrsel[i >> 3] = 1 << (i & 7) pcrsel[i >> 3] = 1 << (i & 7)
pcrsel = ''.join(map(chr, pcrsel)) pcrsel = ''.join(map(chr, pcrsel)).encode()
fmt = '>HII IHB%us' % (pcrsel_len) fmt = '>HII IHB%us' % (pcrsel_len)
cmd = struct.pack(fmt, cmd = struct.pack(fmt,
...@@ -443,7 +444,7 @@ class Client: ...@@ -443,7 +444,7 @@ class Client:
TPM2_CC_PCR_EXTEND, TPM2_CC_PCR_EXTEND,
i, i,
len(auth_cmd), len(auth_cmd),
str(auth_cmd), bytes(auth_cmd),
1, bank_alg, dig) 1, bank_alg, dig)
self.send_cmd(cmd) self.send_cmd(cmd)
...@@ -457,7 +458,7 @@ class Client: ...@@ -457,7 +458,7 @@ class Client:
TPM2_RH_NULL, TPM2_RH_NULL,
TPM2_RH_NULL, TPM2_RH_NULL,
16, 16,
'\0' * 16, ('\0' * 16).encode(),
0, 0,
session_type, session_type,
TPM2_ALG_NULL, TPM2_ALG_NULL,
...@@ -472,7 +473,7 @@ class Client: ...@@ -472,7 +473,7 @@ class Client:
for i in pcrs: for i in pcrs:
pcr = self.read_pcr(i, bank_alg) pcr = self.read_pcr(i, bank_alg)
if pcr == None: if pcr is None:
return None return None
x += pcr x += pcr
...@@ -489,7 +490,7 @@ class Client: ...@@ -489,7 +490,7 @@ class Client:
pcrsel = [0] * pcrsel_len pcrsel = [0] * pcrsel_len
for i in pcrs: for i in pcrs:
pcrsel[i >> 3] |= 1 << (i & 7) pcrsel[i >> 3] |= 1 << (i & 7)
pcrsel = ''.join(map(chr, pcrsel)) pcrsel = ''.join(map(chr, pcrsel)).encode()
fmt = '>HII IH%usIHB3s' % ds fmt = '>HII IH%usIHB3s' % ds
cmd = struct.pack(fmt, cmd = struct.pack(fmt,
...@@ -497,7 +498,8 @@ class Client: ...@@ -497,7 +498,8 @@ class Client:
struct.calcsize(fmt), struct.calcsize(fmt),
TPM2_CC_POLICY_PCR, TPM2_CC_POLICY_PCR,
handle, handle,
len(dig), str(dig), len(dig),
bytes(dig),
1, 1,
bank_alg, bank_alg,
pcrsel_len, pcrsel) pcrsel_len, pcrsel)
...@@ -534,7 +536,7 @@ class Client: ...@@ -534,7 +536,7 @@ class Client:
self.send_cmd(cmd) self.send_cmd(cmd)
def create_root_key(self, auth_value = ''): def create_root_key(self, auth_value = bytes()):
attributes = \ attributes = \
Public.FIXED_TPM | \ Public.FIXED_TPM | \
Public.FIXED_PARENT | \ Public.FIXED_PARENT | \
...@@ -570,11 +572,11 @@ class Client: ...@@ -570,11 +572,11 @@ class Client:
TPM2_CC_CREATE_PRIMARY, TPM2_CC_CREATE_PRIMARY,
TPM2_RH_OWNER, TPM2_RH_OWNER,
len(auth_cmd), len(auth_cmd),
str(auth_cmd), bytes(auth_cmd),
len(sensitive), len(sensitive),
str(sensitive), bytes(sensitive),
len(public), len(public),
str(public), bytes(public),
0, 0) 0, 0)
return struct.unpack('>I', self.send_cmd(cmd)[10:14])[0] return struct.unpack('>I', self.send_cmd(cmd)[10:14])[0]
...@@ -587,7 +589,7 @@ class Client: ...@@ -587,7 +589,7 @@ class Client:
attributes = 0 attributes = 0
if not policy_dig: if not policy_dig:
attributes |= Public.USER_WITH_AUTH attributes |= Public.USER_WITH_AUTH
policy_dig = '' policy_dig = bytes()
auth_cmd = AuthCommand() auth_cmd = AuthCommand()
sensitive = SensitiveCreate(user_auth=auth_value, data=data) sensitive = SensitiveCreate(user_auth=auth_value, data=data)
...@@ -608,11 +610,11 @@ class Client: ...@@ -608,11 +610,11 @@ class Client:
TPM2_CC_CREATE, TPM2_CC_CREATE,
parent_key, parent_key,
len(auth_cmd), len(auth_cmd),
str(auth_cmd), bytes(auth_cmd),
len(sensitive), len(sensitive),
str(sensitive), bytes(sensitive),
len(public), len(public),
str(public), bytes(public),
0, 0) 0, 0)
rsp = self.send_cmd(cmd) rsp = self.send_cmd(cmd)
...@@ -635,7 +637,7 @@ class Client: ...@@ -635,7 +637,7 @@ class Client:
TPM2_CC_LOAD, TPM2_CC_LOAD,
parent_key, parent_key,
len(auth_cmd), len(auth_cmd),
str(auth_cmd), bytes(auth_cmd),
blob) blob)
data_handle = struct.unpack('>I', self.send_cmd(cmd)[10:14])[0] data_handle = struct.unpack('>I', self.send_cmd(cmd)[10:14])[0]
...@@ -653,7 +655,7 @@ class Client: ...@@ -653,7 +655,7 @@ class Client:
TPM2_CC_UNSEAL, TPM2_CC_UNSEAL,
data_handle, data_handle,
len(auth_cmd), len(auth_cmd),
str(auth_cmd)) bytes(auth_cmd))
try: try:
rsp = self.send_cmd(cmd) rsp = self.send_cmd(cmd)
...@@ -675,7 +677,7 @@ class Client: ...@@ -675,7 +677,7 @@ class Client:
TPM2_CC_DICTIONARY_ATTACK_LOCK_RESET, TPM2_CC_DICTIONARY_ATTACK_LOCK_RESET,
TPM2_RH_LOCKOUT, TPM2_RH_LOCKOUT,
len(auth_cmd), len(auth_cmd),
str(auth_cmd)) bytes(auth_cmd))
self.send_cmd(cmd) self.send_cmd(cmd)
...@@ -693,7 +695,7 @@ class Client: ...@@ -693,7 +695,7 @@ class Client:
more_data, cap, cnt = struct.unpack('>BII', rsp[:9]) more_data, cap, cnt = struct.unpack('>BII', rsp[:9])
rsp = rsp[9:] rsp = rsp[9:]
for i in xrange(0, cnt): for i in range(0, cnt):
handle = struct.unpack('>I', rsp[:4])[0] handle = struct.unpack('>I', rsp[:4])[0]
handles.append(handle) handles.append(handle)
rsp = rsp[4:] rsp = rsp[4:]
......
...@@ -20,8 +20,8 @@ class SmokeTest(unittest.TestCase): ...@@ -20,8 +20,8 @@ class SmokeTest(unittest.TestCase):
self.client.close() self.client.close()
def test_seal_with_auth(self): def test_seal_with_auth(self):
data = 'X' * 64 data = ('X' * 64).encode()
auth = 'A' * 15 auth = ('A' * 15).encode()
blob = self.client.seal(self.root_key, data, auth, None) blob = self.client.seal(self.root_key, data, auth, None)
result = self.client.unseal(self.root_key, blob, auth, None) result = self.client.unseal(self.root_key, blob, auth, None)
...@@ -30,8 +30,8 @@ class SmokeTest(unittest.TestCase): ...@@ -30,8 +30,8 @@ class SmokeTest(unittest.TestCase):
def test_seal_with_policy(self): def test_seal_with_policy(self):
handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL) handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL)
data = 'X' * 64 data = ('X' * 64).encode()
auth = 'A' * 15 auth = ('A' * 15).encode()
pcrs = [16] pcrs = [16]
try: try:
...@@ -58,14 +58,15 @@ class SmokeTest(unittest.TestCase): ...@@ -58,14 +58,15 @@ class SmokeTest(unittest.TestCase):
self.assertEqual(data, result) self.assertEqual(data, result)
def test_unseal_with_wrong_auth(self): def test_unseal_with_wrong_auth(self):
data = 'X' * 64 data = ('X' * 64).encode()
auth = 'A' * 20 auth = ('A' * 20).encode()
rc = 0 rc = 0
blob = self.client.seal(self.root_key, data, auth, None) blob = self.client.seal(self.root_key, data, auth, None)
try: try:
result = self.client.unseal(self.root_key, blob, auth[:-1] + 'B', None) result = self.client.unseal(self.root_key, blob,
except ProtocolError, e: auth[:-1] + 'B'.encode(), None)
except ProtocolError as e:
rc = e.rc rc = e.rc
self.assertEqual(rc, tpm2.TPM2_RC_AUTH_FAIL) self.assertEqual(rc, tpm2.TPM2_RC_AUTH_FAIL)
...@@ -73,8 +74,8 @@ class SmokeTest(unittest.TestCase): ...@@ -73,8 +74,8 @@ class SmokeTest(unittest.TestCase):
def test_unseal_with_wrong_policy(self): def test_unseal_with_wrong_policy(self):
handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL) handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL)
data = 'X' * 64 data = ('X' * 64).encode()
auth = 'A' * 17 auth = ('A' * 17).encode()
pcrs = [16] pcrs = [16]
try: try:
...@@ -91,7 +92,7 @@ class SmokeTest(unittest.TestCase): ...@@ -91,7 +92,7 @@ class SmokeTest(unittest.TestCase):
# This should succeed. # This should succeed.
ds = tpm2.get_digest_size(tpm2.TPM2_ALG_SHA1) ds = tpm2.get_digest_size(tpm2.TPM2_ALG_SHA1)
self.client.extend_pcr(1, 'X' * ds) self.client.extend_pcr(1, ('X' * ds).encode())
handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY) handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY)
...@@ -108,7 +109,7 @@ class SmokeTest(unittest.TestCase): ...@@ -108,7 +109,7 @@ class SmokeTest(unittest.TestCase):
# Then, extend a PCR that is part of the policy and try to unseal. # Then, extend a PCR that is part of the policy and try to unseal.
# This should fail. # This should fail.
self.client.extend_pcr(16, 'X' * ds) self.client.extend_pcr(16, ('X' * ds).encode())
handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY) handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY)
...@@ -119,7 +120,7 @@ class SmokeTest(unittest.TestCase): ...@@ -119,7 +120,7 @@ class SmokeTest(unittest.TestCase):
self.client.policy_password(handle) self.client.policy_password(handle)
result = self.client.unseal(self.root_key, blob, auth, handle) result = self.client.unseal(self.root_key, blob, auth, handle)
except ProtocolError, e: except ProtocolError as e:
rc = e.rc rc = e.rc
self.client.flush_context(handle) self.client.flush_context(handle)
except: except:
...@@ -130,13 +131,13 @@ class SmokeTest(unittest.TestCase): ...@@ -130,13 +131,13 @@ class SmokeTest(unittest.TestCase):
def test_seal_with_too_long_auth(self): def test_seal_with_too_long_auth(self):
ds = tpm2.get_digest_size(tpm2.TPM2_ALG_SHA1) ds = tpm2.get_digest_size(tpm2.TPM2_ALG_SHA1)
data = 'X' * 64 data = ('X' * 64).encode()
auth = 'A' * (ds + 1) auth = ('A' * (ds + 1)).encode()
rc = 0 rc = 0
try: try:
blob = self.client.seal(self.root_key, data, auth, None) blob = self.client.seal(self.root_key, data, auth, None)
except ProtocolError, e: except ProtocolError as e:
rc = e.rc rc = e.rc
self.assertEqual(rc, tpm2.TPM2_RC_SIZE) self.assertEqual(rc, tpm2.TPM2_RC_SIZE)
...@@ -152,7 +153,7 @@ class SmokeTest(unittest.TestCase): ...@@ -152,7 +153,7 @@ class SmokeTest(unittest.TestCase):
0xDEADBEEF) 0xDEADBEEF)
self.client.send_cmd(cmd) self.client.send_cmd(cmd)
except IOError, e: except IOError as e:
rejected = True rejected = True
except: except:
pass pass
...@@ -212,7 +213,7 @@ class SmokeTest(unittest.TestCase): ...@@ -212,7 +213,7 @@ class SmokeTest(unittest.TestCase):
self.client.tpm.write(cmd) self.client.tpm.write(cmd)
rsp = self.client.tpm.read() rsp = self.client.tpm.read()
except IOError, e: except IOError as e:
# read the response # read the response
rsp = self.client.tpm.read() rsp = self.client.tpm.read()
rejected = True rejected = True
...@@ -283,7 +284,7 @@ class SpaceTest(unittest.TestCase): ...@@ -283,7 +284,7 @@ class SpaceTest(unittest.TestCase):
rc = 0 rc = 0
try: try:
space1.send_cmd(cmd) space1.send_cmd(cmd)
except ProtocolError, e: except ProtocolError as e:
rc = e.rc rc = e.rc
self.assertEqual(rc, tpm2.TPM2_RC_COMMAND_CODE | self.assertEqual(rc, tpm2.TPM2_RC_COMMAND_CODE |
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment