From patchwork Sun Aug 11 02:08:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Nylen X-Patchwork-Id: 11088717 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B83E31399 for ; Sun, 11 Aug 2019 02:08:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B8EB22ADC for ; Sun, 11 Aug 2019 02:08:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F3CA26E74; Sun, 11 Aug 2019 02:08:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A048B22ADC for ; Sun, 11 Aug 2019 02:08:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbfHKCIQ (ORCPT ); Sat, 10 Aug 2019 22:08:16 -0400 Received: from mail-ed1-f47.google.com ([209.85.208.47]:35738 "EHLO mail-ed1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbfHKCIQ (ORCPT ); Sat, 10 Aug 2019 22:08:16 -0400 Received: by mail-ed1-f47.google.com with SMTP id w20so100118748edd.2; Sat, 10 Aug 2019 19:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=RP1LWzRuajmzKFCHqaSzfx+dlpKjssOccTd/Pg6x94Y=; b=pQjStUAk0dXclB0KaZ5iJOIZg/GStMfNwGg/nnbV0Wr22jGRxiYitMBnCG7pRajOli cSV1alOcJZo+PSeV/5gjPa2B6ILKlykPwk71yLM1Hm05nY01A1jfJkJTemW3dGZvQPcm ofwqKDap4EFyrqQ+DjUhVgWHqULDNNct3W+gRL57gWIBTPZkiPOT/im8t6viMOfFEamr ZBUgisBezf7qM7U4KS9r20g0qn9kmCHZ7t0/FBps2W2r8Vs/fW0TDcLCTkzqQ+FMWf6d jgbLGRZtDQKpV8jAyLbVstsG9HASAgVnMsVPpF/QUllbQaIKOxuvPQ7ZwJ8hIGd6jye4 hfig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=RP1LWzRuajmzKFCHqaSzfx+dlpKjssOccTd/Pg6x94Y=; b=tI/5zxMTfN2op9xKywLmVfaTjUovPnZCcAz9i4HhpuM2dunhGOOrDwB/PC48tXMHtX asAZCt102Ki4KiHyPad9ZEAH3xNviFdTfcLYJBN/XTnTHDtUeBubZgz2G144qnxLOTV/ YVInI4s3Sy7GDxRFOIDbyS6wX1ieDUz+xMGjyUYPsmPeb7Srx42LHnEQ2gMtTUWdVIE6 jN9x0uPEw34gbZWsjzjQgmFQT4u3XtOi+qYs9+dfVxS+5a3dbNcpssr/kk5MeLcv104T 0f3rvJjXDd4hNjpdx/cq4FsmycR7km/3f7xxbEO6fkL3eXh8SctImUxXfW3Vxx7EkVS1 sc2g== X-Gm-Message-State: APjAAAWG7gU8Se6MswIbubUceCGqP6+LlolgXBnsgFflYY3/7s9AtK9V b07YU8+yttv7mkYmiq8pZwKSjNSiatbOqgrcadar/kflFeo= X-Google-Smtp-Source: APXvYqxexoPqWF5fiyg/W6Z7Mdxv3GsVnhy2+mXXdUwsH61CiLb2bcrPo/hfsa7DE1sdN3yYs5VC0l6oFTW5CFOqewQ= X-Received: by 2002:a50:de08:: with SMTP id z8mr9025845edk.121.1565489294608; Sat, 10 Aug 2019 19:08:14 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a17:906:2001:0:0:0:0 with HTTP; Sat, 10 Aug 2019 19:08:13 -0700 (PDT) In-Reply-To: References: From: James Nylen Date: Sun, 11 Aug 2019 02:08:13 +0000 Message-ID: Subject: [PATCH] `iwlist scan` fails with many networks available To: Johannes Berg , "David S. Miller" , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. commit 8e80dcb0df71ac8f5d3640bcdb1bba9c7693d63a Author: James Nylen 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);