Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp39175lfv; Tue, 12 Apr 2022 16:22:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMmHgJPSoZb5cWcy1LAgwJKyRPT1Ayt+Ut1HSYdkXy1bAIRBy8zccc6clQ9nvIHLVOLje4 X-Received: by 2002:a17:902:6943:b0:156:1d3c:1e0d with SMTP id k3-20020a170902694300b001561d3c1e0dmr38584052plt.76.1649805722273; Tue, 12 Apr 2022 16:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649805722; cv=none; d=google.com; s=arc-20160816; b=NDQUpJ03dHUega8yrJSfLMO0kFPNFkV1cIdTK0Gwele6sHz29rbQDYFgXUsBaoQfNP ZFAG0ziCu6JwQkAzCKgZs7b3h3RuMyiyYbSsKnTJX3Wvl4ne3zE8up3pQMhQIOEQ5IFs 68eU+NWvuG98v3HNzjLMotHfbjhriJxFAB5h1A+Z5opwYquSo43BXCsti/DUVf8xSVrn OHj2sl1/DYF3b8c4M8LhyGWnkPTKImh+3xgPjzwyK6+C+uU9GWy54vTOIBxoXe1n9NbC Z2aU3P0G/I7OgexfI7K3yDxFTy9HKkCMp0mfLfTRklkKj0V5OV/jMVRDs8L0F6guuLUD cjNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=zAXLaEZNyeZlv6FO3BLygA5GGTQy041zwLruD/Tl3og=; b=zf9AE+O2gTIf58ljHp5qsdrmM1yF7ajzxOsJNvgnZP+BhiXYWjsGaQpE/tRNY2MPzP fJPYSuLZuypoJf9kjMhT11dU+fymhBWRNKjAlAN/tgcBKGPkltduN5cTYvya+/2sWMfD eotfb/HmrXssL3tP/iG1+NMXqI0QPf40tsyFB+sOg+ZAAgN/bULp8PQYdEecM9jnh+P8 ZulpgRcbJG//EBwK0nFyw5JwcJNjFYDWQHk0eSiEW0JkMb/bJr6ELU4q/As1ZOG0tnLf EQJcG/mrmpHfGTaugrITfgUu9LcbcsdlFKeqPudgUEUjw+Q2NBx98VSNvQYuJ6jqc8r0 0IyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OD5yENxh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s37-20020a634525000000b003816043efa1si3683895pga.406.2022.04.12.16.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:22:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OD5yENxh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EF2FB19B0BE; Tue, 12 Apr 2022 14:13:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235976AbiDLK6X (ORCPT + 99 others); Tue, 12 Apr 2022 06:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355786AbiDLKyE (ORCPT ); Tue, 12 Apr 2022 06:54:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D6EB4830B for ; Tue, 12 Apr 2022 02:49:25 -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 ams.source.kernel.org (Postfix) with ESMTPS id C1152B81BBF for ; Tue, 12 Apr 2022 09:49:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21E2CC385A5; Tue, 12 Apr 2022 09:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649756962; bh=gYR2YBHwwyx9GaI6f6MK1uifVDe1QgQzsrtQ7laIKeU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=OD5yENxhrqinRZ28NRL3z3M2cXMflFjo7rdvdCtxSCxp424qOJ4xZBCXY7G3h7jan gFAvOtajyghA11u56CcEIv0q8QqJ+sukQWtvPmf4/5LJJFEv/d9j7s6d12Ol7j47FA bxc3w6gRwbsOI4teqsdV5BgoVZErwUPu5JEnsRVDJPo+fjAtKOdYqJWTv4b0lkLKt8 Kx/X43PP/NTMuNR/1iO2Xrmkx/vO+waCU6oeNucMOsDa8OMvV3v1l1gupRnFCNqS9K UlWSjoljm81z5ZemS8x2D9hsf+6S+sevNUTgv1TFLMgP5SXchUa9fiQYh5ZrwwZfcG AN+RmMmYdZXow== Message-ID: <8b62a788-d5ba-b244-d9f1-2edecba9769f@kernel.org> Date: Tue, 12 Apr 2022 17:49:17 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] f2fs: fix dereference of stale list iterator after loop body Content-Language: en-US To: Jakob Koschel , Jaegeuk Kim Cc: Yunlei He , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Mike Rapoport , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." References: <20220331223414.901960-1-jakobkoschel@gmail.com> From: Chao Yu In-Reply-To: <20220331223414.901960-1-jakobkoschel@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/4/1 6:34, Jakob Koschel wrote: > The list iterator variable will be a bogus pointer if no break was hit. > Dereferencing it (cur->page in this case) could load an out-of-bounds/undefined > value making it unsafe to use that in the comparision to determine if the > specific element was found. > > Since 'cur->page' *can* be out-ouf-bounds it cannot be guaranteed that > by chance (or intention of an attacker) it matches the value of 'page' > even though the correct element was not found. > > This is fixed by using a separate list iterator variable for the loop > and only setting the original variable if a suitable element was found. > Then determing if the element was found is simply checking if the > variable is set. > > Fixes: 8c242db9b8c0 ("f2fs: fix stale ATOMIC_WRITTEN_PAGE private pointer") > Signed-off-by: Jakob Koschel Reviewed-by: Chao Yu Thanks,