mirror of
https://github.com/openharmony/drivers_adapter_khdf_linux.git
synced 2026-07-19 16:43:55 -04:00
!266 [master][drivers_adapter_khdf_linux] fix usb security verification
Merge pull request !266 from wuzhimin/master
This commit is contained in:
+2844
-2789
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
||||
* Utility definitions for "OS Descriptors" support
|
||||
*
|
||||
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
|
||||
* http://www.samsung.com
|
||||
* http://www.samsung.com
|
||||
*
|
||||
* Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
|
||||
*/
|
||||
@@ -16,106 +16,106 @@
|
||||
#include <asm/unaligned.h>
|
||||
#include <linux/nls.h>
|
||||
#include "securec.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
#define USB_EXT_PROP_DW_SIZE 0
|
||||
#define USB_EXT_PROP_DW_PROPERTY_DATA_TYPE 4
|
||||
#define USB_EXT_PROP_W_PROPERTY_NAME_LENGTH 8
|
||||
#define USB_EXT_PROP_B_PROPERTY_NAME 10
|
||||
#define USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH 10
|
||||
#define USB_EXT_PROP_B_PROPERTY_DATA 14
|
||||
#define USB_EXT_PROP_DW_SIZE 0
|
||||
#define USB_EXT_PROP_DW_PROPERTY_DATA_TYPE 4
|
||||
#define USB_EXT_PROP_W_PROPERTY_NAME_LENGTH 8
|
||||
#define USB_EXT_PROP_B_PROPERTY_NAME 10
|
||||
#define USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH 10
|
||||
#define USB_EXT_PROP_B_PROPERTY_DATA 14
|
||||
|
||||
#define USB_EXT_PROP_RESERVED 0
|
||||
#define USB_EXT_PROP_UNICODE 1
|
||||
#define USB_EXT_PROP_UNICODE_ENV 2
|
||||
#define USB_EXT_PROP_BINARY 3
|
||||
#define USB_EXT_PROP_LE32 4
|
||||
#define USB_EXT_PROP_BE32 5
|
||||
#define USB_EXT_PROP_UNICODE_LINK 6
|
||||
#define USB_EXT_PROP_UNICODE_MULTI 7
|
||||
#define USB_EXT_PROP_RESERVED 0
|
||||
#define USB_EXT_PROP_UNICODE 1
|
||||
#define USB_EXT_PROP_UNICODE_ENV 2
|
||||
#define USB_EXT_PROP_BINARY 3
|
||||
#define USB_EXT_PROP_LE32 4
|
||||
#define USB_EXT_PROP_BE32 5
|
||||
#define USB_EXT_PROP_UNICODE_LINK 6
|
||||
#define USB_EXT_PROP_UNICODE_MULTI 7
|
||||
|
||||
static inline u8 *__usb_ext_prop_ptr(u8 *buf, size_t offset)
|
||||
{
|
||||
return buf + offset;
|
||||
return buf + offset;
|
||||
}
|
||||
|
||||
static inline u8 *usb_ext_prop_size_ptr(u8 *buf)
|
||||
{
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_SIZE);
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_SIZE);
|
||||
}
|
||||
|
||||
static inline u8 *usb_ext_prop_type_ptr(u8 *buf)
|
||||
{
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_TYPE);
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_TYPE);
|
||||
}
|
||||
|
||||
static inline u8 *usb_ext_prop_name_len_ptr(u8 *buf)
|
||||
{
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_W_PROPERTY_NAME_LENGTH);
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_W_PROPERTY_NAME_LENGTH);
|
||||
}
|
||||
|
||||
static inline u8 *usb_ext_prop_name_ptr(u8 *buf)
|
||||
{
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_NAME);
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_NAME);
|
||||
}
|
||||
|
||||
static inline u8 *usb_ext_prop_data_len_ptr(u8 *buf, size_t off)
|
||||
{
|
||||
return __usb_ext_prop_ptr(buf,
|
||||
USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + off);
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + off);
|
||||
}
|
||||
|
||||
static inline u8 *usb_ext_prop_data_ptr(u8 *buf, size_t off)
|
||||
{
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_DATA + off);
|
||||
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_DATA + off);
|
||||
}
|
||||
|
||||
static inline void usb_ext_prop_put_size(u8 *buf, int dw_size)
|
||||
{
|
||||
put_unaligned_le32(dw_size, usb_ext_prop_size_ptr(buf));
|
||||
put_unaligned_le32(dw_size, usb_ext_prop_size_ptr(buf));
|
||||
}
|
||||
|
||||
static inline void usb_ext_prop_put_type(u8 *buf, int type)
|
||||
{
|
||||
put_unaligned_le32(type, usb_ext_prop_type_ptr(buf));
|
||||
put_unaligned_le32(type, usb_ext_prop_type_ptr(buf));
|
||||
}
|
||||
|
||||
static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl)
|
||||
{
|
||||
int result;
|
||||
int result;
|
||||
|
||||
put_unaligned_le16(pnl, usb_ext_prop_name_len_ptr(buf));
|
||||
result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN,
|
||||
(wchar_t *) usb_ext_prop_name_ptr(buf), pnl - 2);
|
||||
if (result < 0)
|
||||
return result;
|
||||
put_unaligned_le16(pnl, usb_ext_prop_name_len_ptr(buf));
|
||||
result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN,
|
||||
(wchar_t *) usb_ext_prop_name_ptr(buf), pnl - 2);
|
||||
if (result < 0)
|
||||
return result;
|
||||
|
||||
put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl - 2]);
|
||||
put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl - 2]);
|
||||
|
||||
return pnl;
|
||||
return pnl;
|
||||
}
|
||||
|
||||
static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data,
|
||||
int data_len)
|
||||
static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data, int data_len)
|
||||
{
|
||||
put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
|
||||
memcpy_s(usb_ext_prop_data_ptr(buf, pnl), data_len, data, data_len);
|
||||
int32_t ret;
|
||||
put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
|
||||
ret = memcpy_s(usb_ext_prop_data_ptr(buf, pnl), data_len, data, data_len);
|
||||
if (ret != EOK) {
|
||||
HDF_LOGE("%{public}s: %{public}d memset_s failed", __func__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string,
|
||||
int data_len)
|
||||
static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string, int data_len)
|
||||
{
|
||||
int result;
|
||||
put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
|
||||
result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN,
|
||||
(wchar_t *) usb_ext_prop_data_ptr(buf, pnl),
|
||||
data_len - 2);
|
||||
if (result < 0)
|
||||
return result;
|
||||
int result;
|
||||
put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
|
||||
result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN,
|
||||
(wchar_t *) usb_ext_prop_data_ptr(buf, pnl), data_len - 2);
|
||||
if (result < 0)
|
||||
return result;
|
||||
|
||||
put_unaligned_le16(0,
|
||||
&buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len - 2]);
|
||||
put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len - 2]);
|
||||
|
||||
return data_len;
|
||||
return data_len;
|
||||
}
|
||||
|
||||
#endif /* __U_OS_DESC_H__ */
|
||||
|
||||
@@ -56,27 +56,31 @@ static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void)
|
||||
struct UsbPnpDeviceInfo *infoTemp = NULL;
|
||||
unsigned char *ptr = NULL;
|
||||
static int32_t idNum = 0;
|
||||
int32_t ret;
|
||||
|
||||
ptr = OsalMemCalloc(sizeof(struct UsbPnpDeviceInfo));
|
||||
if (ptr == NULL) {
|
||||
HDF_LOGE("%s:%d OsalMemAlloc faile ", __func__, __LINE__);
|
||||
return NULL;
|
||||
} else {
|
||||
infoTemp = (struct UsbPnpDeviceInfo *)ptr;
|
||||
|
||||
if (idNum++ >= INT32_MAX) {
|
||||
idNum = 0;
|
||||
}
|
||||
infoTemp->id = idNum;
|
||||
OsalMutexInit(&infoTemp->lock);
|
||||
infoTemp->status = USB_PNP_DEVICE_INIT_STATUS;
|
||||
DListHeadInit(&infoTemp->list);
|
||||
memset_s(infoTemp->interfaceRemoveStatus, USB_PNP_INFO_MAX_INTERFACES,
|
||||
0, sizeof(infoTemp->interfaceRemoveStatus));
|
||||
DListInsertTail(&infoTemp->list, &g_usbPnpInfoListHead);
|
||||
|
||||
return infoTemp;
|
||||
}
|
||||
infoTemp = (struct UsbPnpDeviceInfo *)ptr;
|
||||
|
||||
if (idNum++ >= INT32_MAX) {
|
||||
idNum = 0;
|
||||
}
|
||||
infoTemp->id = idNum;
|
||||
OsalMutexInit(&infoTemp->lock);
|
||||
infoTemp->status = USB_PNP_DEVICE_INIT_STATUS;
|
||||
DListHeadInit(&infoTemp->list);
|
||||
ret = memset_s(infoTemp->interfaceRemoveStatus, USB_PNP_INFO_MAX_INTERFACES, 0, sizeof(infoTemp->interfaceRemoveStatus));
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%{public}s:%{public}d memset_s failed", __func__, __LINE__);
|
||||
OsalMemFree(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DListInsertTail(&infoTemp->list, &g_usbPnpInfoListHead);
|
||||
return infoTemp;
|
||||
}
|
||||
|
||||
static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara queryPara)
|
||||
@@ -191,9 +195,8 @@ static int32_t UsbPnpNotifyAddInitInfo(struct UsbPnpDeviceInfo *deviceInfo, unio
|
||||
for (i = 0; i < deviceInfo->info.numInfos; i++) {
|
||||
if ((infoData.usbDev->actconfig->interface[i] == NULL) ||
|
||||
(infoData.usbDev->actconfig->interface[i]->cur_altsetting == NULL)) {
|
||||
HDF_LOGE("%s interface[%d]=%p or interface[%d]->cur_altsetting=%p is NULL",
|
||||
__func__, i, infoData.usbDev->actconfig->interface[i], i,
|
||||
infoData.usbDev->actconfig->interface[i]->cur_altsetting);
|
||||
HDF_LOGE("%{public}s interface[%{public}d] or interface[%{public}d]->cur_altsetting is NULL",
|
||||
__func__, i, i);
|
||||
ret = HDF_ERR_INVALID_PARAM;
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user