From f49c852b5e387ce137bcf16c9388130ac3bee58e Mon Sep 17 00:00:00 2001 From: Amit Purwar Date: Fri, 9 Dec 2016 18:59:16 +0530 Subject: [PATCH] P2P: Fix a theoretical out of bounds read in wpas_p2p_select_go_freq() Commit 8e84921efe652233703588852bc43c36ccb241df ('P2P: Support driver preferred freq list for Autonomous GO case') introduced this loop to go through preferred channel list from the driver. The loop does bounds checking of the index only after having read a value from the array. That could in theory read one entry beyond the end of the stack buffer. Fix this by moving the index variable check to be done before using it to fetch a value from the array. This code is used only if wpa_supplicant is build with CONFIG_DRIVER_NL80211_QCA=y and if the driver supports the vendor extension (get_pref_freq_list() driver op). In addition, the driver would need to return more than P2P_MAX_PREF_CHANNELS (= 100) preferred channels for this to actually be able to read beyond the buffer. No driver is known to return that many preferred channels, so this does not seem to be reachable in practice. Signed-off-by: Amit Purwar Signed-off-by: Mayank Haarit --- wpa_supplicant/p2p_supplicant.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 75ee852e8..6dc08fabd 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -5606,9 +5606,9 @@ static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq) &size, pref_freq_list); if (!res && size > 0) { i = 0; - while (wpas_p2p_disallowed_freq(wpa_s->global, - pref_freq_list[i]) && - i < size) { + while (i < size && + wpas_p2p_disallowed_freq(wpa_s->global, + pref_freq_list[i])) { wpa_printf(MSG_DEBUG, "P2P: preferred_freq_list[%d]=%d is disallowed", i, pref_freq_list[i]);