Commit 828dfc2b authored by Wenwen Wang's avatar Wenwen Wang Committed by Stefan Bader

isdn: eicon: fix a missing-check bug

BugLink: https://bugs.launchpad.net/bugs/1777063

[ Upstream commit 6009d1fe ]

In divasmain.c, the function divas_write() firstly invokes the function
diva_xdi_open_adapter() to open the adapter that matches with the adapter
number provided by the user, and then invokes the function diva_xdi_write()
to perform the write operation using the matched adapter. The two functions
diva_xdi_open_adapter() and diva_xdi_write() are located in diva.c.

In diva_xdi_open_adapter(), the user command is copied to the object 'msg'
from the userspace pointer 'src' through the function pointer 'cp_fn',
which eventually calls copy_from_user() to do the copy. Then, the adapter
number 'msg.adapter' is used to find out a matched adapter from the
'adapter_queue'. A matched adapter will be returned if it is found.
Otherwise, NULL is returned to indicate the failure of the verification on
the adapter number.

As mentioned above, if a matched adapter is returned, the function
diva_xdi_write() is invoked to perform the write operation. In this
function, the user command is copied once again from the userspace pointer
'src', which is the same as the 'src' pointer in diva_xdi_open_adapter() as
both of them are from the 'buf' pointer in divas_write(). Similarly, the
copy is achieved through the function pointer 'cp_fn', which finally calls
copy_from_user(). After the successful copy, the corresponding command
processing handler of the matched adapter is invoked to perform the write
operation.

It is obvious that there are two copies here from userspace, one is in
diva_xdi_open_adapter(), and one is in diva_xdi_write(). Plus, both of
these two copies share the same source userspace pointer, i.e., the 'buf'
pointer in divas_write(). Given that a malicious userspace process can race
to change the content pointed by the 'buf' pointer, this can pose potential
security issues. For example, in the first copy, the user provides a valid
adapter number to pass the verification process and a valid adapter can be
found. Then the user can modify the adapter number to an invalid number.
This way, the user can bypass the verification process of the adapter
number and inject inconsistent data.

