linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Mihai Moldovan <ionic@ionic.de>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-kbuild@vger.kernel.org
Subject: [PATCH AUTOSEL 4.9 14/22] kconfig: nconf: stop endless search loops
Date: Wed,  5 May 2021 12:41:21 -0400	[thread overview]
Message-ID: <20210505164129.3464277-14-sashal@kernel.org> (raw)
In-Reply-To: <20210505164129.3464277-1-sashal@kernel.org>

From: Mihai Moldovan <ionic@ionic.de>

[ Upstream commit 8c94b430b9f6213dec84e309bb480a71778c4213 ]

If the user selects the very first entry in a page and performs a
search-up operation, or selects the very last entry in a page and
performs a search-down operation that will not succeed (e.g., via
[/]asdfzzz[Up Arrow]), nconf will never terminate searching the page.

The reason is that in this case, the starting point will be set to -1
or n, which is then translated into (n - 1) (i.e., the last entry of
the page) or 0 (i.e., the first entry of the page) and finally the
search begins. This continues to work fine until the index reaches 0 or
(n - 1), at which point it will be decremented to -1 or incremented to
n, but not checked against the starting point right away. Instead, it's
wrapped around to the bottom or top again, after which the starting
point check occurs... and naturally fails.

My original implementation added another check for -1 before wrapping
the running index variable around, but Masahiro Yamada pointed out that
the actual issue is that the comparison point (starting point) exceeds
bounds (i.e., the [0,n-1] interval) in the first place and that,
instead, the starting point should be fixed.

This has the welcome side-effect of also fixing the case where the
starting point was n while searching down, which also lead to an
infinite loop.

OTOH, this code is now essentially all his work.

Amazingly, nobody seems to have been hit by this for 11 years - or at
the very least nobody bothered to debug and fix this.

Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 scripts/kconfig/nconf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index f7049e288e93..c58a46904861 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -502,8 +502,8 @@ static int get_mext_match(const char *match_str, match_f flag)
 	else if (flag == FIND_NEXT_MATCH_UP)
 		--match_start;
 
+	match_start = (match_start + items_num) % items_num;
 	index = match_start;
-	index = (index + items_num) % items_num;
 	while (true) {
 		char *str = k_menu_items[index].str;
 		if (strcasestr(str, match_str) != 0)
-- 
2.30.2


  parent reply	other threads:[~2021-05-05 17:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 16:41 [PATCH AUTOSEL 4.9 01/22] fs: dlm: fix debugfs dump Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 02/22] tipc: convert dest node's address to network order Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 03/22] net: stmmac: Set FIFO sizes for ipq806x Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 04/22] ALSA: hdsp: don't disable if not enabled Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 05/22] ALSA: hdspm: " Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 06/22] ALSA: rme9652: " Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 07/22] Bluetooth: Set CONF_NOT_COMPLETE as l2cap_chan default Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 08/22] Bluetooth: verify AMP hci_chan before amp_destroy Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 09/22] Bluetooth: initialize skb_queue_head at l2cap_chan_create() Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 10/22] ip6_vti: proper dev_{hold|put} in ndo_[un]init methods Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 11/22] mac80211: clear the beacon's CRC after channel switch Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 12/22] cuse: prevent clone Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 13/22] selftests: Set CC to clang in lib.mk if LLVM is set Sasha Levin
2021-05-05 16:41 ` Sasha Levin [this message]
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 15/22] sctp: Fix out-of-bounds warning in sctp_process_asconf_param() Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 16/22] ASoC: rt286: Generalize support for ALC3263 codec Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 17/22] samples/bpf: Fix broken tracex1 due to kprobe argument change Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 18/22] powerpc/pseries: Stop calling printk in rtas_stop_self() Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 19/22] wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 20/22] wl3501_cs: Fix out-of-bounds warnings in wl3501_mgmt_join Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 21/22] powerpc/iommu: Annotate nested lock for lockdep Sasha Levin
2021-05-05 16:41 ` [PATCH AUTOSEL 4.9 22/22] net: ethernet: mtk_eth_soc: fix RX VLAN offload Sasha Levin

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=20210505164129.3464277-14-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=ionic@ionic.de \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=stable@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).