VirtualBox

Changeset 93469 in vbox for trunk


Ignore:
Timestamp:
Jan 27, 2022 9:25:39 PM (3 years ago)
Author:
vboxsync
Message:

Additions: Linux: VBoxDRMClient: make IPC socket access configurable via guest property, bugref:10134.

Guest property '/VirtualBox/GuestAdd/DRMIpcRestricted' when set with RDONLYGUEST
flag is used to restrict DRM IPC server socket access to root and users of 'vboxdrmipc'
group. If property is not set or has no RDONLYGUEST flag, access is granted to all users.

VBoxDRMClient subscribes to guest property update notifications and updates server socket
access mode accordingly in runtime. When switching from unrestricted mode to the restricted
one, all established IPC connections will be kept, new connections will require corresponding
access permissions.

Location:
trunk/src/VBox/Additions/x11/VBoxClient
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk

    r93385 r93469  
    103103 VBoxClient_SOURCES += \
    104104        hostversion.cpp
     105 VBoxDRMClient_DEFS += VBOX_WITH_GUEST_PROPS
    105106endif
    106107
  • trunk/src/VBox/Additions/x11/VBoxClient/display-drm.cpp

    r93423 r93469  
    3838 * back to host, so host and guest will have the same screen layout representation.
    3939 *
     40 * By default, access to IPC server socket is granted to all users. It can be restricted to
     41 * only root and users from group 'vboxdrmipc' if '/VirtualBox/GuestAdd/DRMIpcRestricted' guest
     42 * property is set and READ-ONLY for guest. User group 'vboxdrmipc' is created during Guest
     43 * Additions installation. If this group is removed (or not found due to any reason) prior to
     44 * service start, access to IPC server socket will be granted to root only regardless
     45 * if '/VirtualBox/GuestAdd/DRMIpcRestricted' guest property is set or not. If guest property
     46 * is set, but is not READ-ONLY for guest, property is ignored and IPC socket access is granted
     47 * to all users.
     48 *
    4049 * Logging is implemented in a way that errors are always printed out, VBClLogVerbose(1) and
    4150 * VBClLogVerbose(2) are used for debugging purposes. Verbosity level 1 is for messages related
     
    6675 *
    6776 *
    68  * The following loack are utilized:
     77 * The following locks are utilized:
    6978 *
    7079 * #g_ipcClientConnectionsListCritSect - protects access to list of IPC client connections.
     
    7988
    8089#include <VBox/VBoxGuestLib.h>
     90#include <VBox/HostServices/GuestPropertySvc.h>
    8191
    8292#include <iprt/getopt.h>
     
    133143/** IPC client connections counter. */
    134144static volatile uint32_t g_cDrmIpcConnections = 0;
     145/* A flag which indicates whether access to IPC socket should be restricted.
     146 * This flag caches '/VirtualBox/GuestAdd/DRMIpcRestricted' guest property
     147 * in order to prevent its retrieving from the host side each time a new IPC
     148 * client connects to server. This flag is updated each time when property is
     149 * changed on the host side. */
     150static volatile bool g_fDrmIpcRestricted;
    135151
    136152/** DRM version structure. */
     
    920936            {
    921937                /* Authenticate remote peer. */
    922                 rc = vbDrmIpcAuth(hClientSession);
     938                if (ASMAtomicReadBool(&g_fDrmIpcRestricted))
     939                    rc = vbDrmIpcAuth(hClientSession);
     940
    923941                if (RT_SUCCESS(rc))
    924942                {
     
    970988}
    971989
     990/**
     991 * Grant access to DRM IPC server socket depending on VM configuration.
     992 *
     993 * If VM has '/VirtualBox/GuestAdd/DRMIpcRestricted' guest property set
     994 * and this property is READ-ONLY for the guest side, access will be
     995 * granted to root and users from 'vboxdrmipc' group only. If group does
     996 * not exists, only root will have access to the socket.  When property is
     997 * not set or not READ-ONLY, all users will have access to the socket.
     998 *
     999 * @param   hIpcServer  IPC server handle.
     1000 */
     1001static void vbDrmSetIpcServerAccessPermissions(RTLOCALIPCSERVER hIpcServer)
     1002{
     1003    int rc;
     1004
     1005    ASMAtomicWriteBool(&g_fDrmIpcRestricted, VbglR3DrmRestrictedIpcAccessIsNeeded());
     1006
     1007    if (g_fDrmIpcRestricted)
     1008    {
     1009        struct group *pGrp;
     1010        pGrp = getgrnam(VBOX_DRMIPC_USER_GROUP);
     1011        if (pGrp)
     1012        {
     1013            rc = RTLocalIpcServerGrantGroupAccess(hIpcServer, pGrp->gr_gid);
     1014            if (RT_SUCCESS(rc))
     1015                VBClLogInfo("IPC server socket access granted to '" VBOX_DRMIPC_USER_GROUP "' users\n");
     1016            else
     1017                VBClLogError("unable to grant IPC server socket access to '" VBOX_DRMIPC_USER_GROUP "' users, rc=%Rrc\n", rc);
     1018
     1019        }
     1020        else
     1021            VBClLogError("unable to grant IPC server socket access to '" VBOX_DRMIPC_USER_GROUP "', group does not exist\n");
     1022    }
     1023    else
     1024    {
     1025        rc = RTLocalIpcServerSetAccessMode(hIpcServer,
     1026                                           RTFS_UNIX_IRUSR | RTFS_UNIX_IWUSR |
     1027                                           RTFS_UNIX_IRGRP | RTFS_UNIX_IWGRP |
     1028                                           RTFS_UNIX_IROTH | RTFS_UNIX_IWOTH);
     1029        if (RT_SUCCESS(rc))
     1030            VBClLogInfo("IPC server socket access granted to all users\n");
     1031        else
     1032            VBClLogError("unable to grant IPC server socket access to all users, rc=%Rrc\n", rc);
     1033    }
     1034}
     1035
     1036/**
     1037 * Wait and handle '/VirtualBox/GuestAdd/DRMIpcRestricted' guest property change.
     1038 *
     1039 * This function is executed in context of main().
     1040 *
     1041 * @param   hIpcServer  IPC server handle.
     1042 */
     1043static void vbDrmPollIpcServerAccessMode(RTLOCALIPCSERVER hIpcServer)
     1044{
     1045    HGCMCLIENTID idClient;
     1046    int rc;
     1047
     1048    rc = VbglR3GuestPropConnect(&idClient);
     1049    if (RT_SUCCESS(rc))
     1050    {
     1051        do
     1052        {
     1053            /* Buffer should be big enough to fit guest property data layout: Name\0Value\0Flags\0. */
     1054            static char achBuf[GUEST_PROP_MAX_NAME_LEN];
     1055            uint64_t u64Timestamp = 0;
     1056
     1057            rc = VbglR3GuestPropWait(idClient, VBGLR3DRMIPCPROPRESTRICT, achBuf, sizeof(achBuf), u64Timestamp,
     1058                                     VBOX_DRMIPC_RX_TIMEOUT_MS, NULL, NULL, &u64Timestamp, NULL, NULL);
     1059            if (RT_SUCCESS(rc))
     1060                vbDrmSetIpcServerAccessPermissions(hIpcServer);
     1061            else if (rc != VERR_TIMEOUT)
     1062            {
     1063                VBClLogError("error on waiting guest property notification, rc=%Rrc\n", rc);
     1064                RTThreadSleep(VBOX_DRMIPC_RX_RELAX_MS);
     1065            }
     1066
     1067        } while (!ASMAtomicReadBool(&g_fShutdown));
     1068
     1069        VbglR3GuestPropDisconnect(idClient);
     1070    }
     1071    else
     1072        VBClLogError("cannot connect to VM guest properties service, rc=%Rrc\n", rc);
     1073}
     1074
    9721075int main(int argc, char *argv[])
    9731076{
     
    10931196    }
    10941197
    1095     struct group *pGrp;
    1096     pGrp = getgrnam(VBOX_DRMIPC_USER_GROUP);
    1097     if (pGrp)
    1098     {
    1099         rc = RTLocalIpcServerGrantGroupAccess(hIpcServer, pGrp->gr_gid);
    1100         if (RT_FAILURE(rc))
    1101             VBClLogError("unable to grant IPC server socket access to '" VBOX_DRMIPC_USER_GROUP "', rc=%Rrc\n", rc);
    1102     }
    1103     else
    1104         VBClLogError("unable to grant IPC server socket access to '" VBOX_DRMIPC_USER_GROUP "', group does not exist\n");
     1198    /* Set IPC server socket access permissions according to VM configuration. */
     1199    vbDrmSetIpcServerAccessPermissions(hIpcServer);
    11051200
    11061201    /* Attempt to start DRM resize task. */
     
    11141209        if (RT_SUCCESS(rc))
    11151210        {
     1211            /* Poll for host notification about IPC server socket access mode change. */
     1212            vbDrmPollIpcServerAccessMode(hIpcServer);
     1213
    11161214            /* HACK ALERT!
    11171215             * The sequence of RTThreadWait(drmResizeThread) -> RTLocalIpcServerDestroy() -> RTThreadWait(vbDrmIpcThread)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette