trusted.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. /*
  2. * Copyright (C) 2010 IBM Corporation
  3. *
  4. * Author:
  5. * David Safford <safford@us.ibm.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, version 2 of the License.
  10. *
  11. * See Documentation/security/keys-trusted-encrypted.txt
  12. */
  13. #include <crypto/hash_info.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/slab.h>
  18. #include <linux/parser.h>
  19. #include <linux/string.h>
  20. #include <linux/err.h>
  21. #include <keys/user-type.h>
  22. #include <keys/trusted-type.h>
  23. #include <linux/key-type.h>
  24. #include <linux/rcupdate.h>
  25. #include <linux/crypto.h>
  26. #include <crypto/hash.h>
  27. #include <crypto/sha.h>
  28. #include <linux/capability.h>
  29. #include <linux/tpm.h>
  30. #include <linux/tpm_command.h>
  31. #include "trusted.h"
  32. static const char hmac_alg[] = "hmac(sha1)";
  33. static const char hash_alg[] = "sha1";
  34. struct sdesc {
  35. struct shash_desc shash;
  36. char ctx[];
  37. };
  38. static struct crypto_shash *hashalg;
  39. static struct crypto_shash *hmacalg;
  40. static struct sdesc *init_sdesc(struct crypto_shash *alg)
  41. {
  42. struct sdesc *sdesc;
  43. int size;
  44. size = sizeof(struct shash_desc) + crypto_shash_descsize(alg);
  45. sdesc = kmalloc(size, GFP_KERNEL);
  46. if (!sdesc)
  47. return ERR_PTR(-ENOMEM);
  48. sdesc->shash.tfm = alg;
  49. sdesc->shash.flags = 0x0;
  50. return sdesc;
  51. }
  52. static int TSS_sha1(const unsigned char *data, unsigned int datalen,
  53. unsigned char *digest)
  54. {
  55. struct sdesc *sdesc;
  56. int ret;
  57. sdesc = init_sdesc(hashalg);
  58. if (IS_ERR(sdesc)) {
  59. pr_info("trusted_key: can't alloc %s\n", hash_alg);
  60. return PTR_ERR(sdesc);
  61. }
  62. ret = crypto_shash_digest(&sdesc->shash, data, datalen, digest);
  63. kzfree(sdesc);
  64. return ret;
  65. }
  66. static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
  67. unsigned int keylen, ...)
  68. {
  69. struct sdesc *sdesc;
  70. va_list argp;
  71. unsigned int dlen;
  72. unsigned char *data;
  73. int ret;
  74. sdesc = init_sdesc(hmacalg);
  75. if (IS_ERR(sdesc)) {
  76. pr_info("trusted_key: can't alloc %s\n", hmac_alg);
  77. return PTR_ERR(sdesc);
  78. }
  79. ret = crypto_shash_setkey(hmacalg, key, keylen);
  80. if (ret < 0)
  81. goto out;
  82. ret = crypto_shash_init(&sdesc->shash);
  83. if (ret < 0)
  84. goto out;
  85. va_start(argp, keylen);
  86. for (;;) {
  87. dlen = va_arg(argp, unsigned int);
  88. if (dlen == 0)
  89. break;
  90. data = va_arg(argp, unsigned char *);
  91. if (data == NULL) {
  92. ret = -EINVAL;
  93. break;
  94. }
  95. ret = crypto_shash_update(&sdesc->shash, data, dlen);
  96. if (ret < 0)
  97. break;
  98. }
  99. va_end(argp);
  100. if (!ret)
  101. ret = crypto_shash_final(&sdesc->shash, digest);
  102. out:
  103. kzfree(sdesc);
  104. return ret;
  105. }
  106. /*
  107. * calculate authorization info fields to send to TPM
  108. */
  109. static int TSS_authhmac(unsigned char *digest, const unsigned char *key,
  110. unsigned int keylen, unsigned char *h1,
  111. unsigned char *h2, unsigned char h3, ...)
  112. {
  113. unsigned char paramdigest[SHA1_DIGEST_SIZE];
  114. struct sdesc *sdesc;
  115. unsigned int dlen;
  116. unsigned char *data;
  117. unsigned char c;
  118. int ret;
  119. va_list argp;
  120. sdesc = init_sdesc(hashalg);
  121. if (IS_ERR(sdesc)) {
  122. pr_info("trusted_key: can't alloc %s\n", hash_alg);
  123. return PTR_ERR(sdesc);
  124. }
  125. c = h3;
  126. ret = crypto_shash_init(&sdesc->shash);
  127. if (ret < 0)
  128. goto out;
  129. va_start(argp, h3);
  130. for (;;) {
  131. dlen = va_arg(argp, unsigned int);
  132. if (dlen == 0)
  133. break;
  134. data = va_arg(argp, unsigned char *);
  135. if (!data) {
  136. ret = -EINVAL;
  137. break;
  138. }
  139. ret = crypto_shash_update(&sdesc->shash, data, dlen);
  140. if (ret < 0)
  141. break;
  142. }
  143. va_end(argp);
  144. if (!ret)
  145. ret = crypto_shash_final(&sdesc->shash, paramdigest);
  146. if (!ret)
  147. ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE,
  148. paramdigest, TPM_NONCE_SIZE, h1,
  149. TPM_NONCE_SIZE, h2, 1, &c, 0, 0);
  150. out:
  151. kzfree(sdesc);
  152. return ret;
  153. }
  154. /*
  155. * verify the AUTH1_COMMAND (Seal) result from TPM
  156. */
  157. static int TSS_checkhmac1(unsigned char *buffer,
  158. const uint32_t command,
  159. const unsigned char *ononce,
  160. const unsigned char *key,
  161. unsigned int keylen, ...)
  162. {
  163. uint32_t bufsize;
  164. uint16_t tag;
  165. uint32_t ordinal;
  166. uint32_t result;
  167. unsigned char *enonce;
  168. unsigned char *continueflag;
  169. unsigned char *authdata;
  170. unsigned char testhmac[SHA1_DIGEST_SIZE];
  171. unsigned char paramdigest[SHA1_DIGEST_SIZE];
  172. struct sdesc *sdesc;
  173. unsigned int dlen;
  174. unsigned int dpos;
  175. va_list argp;
  176. int ret;
  177. bufsize = LOAD32(buffer, TPM_SIZE_OFFSET);
  178. tag = LOAD16(buffer, 0);
  179. ordinal = command;
  180. result = LOAD32N(buffer, TPM_RETURN_OFFSET);
  181. if (tag == TPM_TAG_RSP_COMMAND)
  182. return 0;
  183. if (tag != TPM_TAG_RSP_AUTH1_COMMAND)
  184. return -EINVAL;
  185. authdata = buffer + bufsize - SHA1_DIGEST_SIZE;
  186. continueflag = authdata - 1;
  187. enonce = continueflag - TPM_NONCE_SIZE;
  188. sdesc = init_sdesc(hashalg);
  189. if (IS_ERR(sdesc)) {
  190. pr_info("trusted_key: can't alloc %s\n", hash_alg);
  191. return PTR_ERR(sdesc);
  192. }
  193. ret = crypto_shash_init(&sdesc->shash);
  194. if (ret < 0)
  195. goto out;
  196. ret = crypto_shash_update(&sdesc->shash, (const u8 *)&result,
  197. sizeof result);
  198. if (ret < 0)
  199. goto out;
  200. ret = crypto_shash_update(&sdesc->shash, (const u8 *)&ordinal,
  201. sizeof ordinal);
  202. if (ret < 0)
  203. goto out;
  204. va_start(argp, keylen);
  205. for (;;) {
  206. dlen = va_arg(argp, unsigned int);
  207. if (dlen == 0)
  208. break;
  209. dpos = va_arg(argp, unsigned int);
  210. ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen);
  211. if (ret < 0)
  212. break;
  213. }
  214. va_end(argp);
  215. if (!ret)
  216. ret = crypto_shash_final(&sdesc->shash, paramdigest);
  217. if (ret < 0)
  218. goto out;
  219. ret = TSS_rawhmac(testhmac, key, keylen, SHA1_DIGEST_SIZE, paramdigest,
  220. TPM_NONCE_SIZE, enonce, TPM_NONCE_SIZE, ononce,
  221. 1, continueflag, 0, 0);
  222. if (ret < 0)
  223. goto out;
  224. if (memcmp(testhmac, authdata, SHA1_DIGEST_SIZE))
  225. ret = -EINVAL;
  226. out:
  227. kzfree(sdesc);
  228. return ret;
  229. }
  230. /*
  231. * verify the AUTH2_COMMAND (unseal) result from TPM
  232. */
  233. static int TSS_checkhmac2(unsigned char *buffer,
  234. const uint32_t command,
  235. const unsigned char *ononce,
  236. const unsigned char *key1,
  237. unsigned int keylen1,
  238. const unsigned char *key2,
  239. unsigned int keylen2, ...)
  240. {
  241. uint32_t bufsize;
  242. uint16_t tag;
  243. uint32_t ordinal;
  244. uint32_t result;
  245. unsigned char *enonce1;
  246. unsigned char *continueflag1;
  247. unsigned char *authdata1;
  248. unsigned char *enonce2;
  249. unsigned char *continueflag2;
  250. unsigned char *authdata2;
  251. unsigned char testhmac1[SHA1_DIGEST_SIZE];
  252. unsigned char testhmac2[SHA1_DIGEST_SIZE];
  253. unsigned char paramdigest[SHA1_DIGEST_SIZE];
  254. struct sdesc *sdesc;
  255. unsigned int dlen;
  256. unsigned int dpos;
  257. va_list argp;
  258. int ret;
  259. bufsize = LOAD32(buffer, TPM_SIZE_OFFSET);
  260. tag = LOAD16(buffer, 0);
  261. ordinal = command;
  262. result = LOAD32N(buffer, TPM_RETURN_OFFSET);
  263. if (tag == TPM_TAG_RSP_COMMAND)
  264. return 0;
  265. if (tag != TPM_TAG_RSP_AUTH2_COMMAND)
  266. return -EINVAL;
  267. authdata1 = buffer + bufsize - (SHA1_DIGEST_SIZE + 1
  268. + SHA1_DIGEST_SIZE + SHA1_DIGEST_SIZE);
  269. authdata2 = buffer + bufsize - (SHA1_DIGEST_SIZE);
  270. continueflag1 = authdata1 - 1;
  271. continueflag2 = authdata2 - 1;
  272. enonce1 = continueflag1 - TPM_NONCE_SIZE;
  273. enonce2 = continueflag2 - TPM_NONCE_SIZE;
  274. sdesc = init_sdesc(hashalg);
  275. if (IS_ERR(sdesc)) {
  276. pr_info("trusted_key: can't alloc %s\n", hash_alg);
  277. return PTR_ERR(sdesc);
  278. }
  279. ret = crypto_shash_init(&sdesc->shash);
  280. if (ret < 0)
  281. goto out;
  282. ret = crypto_shash_update(&sdesc->shash, (const u8 *)&result,
  283. sizeof result);
  284. if (ret < 0)
  285. goto out;
  286. ret = crypto_shash_update(&sdesc->shash, (const u8 *)&ordinal,
  287. sizeof ordinal);
  288. if (ret < 0)
  289. goto out;
  290. va_start(argp, keylen2);
  291. for (;;) {
  292. dlen = va_arg(argp, unsigned int);
  293. if (dlen == 0)
  294. break;
  295. dpos = va_arg(argp, unsigned int);
  296. ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen);
  297. if (ret < 0)
  298. break;
  299. }
  300. va_end(argp);
  301. if (!ret)
  302. ret = crypto_shash_final(&sdesc->shash, paramdigest);
  303. if (ret < 0)
  304. goto out;
  305. ret = TSS_rawhmac(testhmac1, key1, keylen1, SHA1_DIGEST_SIZE,
  306. paramdigest, TPM_NONCE_SIZE, enonce1,
  307. TPM_NONCE_SIZE, ononce, 1, continueflag1, 0, 0);
  308. if (ret < 0)
  309. goto out;
  310. if (memcmp(testhmac1, authdata1, SHA1_DIGEST_SIZE)) {
  311. ret = -EINVAL;
  312. goto out;
  313. }
  314. ret = TSS_rawhmac(testhmac2, key2, keylen2, SHA1_DIGEST_SIZE,
  315. paramdigest, TPM_NONCE_SIZE, enonce2,
  316. TPM_NONCE_SIZE, ononce, 1, continueflag2, 0, 0);
  317. if (ret < 0)
  318. goto out;
  319. if (memcmp(testhmac2, authdata2, SHA1_DIGEST_SIZE))
  320. ret = -EINVAL;
  321. out:
  322. kzfree(sdesc);
  323. return ret;
  324. }
  325. /*
  326. * For key specific tpm requests, we will generate and send our
  327. * own TPM command packets using the drivers send function.
  328. */
  329. static int trusted_tpm_send(const u32 chip_num, unsigned char *cmd,
  330. size_t buflen)
  331. {
  332. int rc;
  333. dump_tpm_buf(cmd);
  334. rc = tpm_send(chip_num, cmd, buflen);
  335. dump_tpm_buf(cmd);
  336. if (rc > 0)
  337. /* Can't return positive return codes values to keyctl */
  338. rc = -EPERM;
  339. return rc;
  340. }
  341. /*
  342. * Lock a trusted key, by extending a selected PCR.
  343. *
  344. * Prevents a trusted key that is sealed to PCRs from being accessed.
  345. * This uses the tpm driver's extend function.
  346. */
  347. static int pcrlock(const int pcrnum)
  348. {
  349. unsigned char hash[SHA1_DIGEST_SIZE];
  350. int ret;
  351. if (!capable(CAP_SYS_ADMIN))
  352. return -EPERM;
  353. ret = tpm_get_random(TPM_ANY_NUM, hash, SHA1_DIGEST_SIZE);
  354. if (ret != SHA1_DIGEST_SIZE)
  355. return ret;
  356. return tpm_pcr_extend(TPM_ANY_NUM, pcrnum, hash) ? -EINVAL : 0;
  357. }
  358. /*
  359. * Create an object specific authorisation protocol (OSAP) session
  360. */
  361. static int osap(struct tpm_buf *tb, struct osapsess *s,
  362. const unsigned char *key, uint16_t type, uint32_t handle)
  363. {
  364. unsigned char enonce[TPM_NONCE_SIZE];
  365. unsigned char ononce[TPM_NONCE_SIZE];
  366. int ret;
  367. ret = tpm_get_random(TPM_ANY_NUM, ononce, TPM_NONCE_SIZE);
  368. if (ret != TPM_NONCE_SIZE)
  369. return ret;
  370. INIT_BUF(tb);
  371. store16(tb, TPM_TAG_RQU_COMMAND);
  372. store32(tb, TPM_OSAP_SIZE);
  373. store32(tb, TPM_ORD_OSAP);
  374. store16(tb, type);
  375. store32(tb, handle);
  376. storebytes(tb, ononce, TPM_NONCE_SIZE);
  377. ret = trusted_tpm_send(TPM_ANY_NUM, tb->data, MAX_BUF_SIZE);
  378. if (ret < 0)
  379. return ret;
  380. s->handle = LOAD32(tb->data, TPM_DATA_OFFSET);
  381. memcpy(s->enonce, &(tb->data[TPM_DATA_OFFSET + sizeof(uint32_t)]),
  382. TPM_NONCE_SIZE);
  383. memcpy(enonce, &(tb->data[TPM_DATA_OFFSET + sizeof(uint32_t) +
  384. TPM_NONCE_SIZE]), TPM_NONCE_SIZE);
  385. return TSS_rawhmac(s->secret, key, SHA1_DIGEST_SIZE, TPM_NONCE_SIZE,
  386. enonce, TPM_NONCE_SIZE, ononce, 0, 0);
  387. }
  388. /*
  389. * Create an object independent authorisation protocol (oiap) session
  390. */
  391. static int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce)
  392. {
  393. int ret;
  394. INIT_BUF(tb);
  395. store16(tb, TPM_TAG_RQU_COMMAND);
  396. store32(tb, TPM_OIAP_SIZE);
  397. store32(tb, TPM_ORD_OIAP);
  398. ret = trusted_tpm_send(TPM_ANY_NUM, tb->data, MAX_BUF_SIZE);
  399. if (ret < 0)
  400. return ret;
  401. *handle = LOAD32(tb->data, TPM_DATA_OFFSET);
  402. memcpy(nonce, &tb->data[TPM_DATA_OFFSET + sizeof(uint32_t)],
  403. TPM_NONCE_SIZE);
  404. return 0;
  405. }
  406. struct tpm_digests {
  407. unsigned char encauth[SHA1_DIGEST_SIZE];
  408. unsigned char pubauth[SHA1_DIGEST_SIZE];
  409. unsigned char xorwork[SHA1_DIGEST_SIZE * 2];
  410. unsigned char xorhash[SHA1_DIGEST_SIZE];
  411. unsigned char nonceodd[TPM_NONCE_SIZE];
  412. };
  413. /*
  414. * Have the TPM seal(encrypt) the trusted key, possibly based on
  415. * Platform Configuration Registers (PCRs). AUTH1 for sealing key.
  416. */
  417. static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
  418. uint32_t keyhandle, const unsigned char *keyauth,
  419. const unsigned char *data, uint32_t datalen,
  420. unsigned char *blob, uint32_t *bloblen,
  421. const unsigned char *blobauth,
  422. const unsigned char *pcrinfo, uint32_t pcrinfosize)
  423. {
  424. struct osapsess sess;
  425. struct tpm_digests *td;
  426. unsigned char cont;
  427. uint32_t ordinal;
  428. uint32_t pcrsize;
  429. uint32_t datsize;
  430. int sealinfosize;
  431. int encdatasize;
  432. int storedsize;
  433. int ret;
  434. int i;
  435. /* alloc some work space for all the hashes */
  436. td = kmalloc(sizeof *td, GFP_KERNEL);
  437. if (!td)
  438. return -ENOMEM;
  439. /* get session for sealing key */
  440. ret = osap(tb, &sess, keyauth, keytype, keyhandle);
  441. if (ret < 0)
  442. goto out;
  443. dump_sess(&sess);
  444. /* calculate encrypted authorization value */
  445. memcpy(td->xorwork, sess.secret, SHA1_DIGEST_SIZE);
  446. memcpy(td->xorwork + SHA1_DIGEST_SIZE, sess.enonce, SHA1_DIGEST_SIZE);
  447. ret = TSS_sha1(td->xorwork, SHA1_DIGEST_SIZE * 2, td->xorhash);
  448. if (ret < 0)
  449. goto out;
  450. ret = tpm_get_random(TPM_ANY_NUM, td->nonceodd, TPM_NONCE_SIZE);
  451. if (ret != TPM_NONCE_SIZE)
  452. goto out;
  453. ordinal = htonl(TPM_ORD_SEAL);
  454. datsize = htonl(datalen);
  455. pcrsize = htonl(pcrinfosize);
  456. cont = 0;
  457. /* encrypt data authorization key */
  458. for (i = 0; i < SHA1_DIGEST_SIZE; ++i)
  459. td->encauth[i] = td->xorhash[i] ^ blobauth[i];
  460. /* calculate authorization HMAC value */
  461. if (pcrinfosize == 0) {
  462. /* no pcr info specified */
  463. ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE,
  464. sess.enonce, td->nonceodd, cont,
  465. sizeof(uint32_t), &ordinal, SHA1_DIGEST_SIZE,
  466. td->encauth, sizeof(uint32_t), &pcrsize,
  467. sizeof(uint32_t), &datsize, datalen, data, 0,
  468. 0);
  469. } else {
  470. /* pcr info specified */
  471. ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE,
  472. sess.enonce, td->nonceodd, cont,
  473. sizeof(uint32_t), &ordinal, SHA1_DIGEST_SIZE,
  474. td->encauth, sizeof(uint32_t), &pcrsize,
  475. pcrinfosize, pcrinfo, sizeof(uint32_t),
  476. &datsize, datalen, data, 0, 0);
  477. }
  478. if (ret < 0)
  479. goto out;
  480. /* build and send the TPM request packet */
  481. INIT_BUF(tb);
  482. store16(tb, TPM_TAG_RQU_AUTH1_COMMAND);
  483. store32(tb, TPM_SEAL_SIZE + pcrinfosize + datalen);
  484. store32(tb, TPM_ORD_SEAL);
  485. store32(tb, keyhandle);
  486. storebytes(tb, td->encauth, SHA1_DIGEST_SIZE);
  487. store32(tb, pcrinfosize);
  488. storebytes(tb, pcrinfo, pcrinfosize);
  489. store32(tb, datalen);
  490. storebytes(tb, data, datalen);
  491. store32(tb, sess.handle);
  492. storebytes(tb, td->nonceodd, TPM_NONCE_SIZE);
  493. store8(tb, cont);
  494. storebytes(tb, td->pubauth, SHA1_DIGEST_SIZE);
  495. ret = trusted_tpm_send(TPM_ANY_NUM, tb->data, MAX_BUF_SIZE);
  496. if (ret < 0)
  497. goto out;
  498. /* calculate the size of the returned Blob */
  499. sealinfosize = LOAD32(tb->data, TPM_DATA_OFFSET + sizeof(uint32_t));
  500. encdatasize = LOAD32(tb->data, TPM_DATA_OFFSET + sizeof(uint32_t) +
  501. sizeof(uint32_t) + sealinfosize);
  502. storedsize = sizeof(uint32_t) + sizeof(uint32_t) + sealinfosize +
  503. sizeof(uint32_t) + encdatasize;
  504. /* check the HMAC in the response */
  505. ret = TSS_checkhmac1(tb->data, ordinal, td->nonceodd, sess.secret,
  506. SHA1_DIGEST_SIZE, storedsize, TPM_DATA_OFFSET, 0,
  507. 0);
  508. /* copy the returned blob to caller */
  509. if (!ret) {
  510. memcpy(blob, tb->data + TPM_DATA_OFFSET, storedsize);
  511. *bloblen = storedsize;
  512. }
  513. out:
  514. kzfree(td);
  515. return ret;
  516. }
  517. /*
  518. * use the AUTH2_COMMAND form of unseal, to authorize both key and blob
  519. */
  520. static int tpm_unseal(struct tpm_buf *tb,
  521. uint32_t keyhandle, const unsigned char *keyauth,
  522. const unsigned char *blob, int bloblen,
  523. const unsigned char *blobauth,
  524. unsigned char *data, unsigned int *datalen)
  525. {
  526. unsigned char nonceodd[TPM_NONCE_SIZE];
  527. unsigned char enonce1[TPM_NONCE_SIZE];
  528. unsigned char enonce2[TPM_NONCE_SIZE];
  529. unsigned char authdata1[SHA1_DIGEST_SIZE];
  530. unsigned char authdata2[SHA1_DIGEST_SIZE];
  531. uint32_t authhandle1 = 0;
  532. uint32_t authhandle2 = 0;
  533. unsigned char cont = 0;
  534. uint32_t ordinal;
  535. uint32_t keyhndl;
  536. int ret;
  537. /* sessions for unsealing key and data */
  538. ret = oiap(tb, &authhandle1, enonce1);
  539. if (ret < 0) {
  540. pr_info("trusted_key: oiap failed (%d)\n", ret);
  541. return ret;
  542. }
  543. ret = oiap(tb, &authhandle2, enonce2);
  544. if (ret < 0) {
  545. pr_info("trusted_key: oiap failed (%d)\n", ret);
  546. return ret;
  547. }
  548. ordinal = htonl(TPM_ORD_UNSEAL);
  549. keyhndl = htonl(SRKHANDLE);
  550. ret = tpm_get_random(TPM_ANY_NUM, nonceodd, TPM_NONCE_SIZE);
  551. if (ret != TPM_NONCE_SIZE) {
  552. pr_info("trusted_key: tpm_get_random failed (%d)\n", ret);
  553. return ret;
  554. }
  555. ret = TSS_authhmac(authdata1, keyauth, TPM_NONCE_SIZE,
  556. enonce1, nonceodd, cont, sizeof(uint32_t),
  557. &ordinal, bloblen, blob, 0, 0);
  558. if (ret < 0)
  559. return ret;
  560. ret = TSS_authhmac(authdata2, blobauth, TPM_NONCE_SIZE,
  561. enonce2, nonceodd, cont, sizeof(uint32_t),
  562. &ordinal, bloblen, blob, 0, 0);
  563. if (ret < 0)
  564. return ret;
  565. /* build and send TPM request packet */
  566. INIT_BUF(tb);
  567. store16(tb, TPM_TAG_RQU_AUTH2_COMMAND);
  568. store32(tb, TPM_UNSEAL_SIZE + bloblen);
  569. store32(tb, TPM_ORD_UNSEAL);
  570. store32(tb, keyhandle);
  571. storebytes(tb, blob, bloblen);
  572. store32(tb, authhandle1);
  573. storebytes(tb, nonceodd, TPM_NONCE_SIZE);
  574. store8(tb, cont);
  575. storebytes(tb, authdata1, SHA1_DIGEST_SIZE);
  576. store32(tb, authhandle2);
  577. storebytes(tb, nonceodd, TPM_NONCE_SIZE);
  578. store8(tb, cont);
  579. storebytes(tb, authdata2, SHA1_DIGEST_SIZE);
  580. ret = trusted_tpm_send(TPM_ANY_NUM, tb->data, MAX_BUF_SIZE);
  581. if (ret < 0) {
  582. pr_info("trusted_key: authhmac failed (%d)\n", ret);
  583. return ret;
  584. }
  585. *datalen = LOAD32(tb->data, TPM_DATA_OFFSET);
  586. ret = TSS_checkhmac2(tb->data, ordinal, nonceodd,
  587. keyauth, SHA1_DIGEST_SIZE,
  588. blobauth, SHA1_DIGEST_SIZE,
  589. sizeof(uint32_t), TPM_DATA_OFFSET,
  590. *datalen, TPM_DATA_OFFSET + sizeof(uint32_t), 0,
  591. 0);
  592. if (ret < 0) {
  593. pr_info("trusted_key: TSS_checkhmac2 failed (%d)\n", ret);
  594. return ret;
  595. }
  596. memcpy(data, tb->data + TPM_DATA_OFFSET + sizeof(uint32_t), *datalen);
  597. return 0;
  598. }
  599. /*
  600. * Have the TPM seal(encrypt) the symmetric key
  601. */
  602. static int key_seal(struct trusted_key_payload *p,
  603. struct trusted_key_options *o)
  604. {
  605. struct tpm_buf *tb;
  606. int ret;
  607. tb = kzalloc(sizeof *tb, GFP_KERNEL);
  608. if (!tb)
  609. return -ENOMEM;
  610. /* include migratable flag at end of sealed key */
  611. p->key[p->key_len] = p->migratable;
  612. ret = tpm_seal(tb, o->keytype, o->keyhandle, o->keyauth,
  613. p->key, p->key_len + 1, p->blob, &p->blob_len,
  614. o->blobauth, o->pcrinfo, o->pcrinfo_len);
  615. if (ret < 0)
  616. pr_info("trusted_key: srkseal failed (%d)\n", ret);
  617. kzfree(tb);
  618. return ret;
  619. }
  620. /*
  621. * Have the TPM unseal(decrypt) the symmetric key
  622. */
  623. static int key_unseal(struct trusted_key_payload *p,
  624. struct trusted_key_options *o)
  625. {
  626. struct tpm_buf *tb;
  627. int ret;
  628. tb = kzalloc(sizeof *tb, GFP_KERNEL);
  629. if (!tb)
  630. return -ENOMEM;
  631. ret = tpm_unseal(tb, o->keyhandle, o->keyauth, p->blob, p->blob_len,
  632. o->blobauth, p->key, &p->key_len);
  633. if (ret < 0)
  634. pr_info("trusted_key: srkunseal failed (%d)\n", ret);
  635. else
  636. /* pull migratable flag out of sealed key */
  637. p->migratable = p->key[--p->key_len];
  638. kzfree(tb);
  639. return ret;
  640. }
  641. enum {
  642. Opt_err = -1,
  643. Opt_new, Opt_load, Opt_update,
  644. Opt_keyhandle, Opt_keyauth, Opt_blobauth,
  645. Opt_pcrinfo, Opt_pcrlock, Opt_migratable,
  646. Opt_hash,
  647. Opt_policydigest,
  648. Opt_policyhandle,
  649. };
  650. static const match_table_t key_tokens = {
  651. {Opt_new, "new"},
  652. {Opt_load, "load"},
  653. {Opt_update, "update"},
  654. {Opt_keyhandle, "keyhandle=%s"},
  655. {Opt_keyauth, "keyauth=%s"},
  656. {Opt_blobauth, "blobauth=%s"},
  657. {Opt_pcrinfo, "pcrinfo=%s"},
  658. {Opt_pcrlock, "pcrlock=%s"},
  659. {Opt_migratable, "migratable=%s"},
  660. {Opt_hash, "hash=%s"},
  661. {Opt_policydigest, "policydigest=%s"},
  662. {Opt_policyhandle, "policyhandle=%s"},
  663. {Opt_err, NULL}
  664. };
  665. /* can have zero or more token= options */
  666. static int getoptions(char *c, struct trusted_key_payload *pay,
  667. struct trusted_key_options *opt)
  668. {
  669. substring_t args[MAX_OPT_ARGS];
  670. char *p = c;
  671. int token;
  672. int res;
  673. unsigned long handle;
  674. unsigned long lock;
  675. unsigned long token_mask = 0;
  676. unsigned int digest_len;
  677. int i;
  678. int tpm2;
  679. tpm2 = tpm_is_tpm2(TPM_ANY_NUM);
  680. if (tpm2 < 0)
  681. return tpm2;
  682. opt->hash = tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1;
  683. while ((p = strsep(&c, " \t"))) {
  684. if (*p == '\0' || *p == ' ' || *p == '\t')
  685. continue;
  686. token = match_token(p, key_tokens, args);
  687. if (test_and_set_bit(token, &token_mask))
  688. return -EINVAL;
  689. switch (token) {
  690. case Opt_pcrinfo:
  691. opt->pcrinfo_len = strlen(args[0].from) / 2;
  692. if (opt->pcrinfo_len > MAX_PCRINFO_SIZE)
  693. return -EINVAL;
  694. res = hex2bin(opt->pcrinfo, args[0].from,
  695. opt->pcrinfo_len);
  696. if (res < 0)
  697. return -EINVAL;
  698. break;
  699. case Opt_keyhandle:
  700. res = kstrtoul(args[0].from, 16, &handle);
  701. if (res < 0)
  702. return -EINVAL;
  703. opt->keytype = SEAL_keytype;
  704. opt->keyhandle = handle;
  705. break;
  706. case Opt_keyauth:
  707. if (strlen(args[0].from) != 2 * SHA1_DIGEST_SIZE)
  708. return -EINVAL;
  709. res = hex2bin(opt->keyauth, args[0].from,
  710. SHA1_DIGEST_SIZE);
  711. if (res < 0)
  712. return -EINVAL;
  713. break;
  714. case Opt_blobauth:
  715. if (strlen(args[0].from) != 2 * SHA1_DIGEST_SIZE)
  716. return -EINVAL;
  717. res = hex2bin(opt->blobauth, args[0].from,
  718. SHA1_DIGEST_SIZE);
  719. if (res < 0)
  720. return -EINVAL;
  721. break;
  722. case Opt_migratable:
  723. if (*args[0].from == '0')
  724. pay->migratable = 0;
  725. else
  726. return -EINVAL;
  727. break;
  728. case Opt_pcrlock:
  729. res = kstrtoul(args[0].from, 10, &lock);
  730. if (res < 0)
  731. return -EINVAL;
  732. opt->pcrlock = lock;
  733. break;
  734. case Opt_hash:
  735. if (test_bit(Opt_policydigest, &token_mask))
  736. return -EINVAL;
  737. for (i = 0; i < HASH_ALGO__LAST; i++) {
  738. if (!strcmp(args[0].from, hash_algo_name[i])) {
  739. opt->hash = i;
  740. break;
  741. }
  742. }
  743. if (i == HASH_ALGO__LAST)
  744. return -EINVAL;
  745. if (!tpm2 && i != HASH_ALGO_SHA1) {
  746. pr_info("trusted_key: TPM 1.x only supports SHA-1.\n");
  747. return -EINVAL;
  748. }
  749. break;
  750. case Opt_policydigest:
  751. digest_len = hash_digest_size[opt->hash];
  752. if (!tpm2 || strlen(args[0].from) != (2 * digest_len))
  753. return -EINVAL;
  754. res = hex2bin(opt->policydigest, args[0].from,
  755. digest_len);
  756. if (res < 0)
  757. return -EINVAL;
  758. opt->policydigest_len = digest_len;
  759. break;
  760. case Opt_policyhandle:
  761. if (!tpm2)
  762. return -EINVAL;
  763. res = kstrtoul(args[0].from, 16, &handle);
  764. if (res < 0)
  765. return -EINVAL;
  766. opt->policyhandle = handle;
  767. break;
  768. default:
  769. return -EINVAL;
  770. }
  771. }
  772. return 0;
  773. }
  774. /*
  775. * datablob_parse - parse the keyctl data and fill in the
  776. * payload and options structures
  777. *
  778. * On success returns 0, otherwise -EINVAL.
  779. */
  780. static int datablob_parse(char *datablob, struct trusted_key_payload *p,
  781. struct trusted_key_options *o)
  782. {
  783. substring_t args[MAX_OPT_ARGS];
  784. long keylen;
  785. int ret = -EINVAL;
  786. int key_cmd;
  787. char *c;
  788. /* main command */
  789. c = strsep(&datablob, " \t");
  790. if (!c)
  791. return -EINVAL;
  792. key_cmd = match_token(c, key_tokens, args);
  793. switch (key_cmd) {
  794. case Opt_new:
  795. /* first argument is key size */
  796. c = strsep(&datablob, " \t");
  797. if (!c)
  798. return -EINVAL;
  799. ret = kstrtol(c, 10, &keylen);
  800. if (ret < 0 || keylen < MIN_KEY_SIZE || keylen > MAX_KEY_SIZE)
  801. return -EINVAL;
  802. p->key_len = keylen;
  803. ret = getoptions(datablob, p, o);
  804. if (ret < 0)
  805. return ret;
  806. ret = Opt_new;
  807. break;
  808. case Opt_load:
  809. /* first argument is sealed blob */
  810. c = strsep(&datablob, " \t");
  811. if (!c)
  812. return -EINVAL;
  813. p->blob_len = strlen(c) / 2;
  814. if (p->blob_len > MAX_BLOB_SIZE)
  815. return -EINVAL;
  816. ret = hex2bin(p->blob, c, p->blob_len);
  817. if (ret < 0)
  818. return -EINVAL;
  819. ret = getoptions(datablob, p, o);
  820. if (ret < 0)
  821. return ret;
  822. ret = Opt_load;
  823. break;
  824. case Opt_update:
  825. /* all arguments are options */
  826. ret = getoptions(datablob, p, o);
  827. if (ret < 0)
  828. return ret;
  829. ret = Opt_update;
  830. break;
  831. case Opt_err:
  832. return -EINVAL;
  833. break;
  834. }
  835. return ret;
  836. }
  837. static struct trusted_key_options *trusted_options_alloc(void)
  838. {
  839. struct trusted_key_options *options;
  840. int tpm2;
  841. tpm2 = tpm_is_tpm2(TPM_ANY_NUM);
  842. if (tpm2 < 0)
  843. return NULL;
  844. options = kzalloc(sizeof *options, GFP_KERNEL);
  845. if (options) {
  846. /* set any non-zero defaults */
  847. options->keytype = SRK_keytype;
  848. if (!tpm2)
  849. options->keyhandle = SRKHANDLE;
  850. }
  851. return options;
  852. }
  853. static struct trusted_key_payload *trusted_payload_alloc(struct key *key)
  854. {
  855. struct trusted_key_payload *p = NULL;
  856. int ret;
  857. ret = key_payload_reserve(key, sizeof *p);
  858. if (ret < 0)
  859. return p;
  860. p = kzalloc(sizeof *p, GFP_KERNEL);
  861. if (p)
  862. p->migratable = 1; /* migratable by default */
  863. return p;
  864. }
  865. /*
  866. * trusted_instantiate - create a new trusted key
  867. *
  868. * Unseal an existing trusted blob or, for a new key, get a
  869. * random key, then seal and create a trusted key-type key,
  870. * adding it to the specified keyring.
  871. *
  872. * On success, return 0. Otherwise return errno.
  873. */
  874. static int trusted_instantiate(struct key *key,
  875. struct key_preparsed_payload *prep)
  876. {
  877. struct trusted_key_payload *payload = NULL;
  878. struct trusted_key_options *options = NULL;
  879. size_t datalen = prep->datalen;
  880. char *datablob;
  881. int ret = 0;
  882. int key_cmd;
  883. size_t key_len;
  884. int tpm2;
  885. tpm2 = tpm_is_tpm2(TPM_ANY_NUM);
  886. if (tpm2 < 0)
  887. return tpm2;
  888. if (datalen <= 0 || datalen > 32767 || !prep->data)
  889. return -EINVAL;
  890. datablob = kmalloc(datalen + 1, GFP_KERNEL);
  891. if (!datablob)
  892. return -ENOMEM;
  893. memcpy(datablob, prep->data, datalen);
  894. datablob[datalen] = '\0';
  895. options = trusted_options_alloc();
  896. if (!options) {
  897. ret = -ENOMEM;
  898. goto out;
  899. }
  900. payload = trusted_payload_alloc(key);
  901. if (!payload) {
  902. ret = -ENOMEM;
  903. goto out;
  904. }
  905. key_cmd = datablob_parse(datablob, payload, options);
  906. if (key_cmd < 0) {
  907. ret = key_cmd;
  908. goto out;
  909. }
  910. if (!options->keyhandle) {
  911. ret = -EINVAL;
  912. goto out;
  913. }
  914. dump_payload(payload);
  915. dump_options(options);
  916. switch (key_cmd) {
  917. case Opt_load:
  918. if (tpm2)
  919. ret = tpm_unseal_trusted(TPM_ANY_NUM, payload, options);
  920. else
  921. ret = key_unseal(payload, options);
  922. dump_payload(payload);
  923. dump_options(options);
  924. if (ret < 0)
  925. pr_info("trusted_key: key_unseal failed (%d)\n", ret);
  926. break;
  927. case Opt_new:
  928. key_len = payload->key_len;
  929. ret = tpm_get_random(TPM_ANY_NUM, payload->key, key_len);
  930. if (ret != key_len) {
  931. pr_info("trusted_key: key_create failed (%d)\n", ret);
  932. goto out;
  933. }
  934. if (tpm2)
  935. ret = tpm_seal_trusted(TPM_ANY_NUM, payload, options);
  936. else
  937. ret = key_seal(payload, options);
  938. if (ret < 0)
  939. pr_info("trusted_key: key_seal failed (%d)\n", ret);
  940. break;
  941. default:
  942. ret = -EINVAL;
  943. goto out;
  944. }
  945. if (!ret && options->pcrlock)
  946. ret = pcrlock(options->pcrlock);
  947. out:
  948. kzfree(datablob);
  949. kzfree(options);
  950. if (!ret)
  951. rcu_assign_keypointer(key, payload);
  952. else
  953. kzfree(payload);
  954. return ret;
  955. }
  956. static void trusted_rcu_free(struct rcu_head *rcu)
  957. {
  958. struct trusted_key_payload *p;
  959. p = container_of(rcu, struct trusted_key_payload, rcu);
  960. kzfree(p);
  961. }
  962. /*
  963. * trusted_update - reseal an existing key with new PCR values
  964. */
  965. static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
  966. {
  967. struct trusted_key_payload *p;
  968. struct trusted_key_payload *new_p;
  969. struct trusted_key_options *new_o;
  970. size_t datalen = prep->datalen;
  971. char *datablob;
  972. int ret = 0;
  973. if (key_is_negative(key))
  974. return -ENOKEY;
  975. p = key->payload.data[0];
  976. if (!p->migratable)
  977. return -EPERM;
  978. if (datalen <= 0 || datalen > 32767 || !prep->data)
  979. return -EINVAL;
  980. datablob = kmalloc(datalen + 1, GFP_KERNEL);
  981. if (!datablob)
  982. return -ENOMEM;
  983. new_o = trusted_options_alloc();
  984. if (!new_o) {
  985. ret = -ENOMEM;
  986. goto out;
  987. }
  988. new_p = trusted_payload_alloc(key);
  989. if (!new_p) {
  990. ret = -ENOMEM;
  991. goto out;
  992. }
  993. memcpy(datablob, prep->data, datalen);
  994. datablob[datalen] = '\0';
  995. ret = datablob_parse(datablob, new_p, new_o);
  996. if (ret != Opt_update) {
  997. ret = -EINVAL;
  998. kzfree(new_p);
  999. goto out;
  1000. }
  1001. if (!new_o->keyhandle) {
  1002. ret = -EINVAL;
  1003. kzfree(new_p);
  1004. goto out;
  1005. }
  1006. /* copy old key values, and reseal with new pcrs */
  1007. new_p->migratable = p->migratable;
  1008. new_p->key_len = p->key_len;
  1009. memcpy(new_p->key, p->key, p->key_len);
  1010. dump_payload(p);
  1011. dump_payload(new_p);
  1012. ret = key_seal(new_p, new_o);
  1013. if (ret < 0) {
  1014. pr_info("trusted_key: key_seal failed (%d)\n", ret);
  1015. kzfree(new_p);
  1016. goto out;
  1017. }
  1018. if (new_o->pcrlock) {
  1019. ret = pcrlock(new_o->pcrlock);
  1020. if (ret < 0) {
  1021. pr_info("trusted_key: pcrlock failed (%d)\n", ret);
  1022. kzfree(new_p);
  1023. goto out;
  1024. }
  1025. }
  1026. rcu_assign_keypointer(key, new_p);
  1027. call_rcu(&p->rcu, trusted_rcu_free);
  1028. out:
  1029. kzfree(datablob);
  1030. kzfree(new_o);
  1031. return ret;
  1032. }
  1033. /*
  1034. * trusted_read - copy the sealed blob data to userspace in hex.
  1035. * On success, return to userspace the trusted key datablob size.
  1036. */
  1037. static long trusted_read(const struct key *key, char __user *buffer,
  1038. size_t buflen)
  1039. {
  1040. struct trusted_key_payload *p;
  1041. char *ascii_buf;
  1042. char *bufp;
  1043. int i;
  1044. p = rcu_dereference_key(key);
  1045. if (!p)
  1046. return -EINVAL;
  1047. if (buffer && buflen >= 2 * p->blob_len) {
  1048. ascii_buf = kmalloc(2 * p->blob_len, GFP_KERNEL);
  1049. if (!ascii_buf)
  1050. return -ENOMEM;
  1051. bufp = ascii_buf;
  1052. for (i = 0; i < p->blob_len; i++)
  1053. bufp = hex_byte_pack(bufp, p->blob[i]);
  1054. if (copy_to_user(buffer, ascii_buf, 2 * p->blob_len) != 0) {
  1055. kzfree(ascii_buf);
  1056. return -EFAULT;
  1057. }
  1058. kzfree(ascii_buf);
  1059. }
  1060. return 2 * p->blob_len;
  1061. }
  1062. /*
  1063. * trusted_destroy - clear and free the key's payload
  1064. */
  1065. static void trusted_destroy(struct key *key)
  1066. {
  1067. kzfree(key->payload.data[0]);
  1068. }
  1069. struct key_type key_type_trusted = {
  1070. .name = "trusted",
  1071. .instantiate = trusted_instantiate,
  1072. .update = trusted_update,
  1073. .destroy = trusted_destroy,
  1074. .describe = user_describe,
  1075. .read = trusted_read,
  1076. };
  1077. EXPORT_SYMBOL_GPL(key_type_trusted);
  1078. static void trusted_shash_release(void)
  1079. {
  1080. if (hashalg)
  1081. crypto_free_shash(hashalg);
  1082. if (hmacalg)
  1083. crypto_free_shash(hmacalg);
  1084. }
  1085. static int __init trusted_shash_alloc(void)
  1086. {
  1087. int ret;
  1088. hmacalg = crypto_alloc_shash(hmac_alg, 0, CRYPTO_ALG_ASYNC);
  1089. if (IS_ERR(hmacalg)) {
  1090. pr_info("trusted_key: could not allocate crypto %s\n",
  1091. hmac_alg);
  1092. return PTR_ERR(hmacalg);
  1093. }
  1094. hashalg = crypto_alloc_shash(hash_alg, 0, CRYPTO_ALG_ASYNC);
  1095. if (IS_ERR(hashalg)) {
  1096. pr_info("trusted_key: could not allocate crypto %s\n",
  1097. hash_alg);
  1098. ret = PTR_ERR(hashalg);
  1099. goto hashalg_fail;
  1100. }
  1101. return 0;
  1102. hashalg_fail:
  1103. crypto_free_shash(hmacalg);
  1104. return ret;
  1105. }
  1106. static int __init init_trusted(void)
  1107. {
  1108. int ret;
  1109. ret = trusted_shash_alloc();
  1110. if (ret < 0)
  1111. return ret;
  1112. ret = register_key_type(&key_type_trusted);
  1113. if (ret < 0)
  1114. trusted_shash_release();
  1115. return ret;
  1116. }
  1117. static void __exit cleanup_trusted(void)
  1118. {
  1119. trusted_shash_release();
  1120. unregister_key_type(&key_type_trusted);
  1121. }
  1122. late_initcall(init_trusted);
  1123. module_exit(cleanup_trusted);
  1124. MODULE_LICENSE("GPL");