|
@@ -36,12 +36,28 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
36
|
36
|
*
|
37
|
37
|
*/
|
38
|
38
|
|
|
39
|
+/* Disambiguate the various error causes */
|
|
40
|
+#define EACCES_UNTRUSTED \
|
|
41
|
+ __einfo_error ( EINFO_EACCES_UNTRUSTED )
|
|
42
|
+#define EINFO_EACCES_UNTRUSTED \
|
|
43
|
+ __einfo_uniqify ( EINFO_EACCES, 0x01, "Untrusted image" )
|
|
44
|
+#define EACCES_PERMANENT \
|
|
45
|
+ __einfo_error ( EINFO_EACCES_PERMANENT )
|
|
46
|
+#define EINFO_EACCES_PERMANENT \
|
|
47
|
+ __einfo_uniqify ( EINFO_EACCES, 0x02, "Trust requirement is permanent" )
|
|
48
|
+
|
39
|
49
|
/** List of registered images */
|
40
|
50
|
struct list_head images = LIST_HEAD_INIT ( images );
|
41
|
51
|
|
42
|
52
|
/** Currently-executing image */
|
43
|
53
|
struct image *current_image;
|
44
|
54
|
|
|
55
|
+/** Current image trust requirement */
|
|
56
|
+static int require_trusted_images = 0;
|
|
57
|
+
|
|
58
|
+/** Prevent changes to image trust requirement */
|
|
59
|
+static int require_trusted_images_permanent = 0;
|
|
60
|
+
|
45
|
61
|
/**
|
46
|
62
|
* Free executable image
|
47
|
63
|
*
|
|
@@ -228,6 +244,12 @@ int image_exec ( struct image *image ) {
|
228
|
244
|
if ( ( rc = image_select ( image ) ) != 0 )
|
229
|
245
|
return rc;
|
230
|
246
|
|
|
247
|
+ /* Check that image is trusted (if applicable) */
|
|
248
|
+ if ( require_trusted_images && ! ( image->flags & IMAGE_TRUSTED ) ) {
|
|
249
|
+ DBGC ( image, "IMAGE %s is not trusted\n", image->name );
|
|
250
|
+ return -EACCES_UNTRUSTED;
|
|
251
|
+ }
|
|
252
|
+
|
231
|
253
|
/* Switch current working directory to be that of the image itself */
|
232
|
254
|
old_cwuri = uri_get ( cwuri );
|
233
|
255
|
churi ( image->uri );
|
|
@@ -355,3 +377,27 @@ struct image * image_find_selected ( void ) {
|
355
|
377
|
}
|
356
|
378
|
return NULL;
|
357
|
379
|
}
|
|
380
|
+
|
|
381
|
+/**
|
|
382
|
+ * Change image trust requirement
|
|
383
|
+ *
|
|
384
|
+ * @v require_trusted Require trusted images
|
|
385
|
+ * @v permanent Make trust requirement permanent
|
|
386
|
+ * @ret rc Return status code
|
|
387
|
+ */
|
|
388
|
+int image_set_trust ( int require_trusted, int permanent ) {
|
|
389
|
+
|
|
390
|
+ /* Update trust requirement, if permitted to do so */
|
|
391
|
+ if ( ! require_trusted_images_permanent ) {
|
|
392
|
+ require_trusted_images = require_trusted;
|
|
393
|
+ require_trusted_images_permanent = permanent;
|
|
394
|
+ }
|
|
395
|
+
|
|
396
|
+ /* Fail if we attempted to change the trust requirement but
|
|
397
|
+ * were not permitted to do so.
|
|
398
|
+ */
|
|
399
|
+ if ( require_trusted_images != require_trusted )
|
|
400
|
+ return -EACCES_PERMANENT;
|
|
401
|
+
|
|
402
|
+ return 0;
|
|
403
|
+}
|