security_stack.c 24.9 KB
Newer Older
1
/*
2
 * Copyright (C) 2010-2014 Red Hat, Inc.
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library.  If not, see
O
Osier Yang 已提交
16
 * <http://www.gnu.org/licenses/>.
17 18 19 20 21 22 23 24
 *
 * Stacked security driver
 */

#include <config.h>

#include "security_stack.h"

25
#include "virerror.h"
26
#include "viralloc.h"
27 28 29 30 31

#define VIR_FROM_THIS VIR_FROM_SECURITY

typedef struct _virSecurityStackData virSecurityStackData;
typedef virSecurityStackData *virSecurityStackDataPtr;
32
typedef struct _virSecurityStackItem virSecurityStackItem;
33
typedef virSecurityStackItem *virSecurityStackItemPtr;
34 35 36 37

struct _virSecurityStackItem {
    virSecurityManagerPtr securityManager;
    virSecurityStackItemPtr next;
38
    virSecurityStackItemPtr prev;
39
};
40 41

struct _virSecurityStackData {
42
    virSecurityStackItemPtr itemsHead;
43 44
};

45 46 47 48 49 50
int
virSecurityStackAddNested(virSecurityManagerPtr mgr,
                          virSecurityManagerPtr nested)
{
    virSecurityStackItemPtr item = NULL;
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
51 52 53 54 55
    virSecurityStackItemPtr tmp;

    tmp = priv->itemsHead;
    while (tmp && tmp->next)
        tmp = tmp->next;
56

57
    if (VIR_ALLOC(item) < 0)
58 59
        return -1;
    item->securityManager = nested;
60
    item->prev = tmp;
61 62 63 64 65
    if (tmp)
        tmp->next = item;
    else
        priv->itemsHead = item;

66 67 68 69 70 71 72
    return 0;
}

virSecurityManagerPtr
virSecurityStackGetPrimary(virSecurityManagerPtr mgr)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
73
    return priv->itemsHead->securityManager;
74 75 76
}

static virSecurityDriverStatus
77
virSecurityStackProbe(const char *virtDriver ATTRIBUTE_UNUSED)
78 79 80 81 82 83 84 85 86 87 88
{
    return SECURITY_DRIVER_ENABLE;
}

static int
virSecurityStackOpen(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED)
{
    return 0;
}

static int
E
Eric Blake 已提交
89
virSecurityStackClose(virSecurityManagerPtr mgr)
90
{
E
Eric Blake 已提交
91
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
92
    virSecurityStackItemPtr next, item = priv->itemsHead;
E
Eric Blake 已提交
93

94 95
    while (item) {
        next = item->next;
96
        virObjectUnref(item->securityManager);
97 98 99
        VIR_FREE(item);
        item = next;
    }
E
Eric Blake 已提交
100

101 102 103 104 105 106
    return 0;
}

static const char *
virSecurityStackGetModel(virSecurityManagerPtr mgr)
{
107
    return virSecurityManagerGetModel(virSecurityStackGetPrimary(mgr));
108 109 110 111 112
}

static const char *
virSecurityStackGetDOI(virSecurityManagerPtr mgr)
{
113
    return virSecurityManagerGetDOI(virSecurityStackGetPrimary(mgr));
114 115
}

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
static int
virSecurityStackPreFork(virSecurityManagerPtr mgr)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    /* XXX For now, we rely on no driver having any state that requires
     * rollback if a later driver in the stack fails; if this changes,
     * we'd need to split this into transaction semantics by dividing
     * the work into prepare/commit/abort.  */
    for (; item; item = item->next) {
        if (virSecurityManagerPreFork(item->securityManager) < 0) {
            rc = -1;
            break;
        }
E
Eric Blake 已提交
132 133 134 135 136
        /* Undo the unbalanced locking left behind after recursion; if
         * PostFork ever delegates to driver callbacks, we'd instead
         * need to recurse to an internal method that does not regrab
         * a lock. */
        virSecurityManagerPostFork(item->securityManager);
137 138 139 140 141
    }

    return rc;
}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

