Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wusb: fix find_first_zero_bit() return value check

In wusb_cluster_id_get(), if no zero bits exist in wusb_cluster_id_table,
find_first_zero_bit() returns CLUSTER_IDS.

But it is impossible to detect that the bitmap is full because there
is an off-by-one error in the return value check. It will cause
unexpected memory access by setting bit out of wusb_cluster_id_table
bitmap, and caller will get wrong cluster id.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-usb@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Akinobu Mita and committed by
Greg Kroah-Hartman
962f3ffa 60b0bf0f

+1 -1
+1 -1
drivers/usb/wusbcore/wusbhc.c
··· 320 320 u8 id; 321 321 spin_lock(&wusb_cluster_ids_lock); 322 322 id = find_first_zero_bit(wusb_cluster_id_table, CLUSTER_IDS); 323 - if (id > CLUSTER_IDS) { 323 + if (id >= CLUSTER_IDS) { 324 324 id = 0; 325 325 goto out; 326 326 }