efi_test.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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 <ivan.hu@canonical.com>");
  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.pending && put_user(pending,
  303. getwakeuptime.pending))
  304. return -EFAULT;
  305. if (getwakeuptime.time) {
  306. if (copy_to_user(getwakeuptime.time, &efi_time,
  307. sizeof(efi_time_t)))
  308. return -EFAULT;
  309. }
  310. return 0;
  311. }
  312. static long efi_runtime_set_waketime(unsigned long arg)
  313. {
  314. struct efi_setwakeuptime __user *setwakeuptime_user;
  315. struct efi_setwakeuptime setwakeuptime;
  316. efi_bool_t enabled;
  317. efi_status_t status;
  318. efi_time_t efi_time;
  319. setwakeuptime_user = (struct efi_setwakeuptime __user *)arg;
  320. if (copy_from_user(&setwakeuptime, setwakeuptime_user,
  321. sizeof(setwakeuptime)))
  322. return -EFAULT;
  323. enabled = setwakeuptime.enabled;
  324. if (setwakeuptime.time) {
  325. if (copy_from_user(&efi_time, setwakeuptime.time,
  326. sizeof(efi_time_t)))
  327. return -EFAULT;
  328. status = efi.set_wakeup_time(enabled, &efi_time);
  329. } else
  330. status = efi.set_wakeup_time(enabled, NULL);
  331. if (put_user(status, setwakeuptime.status))
  332. return -EFAULT;
  333. return status == EFI_SUCCESS ? 0 : -EINVAL;
  334. }
  335. static long efi_runtime_get_nextvariablename(unsigned long arg)
  336. {
  337. struct efi_getnextvariablename __user *getnextvariablename_user;
  338. struct efi_getnextvariablename getnextvariablename;
  339. unsigned long name_size, prev_name_size = 0, *ns = NULL;
  340. efi_status_t status;
  341. efi_guid_t *vd = NULL;
  342. efi_guid_t vendor_guid;
  343. efi_char16_t *name = NULL;
  344. int rv = 0;
  345. getnextvariablename_user = (struct efi_getnextvariablename __user *)arg;
  346. if (copy_from_user(&getnextvariablename, getnextvariablename_user,
  347. sizeof(getnextvariablename)))
  348. return -EFAULT;
  349. if (getnextvariablename.variable_name_size) {
  350. if (get_user(name_size, getnextvariablename.variable_name_size))
  351. return -EFAULT;
  352. ns = &name_size;
  353. prev_name_size = name_size;
  354. }
  355. if (getnextvariablename.vendor_guid) {
  356. if (copy_from_user(&vendor_guid,
  357. getnextvariablename.vendor_guid,
  358. sizeof(vendor_guid)))
  359. return -EFAULT;
  360. vd = &vendor_guid;
  361. }
  362. if (getnextvariablename.variable_name) {
  363. size_t name_string_size = 0;
  364. rv = get_ucs2_strsize_from_user(
  365. getnextvariablename.variable_name,
  366. &name_string_size);
  367. if (rv)
  368. return rv;
  369. /*
  370. * The name_size may be smaller than the real buffer size where
  371. * variable name located in some use cases. The most typical
  372. * case is passing a 0 to get the required buffer size for the
  373. * 1st time call. So we need to copy the content from user
  374. * space for at least the string size of variable name, or else
  375. * the name passed to UEFI may not be terminated as we expected.
  376. */
  377. rv = copy_ucs2_from_user_len(&name,
  378. getnextvariablename.variable_name,
  379. prev_name_size > name_string_size ?
  380. prev_name_size : name_string_size);
  381. if (rv)
  382. return rv;
  383. }
  384. status = efi.get_next_variable(ns, name, vd);
  385. if (put_user(status, getnextvariablename.status)) {
  386. rv = -EFAULT;
  387. goto out;
  388. }
  389. if (status != EFI_SUCCESS) {
  390. if (status == EFI_BUFFER_TOO_SMALL) {
  391. if (ns && put_user(*ns,
  392. getnextvariablename.variable_name_size)) {
  393. rv = -EFAULT;
  394. goto out;
  395. }
  396. }
  397. rv = -EINVAL;
  398. goto out;
  399. }
  400. if (name) {
  401. if (copy_ucs2_to_user_len(getnextvariablename.variable_name,
  402. name, prev_name_size)) {
  403. rv = -EFAULT;
  404. goto out;
  405. }
  406. }
  407. if (ns) {
  408. if (put_user(*ns, getnextvariablename.variable_name_size)) {
  409. rv = -EFAULT;
  410. goto out;
  411. }
  412. }
  413. if (vd) {
  414. if (copy_to_user(getnextvariablename.vendor_guid, vd,
  415. sizeof(efi_guid_t)))
  416. rv = -EFAULT;
  417. }
  418. out:
  419. kfree(name);
  420. return rv;
  421. }
  422. static long efi_runtime_get_nexthighmonocount(unsigned long arg)
  423. {
  424. struct efi_getnexthighmonotoniccount __user *getnexthighmonocount_user;
  425. struct efi_getnexthighmonotoniccount getnexthighmonocount;
  426. efi_status_t status;
  427. u32 count;
  428. getnexthighmonocount_user = (struct
  429. efi_getnexthighmonotoniccount __user *)arg;
  430. if (copy_from_user(&getnexthighmonocount,
  431. getnexthighmonocount_user,
  432. sizeof(getnexthighmonocount)))
  433. return -EFAULT;
  434. status = efi.get_next_high_mono_count(
  435. getnexthighmonocount.high_count ? &count : NULL);
  436. if (put_user(status, getnexthighmonocount.status))
  437. return -EFAULT;
  438. if (status != EFI_SUCCESS)
  439. return -EINVAL;
  440. if (getnexthighmonocount.high_count &&
  441. put_user(count, getnexthighmonocount.high_count))
  442. return -EFAULT;
  443. return 0;
  444. }
  445. static long efi_runtime_reset_system(unsigned long arg)
  446. {
  447. struct efi_resetsystem __user *resetsystem_user;
  448. struct efi_resetsystem resetsystem;
  449. void *data = NULL;
  450. resetsystem_user = (struct efi_resetsystem __user *)arg;
  451. if (copy_from_user(&resetsystem, resetsystem_user,
  452. sizeof(resetsystem)))
  453. return -EFAULT;
  454. if (resetsystem.data_size != 0) {
  455. data = memdup_user((void *)resetsystem.data,
  456. resetsystem.data_size);
  457. if (IS_ERR(data))
  458. return PTR_ERR(data);
  459. }
  460. efi.reset_system(resetsystem.reset_type, resetsystem.status,
  461. resetsystem.data_size, (efi_char16_t *)data);
  462. kfree(data);
  463. return 0;
  464. }
  465. static long efi_runtime_query_variableinfo(unsigned long arg)
  466. {
  467. struct efi_queryvariableinfo __user *queryvariableinfo_user;
  468. struct efi_queryvariableinfo queryvariableinfo;
  469. efi_status_t status;
  470. u64 max_storage, remaining, max_size;
  471. queryvariableinfo_user = (struct efi_queryvariableinfo __user *)arg;
  472. if (copy_from_user(&queryvariableinfo, queryvariableinfo_user,
  473. sizeof(queryvariableinfo)))
  474. return -EFAULT;
  475. status = efi.query_variable_info(queryvariableinfo.attributes,
  476. &max_storage, &remaining, &max_size);
  477. if (put_user(status, queryvariableinfo.status))
  478. return -EFAULT;
  479. if (status != EFI_SUCCESS)
  480. return -EINVAL;
  481. if (put_user(max_storage,
  482. queryvariableinfo.maximum_variable_storage_size))
  483. return -EFAULT;
  484. if (put_user(remaining,
  485. queryvariableinfo.remaining_variable_storage_size))
  486. return -EFAULT;
  487. if (put_user(max_size, queryvariableinfo.maximum_variable_size))
  488. return -EFAULT;
  489. return 0;
  490. }
  491. static long efi_runtime_query_capsulecaps(unsigned long arg)
  492. {
  493. struct efi_querycapsulecapabilities __user *qcaps_user;
  494. struct efi_querycapsulecapabilities qcaps;
  495. efi_capsule_header_t *capsules;
  496. efi_status_t status;
  497. u64 max_size;
  498. int i, reset_type;
  499. int rv = 0;
  500. qcaps_user = (struct efi_querycapsulecapabilities __user *)arg;
  501. if (copy_from_user(&qcaps, qcaps_user, sizeof(qcaps)))
  502. return -EFAULT;
  503. if (qcaps.capsule_count == ULONG_MAX)
  504. return -EINVAL;
  505. capsules = kzalloc_objs(efi_capsule_header_t, qcaps.capsule_count + 1);
  506. if (!capsules)
  507. return -ENOMEM;
  508. for (i = 0; i < qcaps.capsule_count; i++) {
  509. efi_capsule_header_t *c;
  510. /*
  511. * We cannot dereference qcaps.capsule_header_array directly to
  512. * obtain the address of the capsule as it resides in the
  513. * user space
  514. */
  515. if (get_user(c, qcaps.capsule_header_array + i)) {
  516. rv = -EFAULT;
  517. goto out;
  518. }
  519. if (copy_from_user(&capsules[i], c,
  520. sizeof(efi_capsule_header_t))) {
  521. rv = -EFAULT;
  522. goto out;
  523. }
  524. }
  525. qcaps.capsule_header_array = &capsules;
  526. status = efi.query_capsule_caps((efi_capsule_header_t **)
  527. qcaps.capsule_header_array,
  528. qcaps.capsule_count,
  529. &max_size, &reset_type);
  530. if (put_user(status, qcaps.status)) {
  531. rv = -EFAULT;
  532. goto out;
  533. }
  534. if (status != EFI_SUCCESS) {
  535. rv = -EINVAL;
  536. goto out;
  537. }
  538. if (put_user(max_size, qcaps.maximum_capsule_size)) {
  539. rv = -EFAULT;
  540. goto out;
  541. }
  542. if (put_user(reset_type, qcaps.reset_type))
  543. rv = -EFAULT;
  544. out:
  545. kfree(capsules);
  546. return rv;
  547. }
  548. static long efi_runtime_get_supported_mask(unsigned long arg)
  549. {
  550. unsigned int __user *supported_mask;
  551. int rv = 0;
  552. supported_mask = (unsigned int *)arg;
  553. if (put_user(efi.runtime_supported_mask, supported_mask))
  554. rv = -EFAULT;
  555. return rv;
  556. }
  557. static long efi_test_ioctl(struct file *file, unsigned int cmd,
  558. unsigned long arg)
  559. {
  560. switch (cmd) {
  561. case EFI_RUNTIME_GET_VARIABLE:
  562. return efi_runtime_get_variable(arg);
  563. case EFI_RUNTIME_SET_VARIABLE:
  564. return efi_runtime_set_variable(arg);
  565. case EFI_RUNTIME_GET_TIME:
  566. return efi_runtime_get_time(arg);
  567. case EFI_RUNTIME_SET_TIME:
  568. return efi_runtime_set_time(arg);
  569. case EFI_RUNTIME_GET_WAKETIME:
  570. return efi_runtime_get_waketime(arg);
  571. case EFI_RUNTIME_SET_WAKETIME:
  572. return efi_runtime_set_waketime(arg);
  573. case EFI_RUNTIME_GET_NEXTVARIABLENAME:
  574. return efi_runtime_get_nextvariablename(arg);
  575. case EFI_RUNTIME_GET_NEXTHIGHMONOTONICCOUNT:
  576. return efi_runtime_get_nexthighmonocount(arg);
  577. case EFI_RUNTIME_QUERY_VARIABLEINFO:
  578. return efi_runtime_query_variableinfo(arg);
  579. case EFI_RUNTIME_QUERY_CAPSULECAPABILITIES:
  580. return efi_runtime_query_capsulecaps(arg);
  581. case EFI_RUNTIME_RESET_SYSTEM:
  582. return efi_runtime_reset_system(arg);
  583. case EFI_RUNTIME_GET_SUPPORTED_MASK:
  584. return efi_runtime_get_supported_mask(arg);
  585. }
  586. return -ENOTTY;
  587. }
  588. static int efi_test_open(struct inode *inode, struct file *file)
  589. {
  590. int ret = security_locked_down(LOCKDOWN_EFI_TEST);
  591. if (ret)
  592. return ret;
  593. if (!capable(CAP_SYS_ADMIN))
  594. return -EACCES;
  595. /*
  596. * nothing special to do here
  597. * We do accept multiple open files at the same time as we
  598. * synchronize on the per call operation.
  599. */
  600. return 0;
  601. }
  602. static int efi_test_close(struct inode *inode, struct file *file)
  603. {
  604. return 0;
  605. }
  606. /*
  607. * The various file operations we support.
  608. */
  609. static const struct file_operations efi_test_fops = {
  610. .owner = THIS_MODULE,
  611. .unlocked_ioctl = efi_test_ioctl,
  612. .open = efi_test_open,
  613. .release = efi_test_close,
  614. };
  615. static struct miscdevice efi_test_dev = {
  616. MISC_DYNAMIC_MINOR,
  617. "efi_test",
  618. &efi_test_fops
  619. };
  620. static int __init efi_test_init(void)
  621. {
  622. int ret;
  623. ret = misc_register(&efi_test_dev);
  624. if (ret) {
  625. pr_err("efi_test: can't misc_register on minor=%d\n",
  626. MISC_DYNAMIC_MINOR);
  627. return ret;
  628. }
  629. return 0;
  630. }
  631. static void __exit efi_test_exit(void)
  632. {
  633. misc_deregister(&efi_test_dev);
  634. }
  635. module_init(efi_test_init);
  636. module_exit(efi_test_exit);