static int
virSecurityStackTransactionStart(virSecurityManagerPtr mgr)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerTransactionStart(item->securityManager) < 0)
            rc = -1;
    }

    return rc;
}


static int
virSecurityStackTransactionCommit(virSecurityManagerPtr mgr,
161 162
                                  pid_t pid,
                                  bool lock)
163 164 165 166 167 168
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
169
        if (virSecurityManagerTransactionCommit(item->securityManager, pid, lock) < 0)
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
            rc = -1;
    }

    return rc;
}


static void
virSecurityStackTransactionAbort(virSecurityManagerPtr mgr)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;

    for (; item; item = item->next)
        virSecurityManagerTransactionAbort(item->securityManager);
}


188 189 190 191 192
static int
virSecurityStackVerify(virSecurityManagerPtr mgr,
                       virDomainDefPtr def)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
193
    virSecurityStackItemPtr item = priv->itemsHead;
194 195
    int rc = 0;

196
    for (; item; item = item->next) {
197 198 199 200 201
        if (virSecurityManagerVerify(item->securityManager, def) < 0) {
            rc = -1;
            break;
        }
    }
202 203 204 205 206 207 208

    return rc;
}


static int
virSecurityStackGenLabel(virSecurityManagerPtr mgr,
209
                         virDomainDefPtr vm)
210 211 212
{
    int rc = 0;

213
    if (virSecurityManagerGenLabel(virSecurityStackGetPrimary(mgr), vm) < 0)
214 215
        rc = -1;

M
Michal Privoznik 已提交
216
/* TODO */
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
#if 0
    /* We don't allow secondary drivers to generate labels.
     * This may have to change in the future, but requires
     * changes elsewhere in domain_conf.c and capabilities.c
     * XML formats first, to allow recording of multiple
     * labels
     */
    if (virSecurityManagerGenLabel(priv->secondary, vm) < 0)
        rc = -1;
#endif

    return rc;
}


static int
virSecurityStackReleaseLabel(virSecurityManagerPtr mgr,
234
                             virDomainDefPtr vm)
235 236 237
{
    int rc = 0;

238
    if (virSecurityManagerReleaseLabel(virSecurityStackGetPrimary(mgr), vm) < 0)
239
        rc = -1;
240

M
Michal Privoznik 已提交
241
/* TODO */
242 243 244 245 246 247 248 249 250 251 252 253
#if 0
    /* XXX See note in GenLabel */
    if (virSecurityManagerReleaseLabel(priv->secondary, vm) < 0)
        rc = -1;
#endif

    return rc;
}


static int
virSecurityStackReserveLabel(virSecurityManagerPtr mgr,
254 255
                             virDomainDefPtr vm,
                             pid_t pid)
256 257 258
{
    int rc = 0;

259
    if (virSecurityManagerReserveLabel(virSecurityStackGetPrimary(mgr), vm, pid) < 0)
260
        rc = -1;
M
Michal Privoznik 已提交
261
/* TODO */
262 263
#if 0
    /* XXX See note in GenLabel */
264
    if (virSecurityManagerReserveLabel(priv->secondary, vm, pid) < 0)
265 266 267 268 269 270 271 272
        rc = -1;
#endif

    return rc;
}


static int
273 274 275 276
virSecurityStackSetHostdevLabel(virSecurityManagerPtr mgr,
                                virDomainDefPtr vm,
                                virDomainHostdevDefPtr dev,
                                const char *vroot)
277 278 279

{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
280
    virSecurityStackItemPtr item = priv->itemsHead;
281 282
    int rc = 0;

283
    for (; item; item = item->next) {
284 285 286 287
        if (virSecurityManagerSetHostdevLabel(item->securityManager,
                                              vm,
                                              dev,
                                              vroot) < 0)
288 289
            rc = -1;
    }
290 291 292 293 294 295

    return rc;
}


