From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23840C77B76 for ; Wed, 12 Apr 2023 08:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231437AbjDLIxv (ORCPT ); Wed, 12 Apr 2023 04:53:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231461AbjDLIxr (ORCPT ); Wed, 12 Apr 2023 04:53:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F4EF9EC1 for ; Wed, 12 Apr 2023 01:53:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 204F4631CC for ; Wed, 12 Apr 2023 08:53:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31BD5C433EF; Wed, 12 Apr 2023 08:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1681289603; bh=NT8zZTzLMcevEZDJVAuYuUFPgeIwvCBtbsx32sxwWec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tSdVPf4Sl5r/6jsJKyN37UvyH0osHJQMJee299uZ7t17haSuJptLDvpB2hGISGdV6 VemdDdWTUckGY/Nnsg7EJqlllUWxkTcN0NTbNVUqbBMRSyXB02aC8ZPHfFx2hMtREB DExxG1tzn32B6Vk+kKfaCNrue2obt8B5WsN0G+bM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stable@vger.kernel.org, "Liam R. Howlett" Subject: [PATCH 6.2 163/173] maple_tree: reduce user error potential Date: Wed, 12 Apr 2023 10:34:49 +0200 Message-Id: <20230412082844.730111546@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412082838.125271466@linuxfoundation.org> References: <20230412082838.125271466@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: "Liam R. Howlett" commit 50e81c82ad947045c7ed26ddc9acb17276b653b6 upstream. When iterating, a user may operate on the tree and cause the maple state to be altered and left in an unintuitive state. Detect this scenario and correct it by setting to the limit and invalidating the state. Link: https://lkml.kernel.org/r/20230120162650.984577-4-Liam.Howlett@oracle.com Cc: Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett Signed-off-by: Greg Kroah-Hartman --- lib/maple_tree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4736,6 +4736,11 @@ static inline void *mas_next_entry(struc unsigned long last; enum maple_type mt; + if (mas->index > limit) { + mas->index = mas->last = limit; + mas_pause(mas); + return NULL; + } last = mas->last; retry: offset = mas->offset; @@ -4842,6 +4847,11 @@ static inline void *mas_prev_entry(struc { void *entry; + if (mas->index < min) { + mas->index = mas->last = min; + mas_pause(mas); + return NULL; + } retry: while (likely(!mas_is_none(mas))) { entry = mas_prev_nentry(mas, min, mas->index);