This patch reuses the data copied in
diva_xdi_open_adapter() and passes it to diva_xdi_write(). This way, the
above issues can be avoided.
Signed-off-by: default avatarWenwen Wang <wang6495@umn.edu>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 08d6c4b1
...@@ -387,10 +387,10 @@ void divasa_xdi_driver_unload(void) ...@@ -387,10 +387,10 @@ void divasa_xdi_driver_unload(void)
** Receive and process command from user mode utility ** Receive and process command from user mode utility
*/ */
void *diva_xdi_open_adapter(void *os_handle, const void __user *src, void *diva_xdi_open_adapter(void *os_handle, const void __user *src,
int length, int length, void *mptr,
divas_xdi_copy_from_user_fn_t cp_fn) divas_xdi_copy_from_user_fn_t cp_fn)
{ {
diva_xdi_um_cfg_cmd_t msg; diva_xdi_um_cfg_cmd_t *msg = (diva_xdi_um_cfg_cmd_t *)mptr;
diva_os_xdi_adapter_t *a = NULL; diva_os_xdi_adapter_t *a = NULL;
diva_os_spin_lock_magic_t old_irql; diva_os_spin_lock_magic_t old_irql;
struct list_head *tmp; struct list_head *tmp;
...@@ -400,21 +400,21 @@ void *diva_xdi_open_adapter(void *os_handle, const void __user *src, ...@@ -400,21 +400,21 @@ void *diva_xdi_open_adapter(void *os_handle, const void __user *src,
length, sizeof(diva_xdi_um_cfg_cmd_t))) length, sizeof(diva_xdi_um_cfg_cmd_t)))
return NULL; return NULL;
} }
if ((*cp_fn) (os_handle, &msg, src, sizeof(msg)) <= 0) { if ((*cp_fn) (os_handle, msg, src, sizeof(*msg)) <= 0) {
DBG_ERR(("A: A(?) open, write error")) DBG_ERR(("A: A(?) open, write error"))
return NULL; return NULL;
} }
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "open_adapter"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "open_adapter");
list_for_each(tmp, &adapter_queue) { list_for_each(tmp, &adapter_queue) {
a = list_entry(tmp, diva_os_xdi_adapter_t, link); a = list_entry(tmp, diva_os_xdi_adapter_t, link);
if (a->controller == (int)msg.adapter) if (a->controller == (int)msg->adapter)
break; break;
a = NULL; a = NULL;
} }
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "open_adapter"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "open_adapter");
if (!a) { if (!a) {
DBG_ERR(("A: A(%d) open, adapter not found", msg.adapter)) DBG_ERR(("A: A(%d) open, adapter not found", msg->adapter))
} }
return (a); return (a);
...@@ -436,8 +436,10 @@ void diva_xdi_close_adapter(void *adapter, void *os_handle) ...@@ -436,8 +436,10 @@ void diva_xdi_close_adapter(void *adapter, void *os_handle)
int int
diva_xdi_write(void *adapter, void *os_handle, const void __user *src, diva_xdi_write(void *adapter, void *os_handle, const void __user *src,
int length, divas_xdi_copy_from_user_fn_t cp_fn) int length, void *mptr,
divas_xdi_copy_from_user_fn_t cp_fn)
{ {
diva_xdi_um_cfg_cmd_t *msg = (diva_xdi_um_cfg_cmd_t *)mptr;
diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) adapter; diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) adapter;
void *data; void *data;
...@@ -458,7 +460,13 @@ diva_xdi_write(void *adapter, void *os_handle, const void __user *src, ...@@ -458,7 +460,13 @@ diva_xdi_write(void *adapter, void *os_handle, const void __user *src,
return (-2); return (-2);
} }
length = (*cp_fn) (os_handle, data, src, length); if (msg) {
*(diva_xdi_um_cfg_cmd_t *)data = *msg;
length = (*cp_fn) (os_handle, (char *)data + sizeof(*msg),
src + sizeof(*msg), length - sizeof(*msg));
} else {
length = (*cp_fn) (os_handle, data, src, length);
}
if (length > 0) { if (length > 0) {
if ((*(a->interface.cmd_proc)) if ((*(a->interface.cmd_proc))
(a, (diva_xdi_um_cfg_cmd_t *) data, length)) { (a, (diva_xdi_um_cfg_cmd_t *) data, length)) {
......
...@@ -19,10 +19,11 @@ int diva_xdi_read(void *adapter, void *os_handle, void __user *dst, ...@@ -19,10 +19,11 @@ int diva_xdi_read(void *adapter, void *os_handle, void __user *dst,
int max_length, divas_xdi_copy_to_user_fn_t cp_fn); int max_length, divas_xdi_copy_to_user_fn_t cp_fn);
int diva_xdi_write(void *adapter, void *os_handle, const void __user *src, int diva_xdi_write(void *adapter, void *os_handle, const void __user *src,
int length, divas_xdi_copy_from_user_fn_t cp_fn); int length, void *msg,
divas_xdi_copy_from_user_fn_t cp_fn);
void *diva_xdi_open_adapter(void *os_handle, const void __user *src, void *diva_xdi_open_adapter(void *os_handle, const void __user *src,
int length, int length, void *msg,
divas_xdi_copy_from_user_fn_t cp_fn); divas_xdi_copy_from_user_fn_t cp_fn);
void diva_xdi_close_adapter(void *adapter, void *os_handle); void diva_xdi_close_adapter(void *adapter, void *os_handle);
......
...@@ -591,19 +591,22 @@ static int divas_release(struct inode *inode, struct file *file) ...@@ -591,19 +591,22 @@ static int divas_release(struct inode *inode, struct file *file)
static ssize_t divas_write(struct file *file, const char __user *buf, static ssize_t divas_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
diva_xdi_um_cfg_cmd_t msg;
int ret = -EINVAL; int ret = -EINVAL;
if (!file->private_data) { if (!file->private_data) {
file->private_data = diva_xdi_open_adapter(file, buf, file->private_data = diva_xdi_open_adapter(file, buf,
count, count, &msg,
xdi_copy_from_user); xdi_copy_from_user);
} if (!file->private_data)
if (!file->private_data) { return (-ENODEV);
return (-ENODEV); ret = diva_xdi_write(file->private_data, file,
buf, count, &msg, xdi_copy_from_user);
} else {
ret = diva_xdi_write(file->private_data, file,
buf, count, NULL, xdi_copy_from_user);
} }
ret = diva_xdi_write(file->private_data, file,
buf, count, xdi_copy_from_user);
switch (ret) { switch (ret) {
case -1: /* Message should be removed from rx mailbox first */ case -1: /* Message should be removed from rx mailbox first */
ret = -EBUSY; ret = -EBUSY;
...@@ -622,11 +625,12 @@ static ssize_t divas_write(struct file *file, const char __user *buf, ...@@ -622,11 +625,12 @@ static ssize_t divas_write(struct file *file, const char __user *buf,
static ssize_t divas_read(struct file *file, char __user *buf, static ssize_t divas_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
diva_xdi_um_cfg_cmd_t msg;
int ret = -EINVAL; int ret = -EINVAL;
if (!file->private_data) { if (!file->private_data) {
file->private_data = diva_xdi_open_adapter(file, buf, file->private_data = diva_xdi_open_adapter(file, buf,
count, count, &msg,
xdi_copy_from_user); xdi_copy_from_user);
} }
if (!file->private_data) { if (!file->private_data) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment