Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1937867rdb; Thu, 7 Dec 2023 13:04:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/xeGoB3k0QpKVPY2tb1r94XMK2xWektvcAqG4bE3Fy7qDPv0EWQsq/6M9/MBB1wtYzqcF X-Received: by 2002:a17:902:d652:b0:1d0:9d92:f18d with SMTP id y18-20020a170902d65200b001d09d92f18dmr2327274plh.45.1701983097313; Thu, 07 Dec 2023 13:04:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701983097; cv=none; d=google.com; s=arc-20160816; b=NNDVB+esxhDTYjU5tHjLMvlIDZiANVeGR9qFUK+IkoO6tSUVe3tKLf57USoN+NLJTo GkcU55Gyo+104s0Wze86uVd3hkz0Ljhoo60/t+KHYWgGs5Iq8sZESbk/wx2LqlIWjddu 4A4pEigSPV6dr2T1Xm0OUS3WlFGHMIVcFVDsu+Lwr1RzFuqYQ96md6bk6i4vDkvLtkKU p2cZhQT5f2jNURxAkWe+fyskBcF/fjGpLRkkqKzHzsXw8hlNUj6xLG+vzHntW4rO9TVE 9QF8yRBuqokNwoB/Lp/Q0om/dIF2aX7iuiPq6bqGBA9Ec3JT/bnCGpqutPc7tORhDf91 qJ8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=P1df2F2aMLldf9qn7FPBt3am2yl+mT6QC0UrRj9+Dnw=; fh=ZXs/8lm4oSbShKv+TueQUGd90hwfiTiuHU+uQE+P554=; b=Jkv8rVo2tuoR1zNCMTvjcoeJ6VU2x7vd43riAoI4ABj0DyqDOorMODCUyArTiLP1Pm 2qrpTUZOM3tWwHM5J8rZKrAOlspI3iq9FXDw5jyilnEgLv0JAIFh92DdH9i4FtfFjZuE Tdwculm0ALVL9Sez0KXRx2GfRTa3U989movDuWql1tY24D0Sx5+FoNrN82eYYYhnc07c 4z6g0lUQQYaF3FVFxT0AZL5+Xjj3LkVKQSgZBfE1MhjI28bsN398u6GDH+C15nLicyzL CSHoXKBkW5Tbn/XBAT1sykP/3vVncyCt171n7f86Zwp0I7/9ANnJArCTdZqO7WGMqNLO t/pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mMqNHPvw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id u13-20020a170902e5cd00b001cfb4bd0e36si332963plf.341.2023.12.07.13.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 13:04:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mMqNHPvw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 411EE80DB725; Thu, 7 Dec 2023 13:04:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443934AbjLGVEi (ORCPT + 99 others); Thu, 7 Dec 2023 16:04:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235238AbjLGVEf (ORCPT ); Thu, 7 Dec 2023 16:04:35 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F9F0171A for ; Thu, 7 Dec 2023 13:04:41 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2866fe08b32so1189950a91.2 for ; Thu, 07 Dec 2023 13:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701983081; x=1702587881; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=P1df2F2aMLldf9qn7FPBt3am2yl+mT6QC0UrRj9+Dnw=; b=mMqNHPvw7iYk1AsnxRD4tGF+MQvNu/BlvCKB3YbPFNplnOMXJHTIlMdRE8ZSwguDiv DO9FGWz5xZ9WV2NZQM+0M1oDpuz+1OWetjwKhE+P0z+AeG4oDpTpbANzixwVMuQ0pqu+ k8j9eoVdIar/wh5x0owXpcQIzDwfUIIe5aQ98= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701983081; x=1702587881; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=P1df2F2aMLldf9qn7FPBt3am2yl+mT6QC0UrRj9+Dnw=; b=kINd9BVaHSlWFl/2XA2W7ml+G3NMcmYCsyemowJtUT24YW856QX5N89bpqWOCQgt0D bNY39OhMC/PefTMruIHugPTAR8msK2WtPDSh7gfMrxYTvBaZLbkHOBZHacgRNP6OfvCu 61I6ZLHNecJQTjHzbDym11pcxgzNEXk9T2RpnaGVhi9K7JjENxL9OlUgQfQUTp4kCgb7 +AXhbxxSnSdhHC8FysPe0JQHrdXL7AHD5oczEBHDrGvfAX/l2thsLEslbzK1QP9PzfFT hEdRGjKVL8+PyBkyg8MKFrDohmkE0LjQZ9nUqc0zHm0f1Df5OCaqzczC2InTkMIeOQkx ruuw== X-Gm-Message-State: AOJu0YymlcgY9yDhYOsl4Jn/kLipRBF7aDf9bqHK+eaMdVVmw66bb68f ATUuFeRY4U2x0d6XlgHbY7g7AA== X-Received: by 2002:a17:90b:350a:b0:285:b3a8:40ac with SMTP id ls10-20020a17090b350a00b00285b3a840acmr2717736pjb.19.1701983080991; Thu, 07 Dec 2023 13:04:40 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id sc4-20020a17090b510400b002868d090c27sm354680pjb.25.2023.12.07.13.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 13:04:40 -0800 (PST) Date: Thu, 7 Dec 2023 13:04:39 -0800 From: Kees Cook To: "Liam R. Howlett" Cc: Andrew Morton , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mark Brown , Naresh Kamboju , linux-kselftest@vger.kernel.org, Linux ARM , kft-triage@lists.linaro.org, regressions@lists.linux.dev, Will Deacon , Catalin Marinas , Dan Carpenter , Eric Biederman , linux-next@vger.kernel.org Subject: Re: [PATCH] maple_tree: Fix mas_prev() state separation code Message-ID: <202312071302.99D5B1BB76@keescook> References: <20231207014104.n6vul2ylgqjnsfia@revolve> <20231207193319.4025462-1-Liam.Howlett@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231207193319.4025462-1-Liam.Howlett@oracle.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 07 Dec 2023 13:04:54 -0800 (PST) On Thu, Dec 07, 2023 at 02:33:19PM -0500, Liam R. Howlett wrote: > mas_prev() was setting the ma_underflow condition when the limit was > reached and not when the limit was attempting to go lower. This > resulted in the incorrect behaviour on subsequent actions. > > This commit fixes the status setting to only set ma_underflow when the > lower limit is attempted to be decremented, and modifies the testing to > ensure that's the case. > > Signed-off-by: Liam R. Howlett Is this is related to the report[1] I forwarded? If so, please add these tags too: Reported-by: Linux Kernel Functional Testing Closes: https://lore.kernel.org/all/CA+G9fYs-j2FYZSFSVZj48mgoM9gQd4-7M2mu2Ez3D1DqDdW2bQ@mail.gmail.com/ [1] Thanks either way! -Kees > --- > > Andrew, > > This should be clean to squash into 7f79fdb1d94d7 ("maple_tree: separate > ma_state node from status.") which is currently in your mm-unstable > branch. > > Thanks, > Liam > > > lib/maple_tree.c | 16 ++++++++++++---- > lib/test_maple_tree.c | 9 +++++++-- > 2 files changed, 19 insertions(+), 6 deletions(-) > > diff --git a/lib/maple_tree.c b/lib/maple_tree.c > index 89f8d21602774..47f2a7a973852 100644 > --- a/lib/maple_tree.c > +++ b/lib/maple_tree.c > @@ -4432,6 +4432,9 @@ static void *mas_prev_slot(struct ma_state *mas, unsigned long min, bool empty) > mas->last = mas->index - 1; > mas->index = mas_safe_min(mas, pivots, mas->offset); > } else { > + if (mas->index <= min) > + goto underflow; > + > if (mas_prev_node(mas, min)) { > mas_rewalk(mas, save_point); > goto retry; > @@ -4452,15 +4455,15 @@ static void *mas_prev_slot(struct ma_state *mas, unsigned long min, bool empty) > if (unlikely(mas_rewalk_if_dead(mas, node, save_point))) > goto retry; > > - if (mas->index <= min) > - mas->status = ma_underflow; > > if (likely(entry)) > return entry; > > if (!empty) { > - if (mas_is_underflow(mas)) > + if (mas->index <= min) { > + mas->status = ma_underflow; > return NULL; > + } > > goto again; > } > @@ -4596,7 +4599,7 @@ static void *mas_next_slot(struct ma_state *mas, unsigned long max, bool empty) > if (unlikely(mas_rewalk_if_dead(mas, node, save_point))) > goto retry; > > - if (pivot >= max) { > + if (pivot >= max) { /* Was at the limit, next will extend beyond */ > mas->status = ma_overflow; > return NULL; > } > @@ -4611,6 +4614,11 @@ static void *mas_next_slot(struct ma_state *mas, unsigned long max, bool empty) > else > mas->last = mas->max; > } else { > + if (mas->last >= max) { > + mas->status = ma_overflow; > + return NULL; > + } > + > if (mas_next_node(mas, node, max)) { > mas_rewalk(mas, save_point); > goto retry; > diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c > index 15fbeb788f3ac..29185ac5c727f 100644 > --- a/lib/test_maple_tree.c > +++ b/lib/test_maple_tree.c > @@ -3294,8 +3294,8 @@ static noinline void __init check_state_handling(struct maple_tree *mt) > MT_BUG_ON(mt, mas.last != 0x1500); > MT_BUG_ON(mt, !mas_is_active(&mas)); > > - /* next:active ->active */ > - entry = mas_next(&mas, ULONG_MAX); > + /* next:active ->active (spanning limit) */ > + entry = mas_next(&mas, 0x2100); > MT_BUG_ON(mt, entry != ptr2); > MT_BUG_ON(mt, mas.index != 0x2000); > MT_BUG_ON(mt, mas.last != 0x2500); > @@ -3360,6 +3360,11 @@ static noinline void __init check_state_handling(struct maple_tree *mt) > MT_BUG_ON(mt, entry != ptr); > MT_BUG_ON(mt, mas.index != 0x1000); > MT_BUG_ON(mt, mas.last != 0x1500); > + MT_BUG_ON(mt, !mas_is_active(&mas)); /* spanning limit */ > + entry = mas_prev(&mas, 0x1200); /* underflow */ > + MT_BUG_ON(mt, entry != NULL); > + MT_BUG_ON(mt, mas.index != 0x1000); > + MT_BUG_ON(mt, mas.last != 0x1500); > MT_BUG_ON(mt, !mas_is_underflow(&mas)); > > /* prev:underflow -> underflow (lower limit) spanning end range */ > -- > 2.40.1 > -- Kees Cook