linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: James Nylen <jnylen@gmail.com>
To: Johannes Berg <johannes@sipsolutions.net>,
	"David S. Miller" <davem@davemloft.net>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] `iwlist scan` fails with many networks available
Date: Sun, 11 Aug 2019 02:08:13 +0000	[thread overview]
Message-ID: <CABVa4NhutjvHPbyaxNeVpJjf-RMJdwEX-Yjk4bkqLC1DN3oXPA@mail.gmail.com> (raw)
In-Reply-To: <CABVa4NgWMkJuyB1P5fwQEYHwqBRiySE+fGQpMKt8zbp+xJ8+rw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 464 bytes --]

In 5.x it's still possible for `ieee80211_scan_results` (`iwlist
scan`) to fail when too many wireless networks are available.  This
code path is used by `wicd`.

Previously: https://lkml.org/lkml/2017/4/2/192

I've been applying this updated patch to my own kernels since 2017 with
no issues.  I am sure it is not the ideal way to solve this problem, but
I'm making my fix available in case it helps others.

Please advise on next steps or if this is a dead end.

[-- Attachment #2: wireless-scan-less-e2big.diff --]
[-- Type: text/plain, Size: 1993 bytes --]

commit 8e80dcb0df71ac8f5d3640bcdb1bba9c7693d63a
Author: James Nylen <jnylen@gmail.com>
Date:   Wed Apr 26 14:38:58 2017 +0200

    Hack: Make `ieee80211_scan_results` (`iwlist scan`) return less E2BIG
    
    See: https://lkml.org/lkml/2017/4/2/192
    
    (and branch `jcn/hack/wireless-scan-no-e2big`)
    
    This should really be done with a bigger limit inside the `iwlist` code
    instead, if possible (or even better: modify `wicd` to use `iw scan`
    instead).

diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index 21be56b3128e..08fa9cb68f59 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -1699,6 +1699,7 @@ static int ieee80211_scan_results(struct cfg80211_registered_device *rdev,
 				  struct iw_request_info *info,
 				  char *buf, size_t len)
 {
+	char *maybe_current_ev;
 	char *current_ev = buf;
 	char *end_buf = buf + len;
 	struct cfg80211_internal_bss *bss;
@@ -1709,14 +1710,29 @@ static int ieee80211_scan_results(struct cfg80211_registered_device *rdev,
 
 	list_for_each_entry(bss, &rdev->bss_list, list) {
 		if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
-			err = -E2BIG;
+			// Buffer too small to hold another BSS.  Only report
+			// an error if we have not yet reached the maximum
+			// buffer size that `iwlist` can handle.
+			if (len < 0xFFFF) {
+				err = -E2BIG;
+			}
 			break;
 		}
-		current_ev = ieee80211_bss(&rdev->wiphy, info, bss,
-					   current_ev, end_buf);
-		if (IS_ERR(current_ev)) {
-			err = PTR_ERR(current_ev);
+		maybe_current_ev = ieee80211_bss(&rdev->wiphy, info, bss,
+					         current_ev, end_buf);
+		if (IS_ERR(maybe_current_ev)) {
+			err = PTR_ERR(maybe_current_ev);
+			if (err == -E2BIG) {
+				// Last BSS failed to copy into buffer.  As
+				// above, only report an error if `iwlist` will
+				// retry again with a larger buffer.
+				if (len >= 0xFFFF) {
+					err = 0;
+				}
+			}
 			break;
+		} else {
+			current_ev = maybe_current_ev;
 		}
 	}
 	spin_unlock_bh(&rdev->bss_lock);

       reply	other threads:[~2019-08-11  2:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CABVa4NgWMkJuyB1P5fwQEYHwqBRiySE+fGQpMKt8zbp+xJ8+rw@mail.gmail.com>
2019-08-11  2:08 ` James Nylen [this message]
2019-08-11  6:25   ` [PATCH] `iwlist scan` fails with many networks available Johannes Berg
2019-08-13  0:43     ` James Nylen
2019-08-21  7:59       ` Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABVa4NhutjvHPbyaxNeVpJjf-RMJdwEX-Yjk4bkqLC1DN3oXPA@mail.gmail.com \
    --to=jnylen@gmail.com \
    --cc=davem@davemloft.net \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).