Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp137722pxj; Mon, 17 May 2021 23:14:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS6EmxmZX3sgCqNhTpG+TZwLNTiuOXWbaVviDCKdvYvhVMxPlLpkjC4okMZTkVBpMU4Mx9 X-Received: by 2002:a05:6402:2548:: with SMTP id l8mr5155580edb.208.1621318464911; Mon, 17 May 2021 23:14:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621318464; cv=none; d=google.com; s=arc-20160816; b=ExJzgaSfsz7+JLt/qqUR95gLEIiZ6N3rseSSm5UULZtkHHgSFJcp25FIkaac7hgL4J rcBUF8AmAVCIWFrxfqkkc/FheiNqGZ8wT5yI1RE26bR6K2dln9nk1wgdmSTtgciz8xvE FQb5QewqVSMqFAnVVxmvVq0LNyuz+mUSYi8l5vp2RbFWT4IFK1EmUYTQMAoWP9q4lcdt n6JOFggrzGlS9BOM4zMsmZbv6L4e1+mvc0cIJL1Qz4R23h/Fz1Ogw0LGlHkEkPT6wfji cgJa6SEC6vYrxddpQDYsuT9uXBtTVyYI39bsYayfKVgHNrKwRypxaENLhIZSzqrZO0fr E69A== 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=BE2EnV9H3N/fvhN0ZW6Bxh8vEXBC1JiYrq/Ux8L2DZg=; b=Uuhv4YSjLkfnrjspig55mzDPn0r0JQZvEHl10SlEZGCtPtX/3RTIVijX8JAG1rebb1 XD1f221/DjOkSZGN0AmwiVi9Bi+sfwoKvLGQeW0I/Ay8u7SxwqpHRWdx1vRUu+Srn9bH H0e0wgRwqk800SQbf1hEKzAHXXaQzt9LZ2ZytHngLoMhGuzMnfkQFmDrLzVoJ4dhu9TT pPxR1EtuyqgmSzcJgedyb+K97/CLgDnfFejsDBlspCM1tlH6okt1MHikOrV2w2GKmHOD tvgr68VAgwg398qvufbahXGrJbeba5/bu78c9JSHJUgBYZZ8Etf4zEssrvuGr3jlYYtQ ywEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tln8JYvY; 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 t1si2385464edw.346.2021.05.17.23.13.58; Mon, 17 May 2021 23:14:24 -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=tln8JYvY; 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 S241186AbhEQOsj (ORCPT + 99 others); Mon, 17 May 2021 10:48:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:50854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241276AbhEQOkN (ORCPT ); Mon, 17 May 2021 10:40:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5E38261947; Mon, 17 May 2021 14:18:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261130; bh=krCIKtZo6P7jGrPBiaStvZ2n8tEKtJJdDsSUq2CkYcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tln8JYvYfYN1FMY7j4MK76hXiFWn/9nE53Ecoxy4PmLC86ntCVb8blM8HQuwdzUaA ePB31Kg+8VMV86gM3/g3UUHrenOG4z1pJuFRu7KgpOCofmPjYnot6dRI/debOPwrKM At2FYN/qD/zKXeI67jJfBjh05NiVHpiUDSwgpsk4= 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 5.11 077/329] kconfig: nconf: stop endless search loops Date: Mon, 17 May 2021 15:59:48 +0200 Message-Id: <20210517140304.708074783@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@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 e0f965529166..af814b39b876 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -504,8 +504,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) != NULL) -- 2.30.2