Changeset 18361 in vbox for trunk/src/VBox/Additions/linux/module/vboxmod.c
- Timestamp:
- Mar 26, 2009 11:47:51 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/module/vboxmod.c
r18352 r18361 939 939 /** 940 940 * IOCTL handler for vboxuser 941 * @todo currently this is just a copy of vboxadd_ioctl. We should 942 * decide if we wish to restrict this. If we do, we should remove 943 * the more general ioctls (HGCM call, VMM device request) and 944 * replace them with specific ones. If not, then we should just 945 * make vboxadd world readable and writable or something. 941 946 */ 942 947 static int vboxuser_ioctl(struct inode *inode, struct file *filp, … … 946 951 947 952 /* Deal with variable size ioctls first. */ 948 if ( VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_HGCM_CALL(0)) 953 #ifdef DEBUG /* Only allow random user applications to spam the log in 954 * debug additions builds */ 955 if ( VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_LOG(0)) 956 == VBOXGUEST_IOCTL_STRIP_SIZE(cmd)) 957 { 958 char *pszMessage; 959 960 IOCTL_LOG_ENTRY(arg); 961 pszMessage = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL); 962 if (NULL == pszMessage) 963 { 964 LogRelFunc(("VBOXGUEST_IOCTL_LOG: cannot allocate %d bytes of memory!\n", 965 _IOC_SIZE(cmd))); 966 rc = -ENOMEM; 967 } 968 if ( (0 == rc) 969 && copy_from_user(pszMessage, (void*)arg, _IOC_SIZE(cmd))) 970 { 971 LogRelFunc(("VBOXGUEST_IOCTL_LOG: copy_from_user failed!\n")); 972 rc = -EFAULT; 973 } 974 if (0 == rc) 975 { 976 Log(("%.*s", _IOC_SIZE(cmd), pszMessage)); 977 } 978 if (NULL != pszMessage) 979 { 980 kfree(pszMessage); 981 } 982 IOCTL_LOG_EXIT(arg); 983 } 984 else 985 #endif 986 if ( VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_VMMREQUEST(0)) 987 == VBOXGUEST_IOCTL_STRIP_SIZE(cmd)) 988 { 989 VMMDevRequestHeader reqHeader; 990 VMMDevRequestHeader *reqFull = NULL; 991 size_t cbRequestSize; 992 size_t cbVanillaRequestSize; 993 994 IOCTL_VMM_ENTRY(arg); 995 if (copy_from_user(&reqHeader, (void*)arg, sizeof(reqHeader))) 996 { 997 LogRelFunc(("VBOXGUEST_IOCTL_VMMREQUEST: copy_from_user failed for vmm request!\n")); 998 rc = -EFAULT; 999 } 1000 if (0 == rc) 1001 { 1002 /* get the request size */ 1003 cbVanillaRequestSize = vmmdevGetRequestSize(reqHeader.requestType); 1004 if (!cbVanillaRequestSize) 1005 { 1006 LogRelFunc(("VBOXGUEST_IOCTL_VMMREQUEST: invalid request type: %d\n", 1007 reqHeader.requestType)); 1008 rc = -EINVAL; 1009 } 1010 } 1011 if (0 == rc) 1012 { 1013 cbRequestSize = reqHeader.size; 1014 if (cbRequestSize < cbVanillaRequestSize) 1015 { 1016 LogRelFunc(("VBOXGUEST_IOCTL_VMMREQUEST: invalid request size: %d min: %d type: %d\n", 1017 cbRequestSize, 1018 cbVanillaRequestSize, 1019 reqHeader.requestType)); 1020 rc = -EINVAL; 1021 } 1022 } 1023 if (0 == rc) 1024 { 1025 /* request storage for the full request */ 1026 rc = VbglGRAlloc(&reqFull, cbRequestSize, reqHeader.requestType); 1027 if (RT_FAILURE(rc)) 1028 { 1029 LogRelFunc(("VBOXGUEST_IOCTL_VMMREQUEST: could not allocate request structure! rc = %d\n", rc)); 1030 rc = -EFAULT; 1031 } 1032 } 1033 if (0 == rc) 1034 { 1035 /* now get the full request */ 1036 if (copy_from_user(reqFull, (void*)arg, cbRequestSize)) 1037 { 1038 LogRelFunc(("VBOXGUEST_IOCTL_VMMREQUEST: failed to fetch full request from user space!\n")); 1039 rc = -EFAULT; 1040 } 1041 } 1042 1043 /* now issue the request */ 1044 if (0 == rc) 1045 { 1046 int rrc = VbglGRPerform(reqFull); 1047 1048 /* asynchronous processing? */ 1049 if (rrc == VINF_HGCM_ASYNC_EXECUTE) 1050 { 1051 VMMDevHGCMRequestHeader *reqHGCM = (VMMDevHGCMRequestHeader*)reqFull; 1052 wait_event_interruptible (vboxDev->eventq, reqHGCM->fu32Flags & VBOX_HGCM_REQ_DONE); 1053 rrc = reqFull->rc; 1054 } 1055 1056 /* failed? */ 1057 if (RT_FAILURE(rrc) || RT_FAILURE(reqFull->rc)) 1058 { 1059 LogRelFunc(("VBOXGUEST_IOCTL_VMMREQUEST: request execution failed!\n")); 1060 rc = RT_FAILURE(rrc) ? -RTErrConvertToErrno(rrc) 1061 : -RTErrConvertToErrno(reqFull->rc); 1062 } 1063 else 1064 { 1065 /* success, copy the result data to user space */ 1066 if (copy_to_user((void*)arg, (void*)reqFull, cbRequestSize)) 1067 { 1068 LogRelFunc(("VBOXGUEST_IOCTL_VMMREQUEST: error copying request result to user space!\n")); 1069 rc = -EFAULT; 1070 } 1071 } 1072 } 1073 if (NULL != reqFull) 1074 VbglGRFree(reqFull); 1075 IOCTL_VMM_EXIT(arg); 1076 } 1077 else if ( VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_HGCM_CALL(0)) 949 1078 == VBOXGUEST_IOCTL_STRIP_SIZE(cmd)) 950 1079 { … … 966 1095 switch (cmd) 967 1096 { 1097 case VBOXGUEST_IOCTL_WAITEVENT: 1098 IOCTL_ENTRY("VBOXGUEST_IOCTL_WAITEVENT", arg); 1099 rc = vboxadd_wait_event((void *) arg); 1100 IOCTL_EXIT("VBOXGUEST_IOCTL_WAITEVENT", arg); 1101 break; 1102 case VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS: 1103 IOCTL_ENTRY("VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS", arg); 1104 ++vboxDev->u32GuestInterruptions; 1105 IOCTL_EXIT("VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS", arg); 1106 break; 968 1107 case VBOXGUEST_IOCTL_HGCM_CONNECT: 969 1108 IOCTL_ENTRY("VBOXGUEST_IOCTL_HGCM_CONNECT", arg); … … 976 1115 IOCTL_EXIT("VBOXGUEST_IOCTL_HGCM_DISCONNECT", arg); 977 1116 break; 1117 case VBOXGUEST_IOCTL_CTL_FILTER_MASK: 1118 { 1119 VBoxGuestFilterMaskInfo info; 1120 IOCTL_ENTRY("VBOXGUEST_IOCTL_CTL_FILTER_MASK", arg); 1121 if (copy_from_user((void*)&info, (void*)arg, sizeof(info))) 1122 { 1123 LogRelFunc(("VBOXGUEST_IOCTL_CTL_FILTER_MASK: error getting parameters from user space!\n")); 1124 rc = -EFAULT; 1125 break; 1126 } 1127 rc = -RTErrConvertToErrno(vboxadd_control_filter_mask(&info)); 1128 IOCTL_EXIT("VBOXGUEST_IOCTL_CTL_FILTER_MASK", arg); 1129 break; 1130 } 978 1131 default: 979 1132 LogRelFunc(("unknown command: %x\n", cmd));
Note:
See TracChangeset
for help on using the changeset viewer.