efi_test.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * EFI Test Driver for Runtime Services
  4. *
  5. * Copyright(C) 2012-2016 Canonical Ltd.
  6. *
  7. * This driver exports EFI runtime services interfaces into userspace, which
  8. * allow to use and test UEFI runtime services provided by firmware.
  9. *
  10. */
  11. #include <linux/miscdevice.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/proc_fs.h>
  15. #include <linux/efi.h>
  16. #include <linux/security.h>
  17. #include <linux/slab.h>
  18. #include <linux/uaccess.h>
  19. #include "efi_test.h"
  20. MODULE_AUTHOR("Ivan Hu <[email protected]>");
  21. MODULE_DESCRIPTION("EFI Test Driver");
  22. MODULE_LICENSE("GPL");
  23. /*
  24. * Count the bytes in 'str', including the terminating NULL.
  25. *
  26. * Note this function returns the number of *bytes*, not the number of
  27. * ucs2 characters.
  28. */
  29. static inline size_t user_ucs2_strsize(efi_char16_t __user *str)
  30. {
  31. efi_char16_t *s = str, c;
  32. size_t len;
  33. if (!str)
  34. return 0;
  35. /* Include terminating NULL */
  36. len = sizeof(efi_char16_t);
  37. if (get_user(c, s++)) {
  38. /* Can't read userspace memory for size */
  39. return 0;
  40. }
  41. while (c != 0) {
  42. if (get_user(c, s++)) {
  43. /* Can't read userspace memory for size */
  44. return 0;
  45. }
  46. len += sizeof(efi_char16_t);
  47. }
  48. return len;
  49. }
  50. /*
  51. * Allocate a buffer and copy a ucs2 string from user space into it.
  52. */
  53. static inline int
  54. copy_ucs2_from_user_len(efi_char16_t **dst, efi_char16_t __user *src,
  55. size_t len)
  56. {
  57. efi_char16_t *buf;
  58. if (!src) {
  59. *dst = NULL;
  60. return 0;
  61. }
  62. buf = memdup_user(src, len);
  63. if (IS_ERR(buf)) {
  64. *dst = NULL;
  65. return PTR_ERR(buf);
  66. }
  67. *dst = buf;
  68. return 0;
  69. }
  70. /*
  71. * Count the bytes in 'str', including the terminating NULL.
  72. *
  73. * Just a wrap for user_ucs2_strsize
  74. */
  75. static inline int
  76. get_ucs2_strsize_from_user(efi_char16_t __user *src, size_t *len)
  77. {
  78. *len = user_ucs2_strsize(src);
  79. if (*len == 0)
  80. return -EFAULT;
  81. return 0;
  82. }
  83. /*
  84. * Calculate the required buffer allocation size and copy a ucs2 string
  85. * from user space into it.
  86. *
  87. * This function differs from copy_ucs2_from_user_len() because it
  88. * calculates the size of the buffer to allocate by taking the length of
  89. * the string 'src'.
  90. *
  91. * If a non-zero value is returned, the caller MUST NOT access 'dst'.
  92. *
  93. * It is the caller's responsibility to free 'dst'.
  94. */
  95. static inline int
  96. copy_ucs2_from_user(efi_char16_t **dst, efi_char16_t __user *src)
  97. {
  98. size_t len;
  99. len = user_ucs2_strsize(src);
  100. if (len == 0)
  101. return -EFAULT;
  102. return copy_ucs2_from_user_len(dst, src, len);
  103. }
  104. /*
  105. * Copy a ucs2 string to a user buffer.
  106. *
  107. * This function is a simple wrapper around copy_to_user() that does
  108. * nothing if 'src' is NULL, which is useful for reducing the amount of
  109. * NULL checking the caller has to do.
  110. *
  111. * 'len' specifies the number of bytes to copy.
  112. */
  113. static inline int
  114. copy_ucs2_to_user_len(efi_char16_t __user *dst, efi_char16_t *src, size_t len)
  115. {
  116. if (!src)
  117. return 0;
  118. return copy_to_user(dst, src, len);
  119. }
  120. static long efi_runtime_get_variable(unsigned long arg)
  121. {
  122. struct efi_getvariable __user *getvariable_user;
  123. struct efi_getvariable getvariable;
  124. unsigned long datasize = 0, prev_datasize, *dz;
  125. efi_guid_t vendor_guid, *vd = NULL;
  126. efi_status_t status;
  127. efi_char16_t *name = NULL;
  128. u32 attr, *at;
  129. void *data = NULL;
  130. int rv = 0;
  131. getvariable_user = (struct efi_getvariable __user *)arg;
  132. if (copy_from_user(&getvariable, getvariable_user,
  133. sizeof(getvariable)))
  134. return -EFAULT;
  135. if (getvariable.data_size &&
  136. get_user(datasize, getvariable.data_size))
  137. return -EFAULT;
  138. if (getvariable.vendor_guid) {
  139. if (copy_from_user(&vendor_guid, getvariable.vendor_guid,
  140. sizeof(vendor_guid)))
  141. return -EFAULT;
  142. vd = &vendor_guid;
  143. }
  144. if (getvariable.variable_name) {
  145. rv = copy_ucs2_from_user(&name, getvariable.variable_name);
  146. if (rv)
  147. return rv;
  148. }
  149. at = getvariable.attributes ? &attr : NULL;
  150. dz = getvariable.data_size ? &datasize : NULL;
  151. if (getvariable.data_size && getvariable.data) {
  152. data = kmalloc(datasize, GFP_KERNEL);
  153. if (!data) {
  154. kfree(name);
  155. return -ENOMEM;
  156. }
  157. }
  158. prev_datasize = datasize;
  159. status = efi.get_variable(name, vd, at, dz, data);
  160. kfree(name);
  161. if (put_user(status, getvariable.status)) {
  162. rv = -EFAULT;
  163. goto out;
  164. }
  165. if (status != EFI_SUCCESS) {
  166. if (status == EFI_BUFFER_TOO_SMALL) {
  167. if (dz && put_user(datasize, getvariable.data_size)) {
  168. rv = -EFAULT;
  169. goto out;
  170. }
  171. }
  172. rv = -EINVAL;
  173. goto out;
  174. }
  175. if (prev_datasize < datasize) {
  176. rv = -EINVAL;
  177. goto out;
  178. }
  179. if (data) {
  180. if (copy_to_user(getvariable.data, data, datasize)) {
  181. rv = -EFAULT;
  182. goto out;
  183. }
  184. }
  185. if (at && put_user(attr, getvariable.attributes)) {
  186. rv = -EFAULT;
  187. goto out;
  188. }
  189. if (dz && put_user(datasize, getvariable.data_size))
  190. rv = -EFAULT;
  191. out:
  192. kfree(data);
  193. return rv;
  194. }
  195. static long efi_runtime_set_variable(unsigned long arg)
  196. {
  197. struct efi_setvariable __user *setvariable_user;
  198. struct efi_setvariable setvariable;
  199. efi_guid_t vendor_guid;
  200. efi_status_t status;
  201. efi_char16_t *name = NULL;
  202. void *data;
  203. int rv = 0;
  204. setvariable_user = (struct efi_setvariable __user *)arg;
  205. if (copy_from_user(&setvariable, setvariable_user, sizeof(setvariable)))
  206. return -EFAULT;
  207. if (copy_from_user(&vendor_guid, setvariable.vendor_guid,
  208. sizeof(vendor_guid)))
  209. return -EFAULT;
  210. if (setvariable.variable_name) {
  211. rv = copy_ucs2_from_user(&name, setvariable.variable_name);
  212. if (rv)
  213. return rv;
  214. }
  215. data = memdup_user(setvariable.data, setvariable.data_size);
  216. if (IS_ERR(data)) {
  217. kfree(name);
  218. return PTR_ERR(data);
  219. }
  220. status = efi.set_variable(name, &vendor_guid,
  221. setvariable.attributes,
  222. setvariable.data_size, data);
  223. if (put_user(status, setvariable.status)) {
  224. rv = -EFAULT;
  225. goto out;
  226. }
  227. rv = status == EFI_SUCCESS ? 0 : -EINVAL;
  228. out:
  229. kfree(data);
  230. kfree(name);
  231. return rv;
  232. }
  233. static long efi_runtime_get_time(unsigned long arg)
  234. {
  235. struct efi_gettime __user *gettime_user;
  236. struct efi_gettime gettime;
  237. efi_status_t status;
  238. efi_time_cap_t cap;
  239. efi_time_t efi_time;
  240. gettime_user = (struct efi_gettime __user *)arg;
  241. if (copy_from_user(&gettime, gettime_user, sizeof(gettime)))
  242. return -EFAULT;
  243. status = efi.get_time(gettime.time ? &efi_time : NULL,
  244. gettime.capabilities ? &cap : NULL);
  245. if (put_user(status, gettime.status))
  246. return -EFAULT;
  247. if (status != EFI_SUCCESS)
  248. return -EINVAL;
  249. if (gettime.capabilities) {
  250. efi_time_cap_t __user *cap_local;
  251. cap_local = (efi_time_cap_t *)gettime.capabilities;
  252. if (put_user(cap.resolution, &(cap_local->resolution)) ||
  253. put_user(cap.accuracy, &(cap_local->accuracy)) ||
  254. put_user(cap.sets_to_zero, &(cap_local->sets_to_zero)))
  255. return -EFAULT;
  256. }
  257. if (gettime.time) {
  258. if (copy_to_user(gettime.time, &efi_time, sizeof(efi_time_t)))
  259. return -EFAULT;
  260. }
  261. return 0;
  262. }
  263. static long efi_runtime_set_time(unsigned long arg)
  264. {
  265. struct efi_settime __user *settime_user;
  266. struct efi_settime settime;
  267. efi_status_t status;
  268. efi_time_t efi_time;
  269. settime_user = (struct efi_settime __user *)arg;
  270. if (copy_from_user(&settime, settime_user, sizeof(settime)))
  271. return -EFAULT;
  272. if (copy_from_user(&efi_time, settime.time,
  273. sizeof(efi_time_t)))
  274. return -EFAULT;
  275. status = efi.set_time(&efi_time);
  276. if (put_user(status, settime.status))
  277. return -EFAULT;
  278. return status == EFI_SUCCESS ? 0 : -EINVAL;
  279. }
  280. static long efi_runtime_get_waketime(unsigned long arg)
  281. {
  282. struct efi_getwakeuptime __user *getwakeuptime_user;
  283. struct efi_getwakeuptime getwakeuptime;
  284. efi_bool_t enabled, pending;
  285. efi_status_t status;
  286. efi_time_t efi_time;
  287. getwakeuptime_user = (struct efi_getwakeuptime __user *)arg;
  288. if (copy_from_user(&getwakeuptime, getwakeuptime_user,
  289. sizeof(getwakeuptime)))
  290. return -EFAULT;
  291. status = efi.get_wakeup_time(
  292. getwakeuptime.enabled ? (efi_bool_t *)&enabled : NULL,
  293. getwakeuptime.pending ? (efi_bool_t *)&pending : NULL,
  294. getwakeuptime.time ? &efi_time : NULL);
  295. if (put_user(status, getwakeuptime.status))
  296. return -EFAULT;
  297. if (status != EFI_SUCCESS)
  298. return -EINVAL;
  299. if (getwakeuptime.enabled && put_user(enabled,
  300. getwakeuptime.enabled))
  301. return -EFAULT;
  302. if (getwakeuptime.time) {
  303. if (copy_to_user(getwakeuptime.time, &efi_time,
  304. sizeof(efi_time_t)))
  305. return -EFAULT;
  306. }
  307. return 0;
  308. }
  309. static long efi_runtime_set_waketime(unsigned long arg)
  310. {
  311. struct efi_setwakeuptime __user *setwakeuptime_user;
  312. struct efi_setwakeuptime setwakeuptime;
  313. efi_bool_t enabled;
  314. efi_status_t status;
  315. efi_time_t efi_time;
  316. setwakeuptime_user = (struct efi_setwakeuptime __user *)arg;
  317. if (copy_from_user(&setwakeuptime, setwakeuptime_user,
  318. sizeof(setwakeuptime)))
  319. return -EFAULT;
  320. enabled = setwakeuptime.enabled;
  321. if (setwakeuptime.time) {
  322. if (copy_from_user(&efi_time, setwakeuptime.time,
  323. sizeof(efi_time_t)))
  324. return -EFAULT;
  325. status = efi.set_wakeup_time(enabled, &efi_time);
  326. } else
  327. status = efi.set_wakeup_time(enabled, NULL);
  328. if (put_user(status, setwakeuptime.status))
  329. return -EFAULT;
  330. return status == EFI_SUCCESS ? 0 : -EINVAL;
  331. }
  332. static long efi_runtime_get_nextvariablename(unsigned long arg)
  333. {
  334. struct efi_getnextvariablename __user *getnextvariablename_user;
  335. struct efi_getnextvariablename getnextvariablename;
  336. unsigned long name_size, prev_name_size = 0, *ns = NULL;
  337. efi_status_t status;
  338. efi_guid_t *vd = NULL;
  339. efi_guid_t vendor_guid;
  340. efi_char16_t *name = NULL;
  341. int rv = 0;
  342. getnextvariablename_user = (struct efi_getnextvariablename __user *)arg;
  343. if (copy_from_user(&getnextvariablename, getnextvariablename_user,
  344. sizeof(getnextvariablename)))
  345. return -EFAULT;
  346. if (getnextvariablename.variable_name_size) {
  347. if (get_user(name_size, getnextvariablename.variable_name_size))
  348. return -EFAULT;
  349. ns = &name_size;
  350. prev_name_size = name_size;
  351. }
  352. if (getnextvariablename.vendor_guid) {
  353. if (copy_from_user(&vendor_guid,
  354. getnextvariablename.vendor_guid,
  355. sizeof(vendor_guid)))
  356. return -EFAULT;
  357. vd = &vendor_guid;
  358. }
  359. if (getnextvariablename.variable_name) {
  360. size_t name_string_size = 0;
  361. rv = get_ucs2_strsize_from_user(
  362. getnextvariablename.variable_name,
  363. &name_string_size);
  364. if (rv)
  365. return rv;
  366. /*
  367. * The name_size may be smaller than the real buffer size where
  368. * variable name located in some use cases. The most typical
  369. * case is passing a 0 to get the required buffer size for the
  370. * 1st time call. So we need to copy the content from user
  371. * space for at least the string size of variable name, or else
  372. * the name passed to UEFI may not be terminated as we expected.
  373. */
  374. rv = copy_ucs2_from_user_len(&name,
  375. getnextvariablename.variable_name,
  376. prev_name_size > name_string_size ?
  377. prev_name_size : name_string_size);
  378. if (rv)
  379. return rv;
  380. }
  381. status = efi.get_next_variable(ns, name, vd);
  382. if (put_user(status, getnextvariablename.status)) {
  383. rv = -EFAULT;
  384. goto out;
  385. }
  386. if (status != EFI_SUCCESS) {
  387. if (status == EFI_BUFFER_TOO_SMALL) {
  388. if (ns && put_user(*ns,
  389. getnextvariablename.variable_name_size)) {
  390. rv = -EFAULT;
  391. goto out;
  392. }
  393. }
  394. rv = -EINVAL;
  395. goto out;
  396. }
  397. if (name) {
  398. if (copy_ucs2_to_user_len(getnextvariablename.variable_name,
  399. name, prev_name_size)) {
  400. rv = -EFAULT;
  401. goto out;
  402. }
  403. }
  404. if (ns) {
  405. if (put_user(*ns, getnextvariablename.variable_name_size)) {
  406. rv = -EFAULT;
  407. goto out;
  408. }
  409. }
  410. if (vd) {
  411. if (copy_to_user(getnextvariablename.vendor_guid, vd,
  412. sizeof(efi_guid_t)))
  413. rv = -EFAULT;
  414. }
  415. out:
  416. kfree(name);
  417. return rv;
  418. }
  419. static long efi_runtime_get_nexthighmonocount(unsigned long arg)
  420. {
  421. struct efi_getnexthighmonotoniccount __user *getnexthighmonocount_user;
  422. struct efi_getnexthighmonotoniccount getnexthighmonocount;
  423. efi_status_t status;
  424. u32 count;
  425. getnexthighmonocount_user = (struct
  426. efi_getnexthighmonotoniccount __user *)arg;
  427. if (copy_from_user(&getnexthighmonocount,
  428. getnexthighmonocount_user,
  429. sizeof(getnexthighmonocount)))
  430. return -EFAULT;
  431. status = efi.get_next_high_mono_count(
  432. getnexthighmonocount.high_count ? &count : NULL);
  433. if (put_user(status, getnexthighmonocount.status))
  434. return -EFAULT;
  435. if (status != EFI_SUCCESS)
  436. return -EINVAL;
  437. if (getnexthighmonocount.high_count &&
  438. put_user(count, getnexthighmonocount.high_count))
  439. return -EFAULT;
  440. return 0;
  441. }
  442. static long efi_runtime_reset_system(unsigned long arg)
  443. {
  444. struct efi_resetsystem __user *resetsystem_user;
  445. struct efi_resetsystem resetsystem;
  446. void *data = NULL;
  447. resetsystem_user = (struct efi_resetsystem __user *)arg;
  448. if (copy_from_user(&resetsystem, resetsystem_user,
  449. sizeof(resetsystem)))
  450. return -EFAULT;
  451. if (resetsystem.data_size != 0) {
  452. data = memdup_user((void *)resetsystem.data,
  453. resetsystem.data_size);
  454. if (IS_ERR(data))
  455. return PTR_ERR(data);
  456. }
  457. efi.reset_system(resetsystem.reset_type, resetsystem.status,
  458. resetsystem.data_size, (efi_char16_t *)data);
  459. kfree(data);
  460. return 0;
  461. }
  462. static long efi_runtime_query_variableinfo(unsigned long arg)
  463. {
  464. struct efi_queryvariableinfo __user *queryvariableinfo_user;
  465. struct efi_queryvariableinfo queryvariableinfo;
  466. efi_status_t status;
  467. u64 max_storage, remaining, max_size;
  468. queryvariableinfo_user = (struct efi_queryvariableinfo __user *)arg;
  469. if (copy_from_user(&queryvariableinfo, queryvariableinfo_user,
  470. sizeof(queryvariableinfo)))
  471. return -EFAULT;
  472. status = efi.query_variable_info(queryvariableinfo.attributes,
  473. &max_storage, &remaining, &max_size);
  474. if (put_user(status, queryvariableinfo.status))
  475. return -EFAULT;
  476. if (status != EFI_SUCCESS)
  477. return -EINVAL;
  478. if (put_user(max_storage,
  479. queryvariableinfo.maximum_variable_storage_size))
  480. return -EFAULT;
  481. if (put_user(remaining,
  482. queryvariableinfo.remaining_variable_storage_size))
  483. return -EFAULT;
  484. if (put_user(max_size, queryvariableinfo.maximum_variable_size))
  485. return -EFAULT;
  486. return 0;
  487. }
  488. static long efi_runtime_query_capsulecaps(unsigned long arg)
  489. {
  490. struct efi_querycapsulecapabilities __user *qcaps_user;
  491. struct efi_querycapsulecapabilities qcaps;
  492. efi_capsule_header_t *capsules;
  493. efi_status_t status;
  494. u64 max_size;
  495. int i, reset_type;
  496. int rv = 0;
  497. qcaps_user = (struct efi_querycapsulecapabilities __user *)arg;
  498. if (copy_from_user(&qcaps, qcaps_user, sizeof(qcaps)))
  499. return -EFAULT;
  500. if (qcaps.capsule_count == ULONG_MAX)
  501. return -EINVAL;
  502. capsules = kcalloc(qcaps.capsule_count + 1,
  503. sizeof(efi_capsule_header_t), GFP_KERNEL);
  504. if (!capsules)
  505. return -ENOMEM;
  506. for (i = 0; i < qcaps.capsule_count; i++) {
  507. efi_capsule_header_t *c;
  508. /*
  509. * We cannot dereference qcaps.capsule_header_array directly to
  510. * obtain the address of the capsule as it resides in the
  511. * user space
  512. */
  513. if (get_user(c, qcaps.capsule_header_array + i)) {
  514. rv = -EFAULT;
  515. goto out;
  516. }
  517. if (copy_from_user(&capsules[i], c,
  518. sizeof(efi_capsule_header_t))) {
  519. rv = -EFAULT;
  520. goto out;
  521. }
  522. }
  523. qcaps.capsule_header_array = &capsules;
  524. status = efi.query_capsule_caps((efi_capsule_header_t **)
  525. qcaps.capsule_header_array,
  526. qcaps.capsule_count,
  527. &max_size, &reset_type);
  528. if (put_user(status, qcaps.status)) {
  529. rv = -EFAULT;
  530. goto out;
  531. }
  532. if (status != EFI_SUCCESS) {
  533. rv = -EINVAL;
  534. goto out;
  535. }
  536. if (put_user(max_size, qcaps.maximum_capsule_size)) {
  537. rv = -EFAULT;
  538. goto out;
  539. }
  540. if (put_user(reset_type, qcaps.reset_type))
  541. rv = -EFAULT;
  542. out:
  543. kfree(capsules);
  544. return rv;
  545. }
  546. static long efi_runtime_get_supported_mask(unsigned long arg)
  547. {
  548. unsigned int __user *supported_mask;
  549. int rv = 0;
  550. supported_mask = (unsigned int *)arg;
  551. if (put_user(efi.runtime_supported_mask, supported_mask))
  552. rv = -EFAULT;
  553. return rv;
  554. }
  555. static long efi_test_ioctl(struct file *file, unsigned int cmd,
  556. unsigned long arg)
  557. {
  558. switch (cmd) {
  559. case EFI_RUNTIME_GET_VARIABLE:
  560. return efi_runtime_get_variable(arg);
  561. case EFI_RUNTIME_SET_VARIABLE:
  562. return efi_runtime_set_variable(arg);
  563. case EFI_RUNTIME_GET_TIME:
  564. return efi_runtime_get_time(arg);
  565. case EFI_RUNTIME_SET_TIME:
  566. return efi_runtime_set_time(arg);
  567. case EFI_RUNTIME_GET_WAKETIME:
  568. return efi_runtime_get_waketime(arg);
  569. case EFI_RUNTIME_SET_WAKETIME:
  570. return efi_runtime_set_waketime(arg);
  571. case EFI_RUNTIME_GET_NEXTVARIABLENAME:
  572. return efi_runtime_get_nextvariablename(arg);
  573. case EFI_RUNTIME_GET_NEXTHIGHMONOTONICCOUNT:
  574. return efi_runtime_get_nexthighmonocount(arg);
  575. case EFI_RUNTIME_QUERY_VARIABLEINFO:
  576. return efi_runtime_query_variableinfo(arg);
  577. case EFI_RUNTIME_QUERY_CAPSULECAPABILITIES:
  578. return efi_runtime_query_capsulecaps(arg);
  579. case EFI_RUNTIME_RESET_SYSTEM:
  580. return efi_runtime_reset_system(arg);
  581. case EFI_RUNTIME_GET_SUPPORTED_MASK:
  582. return efi_runtime_get_supported_mask(arg);
  583. }
  584. return -ENOTTY;
  585. }
  586. static int efi_test_open(struct inode *inode, struct file *file)
  587. {
  588. int ret = security_locked_down(LOCKDOWN_EFI_TEST);
  589. if (ret)
  590. return ret;
  591. if (!capable(CAP_SYS_ADMIN))
  592. return -EACCES;
  593. /*
  594. * nothing special to do here
  595. * We do accept multiple open files at the same time as we
  596. * synchronize on the per call operation.
  597. */
  598. return 0;
  599. }
  600. static int efi_test_close(struct inode *inode, struct file *file)
  601. {
  602. return 0;
  603. }
  604. /*
  605. * The various file operations we support.
  606. */
  607. static const struct file_operations efi_test_fops = {
  608. .owner = THIS_MODULE,
  609. .unlocked_ioctl = efi_test_ioctl,
  610. .open = efi_test_open,
  611. .release = efi_test_close,
  612. .llseek = no_llseek,
  613. };
  614. static struct miscdevice efi_test_dev = {
  615. MISC_DYNAMIC_MINOR,
  616. "efi_test",
  617. &efi_test_fops
  618. };
  619. static int __init efi_test_init(void)
  620. {
  621. int ret;
  622. ret = misc_register(&efi_test_dev);
  623. if (ret) {
  624. pr_err("efi_test: can't misc_register on minor=%d\n",
  625. MISC_DYNAMIC_MINOR);
  626. return ret;
  627. }
  628. return 0;
  629. }
  630. static void __exit efi_test_exit(void)
  631. {
  632. misc_deregister(&efi_test_dev);
  633. }
  634. module_init(efi_test_init);
  635. module_exit(efi_test_exit);