static int
296 297 298 299
virSecurityStackRestoreHostdevLabel(virSecurityManagerPtr mgr,
                                    virDomainDefPtr vm,
                                    virDomainHostdevDefPtr dev,
                                    const char *vroot)
300 301
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
302
    virSecurityStackItemPtr item = priv->itemsHead;
303 304
    int rc = 0;

305
    for (; item; item = item->next) {
306 307 308 309
        if (virSecurityManagerRestoreHostdevLabel(item->securityManager,
                                                  vm,
                                                  dev,
                                                  vroot) < 0)
310 311
            rc = -1;
    }
312 313 314 315 316 317

    return rc;
}


static int
318 319
virSecurityStackSetAllLabel(virSecurityManagerPtr mgr,
                            virDomainDefPtr vm,
320
                            const char *stdin_path,
321 322
                            bool chardevStdioLogd,
                            bool migrated)
323 324
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
325
    virSecurityStackItemPtr item = priv->itemsHead;
326 327
    int rc = 0;

328
    for (; item; item = item->next) {
329
        if (virSecurityManagerSetAllLabel(item->securityManager, vm,
330 331
                                          stdin_path, chardevStdioLogd,
                                          migrated) < 0)
332 333
            rc = -1;
    }
334 335 336 337 338 339

    return rc;
}


static int
340 341
virSecurityStackRestoreAllLabel(virSecurityManagerPtr mgr,
                                virDomainDefPtr vm,
342 343
                                bool migrated,
                                bool chardevStdioLogd)
344 345
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
346
    virSecurityStackItemPtr item = priv->itemsHead;
347 348
    int rc = 0;

349
    for (; item; item = item->next) {
350 351
        if (virSecurityManagerRestoreAllLabel(item->securityManager, vm,
                                              migrated, chardevStdioLogd) < 0)
352 353
            rc = -1;
    }
354 355 356 357 358 359 360

    return rc;
}


static int
virSecurityStackSetSavedStateLabel(virSecurityManagerPtr mgr,
361
                                   virDomainDefPtr vm,
362 363 364
                                   const char *savefile)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
365
    virSecurityStackItemPtr item = priv->itemsHead;
366 367
    int rc = 0;

368 369 370 371
    for (; item; item = item->next) {
        if (virSecurityManagerSetSavedStateLabel(item->securityManager, vm, savefile) < 0)
            rc = -1;
    }
372 373 374 375 376 377 378

    return rc;
}


static int
virSecurityStackRestoreSavedStateLabel(virSecurityManagerPtr mgr,
379
                                       virDomainDefPtr vm,
380 381 382
                                       const char *savefile)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
383
    virSecurityStackItemPtr item = priv->itemsHead;
384 385
    int rc = 0;

386 387 388 389
    for (; item; item = item->next) {
        if (virSecurityManagerRestoreSavedStateLabel(item->securityManager, vm, savefile) < 0)
            rc = -1;
    }
390 391 392 393 394 395 396

    return rc;
}


static int
virSecurityStackSetProcessLabel(virSecurityManagerPtr mgr,
397
                                virDomainDefPtr vm)
398 399
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
400
    virSecurityStackItemPtr item = priv->itemsHead;
401 402
    int rc = 0;

403 404 405 406
    for (; item; item = item->next) {
        if (virSecurityManagerSetProcessLabel(item->securityManager, vm) < 0)
            rc = -1;
    }
407 408 409 410

    return rc;
}

411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
static int
virSecurityStackSetChildProcessLabel(virSecurityManagerPtr mgr,
                                     virDomainDefPtr vm,
                                     virCommandPtr cmd)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerSetChildProcessLabel(item->securityManager, vm, cmd) < 0)
            rc = -1;
    }

    return rc;
}

