提交 4e24b572 编写于 作者: B boxi

fix: Optimize /dev/quickstart permissions.

Optimize /dev/quickstart permissions.

Close #I3OYUQ

Change-Id: Ie2847efeb5dddf2bbea0251cca39bb7cb973e3f6
上级 cb140a44
......@@ -55,10 +55,15 @@ typedef enum {
QS_CTL_LIMIT
} QuickstartConctrl;
typedef struct {
unsigned int pid;
unsigned int events;
} QuickstartMask;
#define QUICKSTART_IOC_MAGIC 'T'
#define QUICKSTART_UNREGISTER _IO(QUICKSTART_IOC_MAGIC, QS_UNREGISTER)
#define QUICKSTART_NOTIFY _IO(QUICKSTART_IOC_MAGIC, QS_NOTIFY)
#define QUICKSTART_LISTEN _IO(QUICKSTART_IOC_MAGIC, QS_LISTEN)
#define QUICKSTART_LISTEN _IOR(QUICKSTART_IOC_MAGIC, QS_LISTEN, QuickstartMask)
#define QUICKSTART_STAGE(x) _IO(QUICKSTART_IOC_MAGIC, (x))
#define QUICKSTART_NODE "/dev/quickstart"
......
......@@ -49,14 +49,34 @@ static int QuickstartClose(struct file *filep)
return 0;
}
static void QuickstartNotify(unsigned int events)
static int QuickstartNotify(unsigned int events)
{
LOS_EventWrite((PEVENT_CB_S)&g_qsEvent, events);
unsigned int pid = LOS_GetCurrProcessID();
/* 16:low 16 bits for eventMask, high 16 bits for pid */
unsigned int notifyEvent = (pid << 16) | events;
int ret = LOS_EventWrite((PEVENT_CB_S)&g_qsEvent, notifyEvent);
if (ret != 0) {
PRINT_ERR("%s,%d:0x%x\n", __FUNCTION__, __LINE__, ret);
ret = -EINVAL;
}
return ret;
}
static void QuickstartListen(unsigned int eventMask)
static int QuickstartListen(unsigned long arg)
{
LOS_EventRead((PEVENT_CB_S)&g_qsEvent, eventMask, LOS_WAITMODE_AND | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
QuickstartMask listenMask;
if (copy_from_user(&listenMask, (struct QuickstartMask __user *)arg, sizeof(QuickstartMask)) != LOS_OK) {
PRINT_ERR("%s,%d\n", __FUNCTION__, __LINE__);
return -EINVAL;
}
/* 16:low 16 bits for eventMask, high 16 bits for pid */
unsigned int mask = (listenMask.pid << 16) | listenMask.events;
int ret = LOS_EventRead((PEVENT_CB_S)&g_qsEvent, mask, LOS_WAITMODE_AND | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
if (ret != 0) {
PRINT_ERR("%s,%d:0x%x\n", __FUNCTION__, __LINE__, ret);
ret = -EINVAL;
}
return ret;
}
void QuickstartHookRegister(LosSysteminitHook hooks)
......@@ -66,7 +86,7 @@ void QuickstartHookRegister(LosSysteminitHook hooks)
}
}
static void QuickstartStageWorking(unsigned int level)
static int QuickstartStageWorking(unsigned int level)
{
if ((level < QS_STAGE_CNT) && (g_callOnce[level] == 0) && (g_systemInitFunc[level] != NULL)) {
g_callOnce[level] = 1; /* 1: Already called */
......@@ -74,6 +94,7 @@ static void QuickstartStageWorking(unsigned int level)
} else {
PRINT_WARN("Trigger quickstart,but doing nothing!!\n");
}
return 0;
}
static int QuickstartDevUnregister(void)
......@@ -83,27 +104,27 @@ static int QuickstartDevUnregister(void)
static ssize_t QuickstartIoctl(struct file *filep, int cmd, unsigned long arg)
{
ssize_t ret;
if (cmd == QUICKSTART_NOTIFY) {
QuickstartNotify(arg);
return 0;
return QuickstartNotify(arg);
}
if (OsGetUserInitProcessID() != LOS_GetCurrProcessID()) {
PRINT_ERR("Permission denios!\n");
return -1;
return -EACCES;
}
switch (cmd) {
case QUICKSTART_UNREGISTER:
QuickstartDevUnregister();
ret = QuickstartDevUnregister();
break;
case QUICKSTART_LISTEN:
QuickstartListen(arg);
ret = QuickstartListen(arg);
break;
default:
QuickstartStageWorking(cmd - QUICKSTART_STAGE(QS_STAGE1)); /* ioctl cmd converted to stage level */
ret = QuickstartStageWorking(cmd - QUICKSTART_STAGE(QS_STAGE1)); /* ioctl cmd converted to stage level */
break;
}
return 0;
return ret;
}
static const struct file_operations_vfs g_quickstartDevOps = {
......@@ -123,6 +144,6 @@ static const struct file_operations_vfs g_quickstartDevOps = {
int QuickstartDevRegister(void)
{
LOS_EventInit(&g_qsEvent);
return register_driver(QUICKSTART_NODE, &g_quickstartDevOps, 0666, 0); /* 0666: file mode */
return register_driver(QUICKSTART_NODE, &g_quickstartDevOps, 0644, 0); /* 0644: file mode */
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册