OSDN Git Service

ALSA: asihpi: fix a potential double-fetch bug when copying puhm
authorMeng Xu <mengxu.gatech@gmail.com>
Tue, 19 Sep 2017 05:21:56 +0000 (01:21 -0400)
committerTakashi Iwai <tiwai@suse.de>
Tue, 19 Sep 2017 20:03:59 +0000 (22:03 +0200)
commite1af344df4e5c8fe90f4a63235a68d5405afc41b
treeb230497f54de3a989062c5cb983ef1bed9507074
parenta931b9ce93841a5b66b709ba5a244276e345e63b
ALSA: asihpi: fix a potential double-fetch bug when copying puhm

The hm->h.size is intended to hold the actual size of the hm struct
that is copied from userspace and should always be <= sizeof(*hm).

However, after copy_from_user(hm, puhm, hm->h.size), since userspace
process has full control over the memory region pointed by puhm, it is
possible that the value of hm->h.size is different from what is fetched-in
previously (get_user(hm->h.size, (u16 __user *)puhm)). In other words,
hm->h.size is overriden and the relation between hm->h.size and the hm
struct is broken.

This patch proposes to use a seperate variable, msg_size, to hold
the value of the first fetch and override hm->h.size to msg_size
after the second fetch to maintain the relation.

Signed-off-by: Meng Xu <mengxu.gatech@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/asihpi/hpioctl.c