428 429
static int
virSecurityStackGetProcessLabel(virSecurityManagerPtr mgr,
430 431
                                virDomainDefPtr vm,
                                pid_t pid,
432 433 434 435
                                virSecurityLabelPtr seclabel)
{
    int rc = 0;

M
Michal Privoznik 已提交
436
/* TODO */
437
#if 0
438
    if (virSecurityManagerGetProcessLabel(priv->secondary, vm, pid, seclabel) < 0)
439 440
        rc = -1;
#endif
441
    if (virSecurityManagerGetProcessLabel(virSecurityStackGetPrimary(mgr), vm, pid, seclabel) < 0)
442 443 444 445 446 447 448
        rc = -1;

    return rc;
}


static int
449
virSecurityStackSetDaemonSocketLabel(virSecurityManagerPtr mgr,
450
                                     virDomainDefPtr vm)
451 452
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
453
    virSecurityStackItemPtr item = priv->itemsHead;
454 455
    int rc = 0;

456 457 458 459
    for (; item; item = item->next) {
        if (virSecurityManagerSetDaemonSocketLabel(item->securityManager, vm) < 0)
            rc = -1;
    }
460 461 462 463 464

    return rc;
}


465 466
static int
virSecurityStackSetSocketLabel(virSecurityManagerPtr mgr,
467
                               virDomainDefPtr vm)
468 469
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
470
    virSecurityStackItemPtr item = priv->itemsHead;
471 472
    int rc = 0;

473 474 475 476
    for (; item; item = item->next) {
        if (virSecurityManagerSetSocketLabel(item->securityManager, vm) < 0)
            rc = -1;
    }
477 478 479 480 481

    return rc;
}


482 483
static int
virSecurityStackClearSocketLabel(virSecurityManagerPtr mgr,
484
                                 virDomainDefPtr vm)
485 486
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
487
    virSecurityStackItemPtr item = priv->itemsHead;
488 489
    int rc = 0;

490 491 492 493
    for (; item; item = item->next) {
        if (virSecurityManagerClearSocketLabel(item->securityManager, vm) < 0)
            rc = -1;
    }
494 495 496 497

    return rc;
}

498
static int
499
virSecurityStackSetImageFDLabel(virSecurityManagerPtr mgr,
500
                                virDomainDefPtr vm,
501
                                int fd)
502 503
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
504
    virSecurityStackItemPtr item = priv->itemsHead;
505 506
    int rc = 0;

507 508 509 510
    for (; item; item = item->next) {
        if (virSecurityManagerSetImageFDLabel(item->securityManager, vm, fd) < 0)
            rc = -1;
    }
511 512 513 514

    return rc;
}

515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
static int
virSecurityStackSetTapFDLabel(virSecurityManagerPtr mgr,
                              virDomainDefPtr vm,
                              int fd)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerSetTapFDLabel(item->securityManager, vm, fd) < 0)
            rc = -1;
    }

    return rc;
}

532 533 534 535
static char *
virSecurityStackGetMountOptions(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
                                virDomainDefPtr vm ATTRIBUTE_UNUSED)
{
536 537
    return NULL;
}
538

539 540 541 542 543 544
virSecurityManagerPtr*
virSecurityStackGetNested(virSecurityManagerPtr mgr)
{
    virSecurityManagerPtr *list = NULL;
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item;
545 546
    int len = 0;
    size_t i;
547 548 549 550

    for (item = priv->itemsHead; item; item = item->next)
        len++;

551
    if (VIR_ALLOC_N(list, len + 1) < 0)
552 553
        return NULL;

554
    for (i = 0, item = priv->itemsHead; item; item = item->next, i++)
555 556 557 558 559 560
        list[i] = item->securityManager;
    list[len] = NULL;

    return list;
}

561 562 563 564 565 566 567
static const char *
virSecurityStackGetBaseLabel(virSecurityManagerPtr mgr, int virtType)
{
    return virSecurityManagerGetBaseLabel(virSecurityStackGetPrimary(mgr),
                                          virtType);
}

568
static int
569 570
virSecurityStackSetImageLabel(virSecurityManagerPtr mgr,
                              virDomainDefPtr vm,
571 572
                              virStorageSourcePtr src,
                              virSecurityDomainImageLabelFlags flags)
573 574 575 576 577 578
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
579 580
        if (virSecurityManagerSetImageLabel(item->securityManager, vm, src,
                                            flags) < 0)
581 582 583 584 585 586 587
            rc = -1;
    }

    return rc;
}

static int
588 589
virSecurityStackRestoreImageLabel(virSecurityManagerPtr mgr,
                                  virDomainDefPtr vm,
590 591
                                  virStorageSourcePtr src,
                                  virSecurityDomainImageLabelFlags flags)
592 593 594 595 596 597 598
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerRestoreImageLabel(item->securityManager,
599
                                                vm, src, flags) < 0)
600 601 602 603 604 605
            rc = -1;
    }

    return rc;
}

606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
static int
virSecurityStackMoveImageMetadata(virSecurityManagerPtr mgr,
                                  pid_t pid,
                                  virStorageSourcePtr src,
                                  virStorageSourcePtr dst)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerMoveImageMetadata(item->securityManager,
                                                pid, src, dst) < 0)
            rc = -1;
    }

    return rc;
}

625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
static int
virSecurityStackSetMemoryLabel(virSecurityManagerPtr mgr,
                               virDomainDefPtr vm,
                               virDomainMemoryDefPtr mem)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerSetMemoryLabel(item->securityManager, vm, mem) < 0)
            rc = -1;
    }

    return rc;
}

static int
virSecurityStackRestoreMemoryLabel(virSecurityManagerPtr mgr,
                                   virDomainDefPtr vm,
                                   virDomainMemoryDefPtr mem)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerRestoreMemoryLabel(item->securityManager,
                                                 vm, mem) < 0)
            rc = -1;
    }

    return rc;
}

660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
static int
virSecurityStackSetInputLabel(virSecurityManagerPtr mgr,
                              virDomainDefPtr vm,
                              virDomainInputDefPtr input)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerSetInputLabel(item->securityManager, vm, input) < 0)
            rc = -1;
    }

    return rc;
}

static int
virSecurityStackRestoreInputLabel(virSecurityManagerPtr mgr,
                                  virDomainDefPtr vm,
                                  virDomainInputDefPtr input)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerRestoreInputLabel(item->securityManager,
                                                vm, input) < 0)
            rc = -1;
    }

    return rc;
}

695
static int
696 697
virSecurityStackDomainSetPathLabel(virSecurityManagerPtr mgr,
                                   virDomainDefPtr vm,
698 699
                                   const char *path,
                                   bool allowSubtree)
700 701 702 703 704 705
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
706
        if (virSecurityManagerDomainSetPathLabel(item->securityManager,
707
                                                 vm, path, allowSubtree) < 0)
708 709 710 711 712 713
            rc = -1;
    }

    return rc;
}

714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
static int
virSecurityStackDomainSetChardevLabel(virSecurityManagerPtr mgr,
                                      virDomainDefPtr def,
                                      virDomainChrSourceDefPtr dev_source,
                                      bool chardevStdioLogd)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerSetChardevLabel(item->securityManager,
                                              def, dev_source,
                                              chardevStdioLogd) < 0)
            rc = -1;
    }

    return rc;
}

static int
virSecurityStackDomainRestoreChardevLabel(virSecurityManagerPtr mgr,
                                          virDomainDefPtr def,
                                          virDomainChrSourceDefPtr dev_source,
                                          bool chardevStdioLogd)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerRestoreChardevLabel(item->securityManager,
                                                  def, dev_source,
                                                  chardevStdioLogd) < 0)
            rc = -1;
    }

    return rc;
}

754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790

static int
virSecurityStackSetTPMLabels(virSecurityManagerPtr mgr,
                             virDomainDefPtr vm)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerSetTPMLabels(item->securityManager,
                                           vm) < 0)
            rc = -1;
    }

    return rc;
}


static int
virSecurityStackRestoreTPMLabels(virSecurityManagerPtr mgr,
                                 virDomainDefPtr vm)
{
    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
    virSecurityStackItemPtr item = priv->itemsHead;
    int rc = 0;

    for (; item; item = item->next) {
        if (virSecurityManagerRestoreTPMLabels(item->securityManager,
                                               vm) < 0)
            rc = -1;
    }

    return rc;
}


791
virSecurityDriver virSecurityDriverStack = {
792 793 794 795 796
    .privateDataLen                     = sizeof(virSecurityStackData),
    .name                               = "stack",
    .probe                              = virSecurityStackProbe,
    .open                               = virSecurityStackOpen,
    .close                              = virSecurityStackClose,
797

798 799
    .getModel                           = virSecurityStackGetModel,
    .getDOI                             = virSecurityStackGetDOI,
800

801 802
    .preFork                            = virSecurityStackPreFork,

803 804 805 806
    .transactionStart                   = virSecurityStackTransactionStart,
    .transactionCommit                  = virSecurityStackTransactionCommit,
    .transactionAbort                   = virSecurityStackTransactionAbort,

807
    .domainSecurityVerify               = virSecurityStackVerify,
808

809 810
    .domainSetSecurityImageLabel        = virSecurityStackSetImageLabel,
    .domainRestoreSecurityImageLabel    = virSecurityStackRestoreImageLabel,
811
    .domainMoveImageMetadata            = virSecurityStackMoveImageMetadata,
812

813 814 815
    .domainSetSecurityMemoryLabel       = virSecurityStackSetMemoryLabel,
    .domainRestoreSecurityMemoryLabel   = virSecurityStackRestoreMemoryLabel,

816 817 818
    .domainSetSecurityInputLabel        = virSecurityStackSetInputLabel,
    .domainRestoreSecurityInputLabel    = virSecurityStackRestoreInputLabel,

819 820 821
    .domainSetSecurityDaemonSocketLabel = virSecurityStackSetDaemonSocketLabel,
    .domainSetSecuritySocketLabel       = virSecurityStackSetSocketLabel,
    .domainClearSecuritySocketLabel     = virSecurityStackClearSocketLabel,
822

823 824 825
    .domainGenSecurityLabel             = virSecurityStackGenLabel,
    .domainReserveSecurityLabel         = virSecurityStackReserveLabel,
    .domainReleaseSecurityLabel         = virSecurityStackReleaseLabel,
826

827 828
    .domainGetSecurityProcessLabel      = virSecurityStackGetProcessLabel,
    .domainSetSecurityProcessLabel      = virSecurityStackSetProcessLabel,
829
    .domainSetSecurityChildProcessLabel = virSecurityStackSetChildProcessLabel,
830

831 832
    .domainSetSecurityAllLabel          = virSecurityStackSetAllLabel,
    .domainRestoreSecurityAllLabel      = virSecurityStackRestoreAllLabel,
833

834 835
    .domainSetSecurityHostdevLabel      = virSecurityStackSetHostdevLabel,
    .domainRestoreSecurityHostdevLabel  = virSecurityStackRestoreHostdevLabel,
836

837 838
    .domainSetSavedStateLabel           = virSecurityStackSetSavedStateLabel,
    .domainRestoreSavedStateLabel       = virSecurityStackRestoreSavedStateLabel,
839

840
    .domainSetSecurityImageFDLabel      = virSecurityStackSetImageFDLabel,
841
    .domainSetSecurityTapFDLabel        = virSecurityStackSetTapFDLabel,
842

843
    .domainGetSecurityMountOptions      = virSecurityStackGetMountOptions,
844

845
    .getBaseLabel                       = virSecurityStackGetBaseLabel,
846

847
    .domainSetPathLabel                 = virSecurityStackDomainSetPathLabel,
848 849 850

    .domainSetSecurityChardevLabel      = virSecurityStackDomainSetChardevLabel,
    .domainRestoreSecurityChardevLabel  = virSecurityStackDomainRestoreChardevLabel,
851 852 853

    .domainSetSecurityTPMLabels         = virSecurityStackSetTPMLabels,
    .domainRestoreSecurityTPMLabels     = virSecurityStackRestoreTPMLabels,
854
};