Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp68411pxj; Thu, 20 May 2021 04:46:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeAKNTqaKPIwvBY6QMOgH8TNiocPZTggZ4gJOqXodO3VHJF/nBjbYc0lTWYTasuQ4lT2eG X-Received: by 2002:a17:906:a20b:: with SMTP id r11mr4345391ejy.323.1621511166065; Thu, 20 May 2021 04:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621511166; cv=none; d=google.com; s=arc-20160816; b=vNhZ88TyOBRSTWRTQC7NQybjz3PtQQ+SK6+irYJwjLNCUVZ1OKDsf/KnksEGccNpGf GmGkNwGGPTIZNScOTAvc9GCzg/xy5AEagW5vc7VhVf1mCyTwov00nvnmzvSYwonE1NqJ /3VoH7InXYdvBvPM0oBYMfEsSEosDvW+0k3XBMv7jQ0cPnKh2I8qRJ5sH/Cl8nuJJnFP YofiTjWFKbmZL4+xH5aMO8DB7Pu3tGRNBaXBbXieOp9dcWZiSa4YZvGbkXMP/WuSQNTo WklMCFwz9Lfm+r+CstqrjmGmopPEioD6DUpXZzFOvPic5n7NVUUxonELhfWU3JDuyFED wQ5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7zf23P/icCai8BtsHzbMI0oNc04FORN+4VHpd20v2Gs=; b=YplHofBrV79CVg7H1Vcgt3S2X0E8QgIQDGjGysUfVMrrM25shaKFtldiOVfJ5sGn2M PDeF8Tz6L2xDW0cobbbS7Qjn7TwPcTW++qowCyVvGkRtjkqGtHgaMI/KrEQRYNCWDujX lcrycGLYzkmCyDVzxzaq/L5j2yvqs+dTI6bBTkOEJPUcJ8kZaUs9xpvJ9bskBmTUMOdO MLF3XOgSSwNhFTUJ0DUEsHSSN68/1zon1cWNAeBcBnp3aSOAp5I6fSh2+tmTwIcI6++N THKaGdfG0lP5gJRrRMqE7mcUqHZealCRAFprm1TIuddHK3aJ9v9W0te9hj/NEltrKT4m NsRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kWIS1zew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r3si2378215ejs.480.2021.05.20.04.45.42; Thu, 20 May 2021 04:46:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kWIS1zew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241009AbhETLmI (ORCPT + 99 others); Thu, 20 May 2021 07:42:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:44022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240637AbhETLVJ (ORCPT ); Thu, 20 May 2021 07:21:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6945661D8A; Thu, 20 May 2021 10:11:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505480; bh=fTf4qo64soCDRDnKGHNUSCNtTuVdhpbH+CBMMyRAsiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kWIS1zewuPLcnN/8NtO73nNTPqP6UN14KwkaeGbCCFEka1cffHvYujnbNqUArNkpA TE4yGoINlmlyGcSyRFEpBVMcTlIcxaUdhLUVfCJiFyOBfqkC93+pIs96jjkaT1mJ8a doQ/BJr14Ov6gjOmlDEDX7Wtg8H2mS4XNoRdaPsA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mihai Moldovan , Masahiro Yamada , Sasha Levin Subject: [PATCH 4.4 147/190] kconfig: nconf: stop endless search loops Date: Thu, 20 May 2021 11:23:31 +0200 Message-Id: <20210520092107.041836258@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mihai Moldovan [ 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 Signed-off-by: Masahiro Yamada Signed-off-by: Sasha Levin --- 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