Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7778576rwi; Mon, 24 Oct 2022 20:39:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7RlHywHnQ7PpsXN8cr2NuMv5kSRHmtaHwDK7JyRoEKjV7WydapfOC5ahKtXTy0QjiruWaF X-Received: by 2002:a17:907:8a24:b0:795:bb7d:643b with SMTP id sc36-20020a1709078a2400b00795bb7d643bmr24874004ejc.115.1666669178419; Mon, 24 Oct 2022 20:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666669178; cv=none; d=google.com; s=arc-20160816; b=FaH7kUc/ua/BK+48betA+IwtCx7dWH+m6Dw/jTsCZ8rdsopljVataXJfDGCxl7+iAI pC4EmHhare4cAk41lJGxe1t5I+T3EEq+a/rjIh9FaL/FTydLEKObG78hzRrISdNGx6fB WHOYFZd4oHJIxc5EspyX8sMumKLF8kwRggGwufOAlDVoltb+GSAx5kmJsg/jKfaZyeUx 720l6DneA0VaG1N4eylRQDilrF/0fpDigYCfDOgKYIY0H0Z3pkZ9V9vsnKcPTNjB599g 5/Rz/VeqkaQzbL0jumm5wFTtAK+fcUTOd1ADExqdoo9SsBYyJ9u7qujPpdyt9mvpHBw5 5uTw== 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=VNzP4Xv7xwYTjGZmtlINfnMVktn7kgzmYkLuvvsCYUo=; b=meZr3/r6SKZzqCY6UhxeB1tLB/OAY9tSOgOWYQxPPMby2QfhCAosPHqJed2Y8xpWgV B06VUXC5GTy4gqWJakwA2oqsiFVSMxwZbKck6iqSHh5KDirLxikkq0ZXCseCyyvXR+K/ YtqMtoNkdi7WfXGRRu5acQwGFzH+nKk8UXdukAuUeFBjrexjM0a3zTPgXO1UVHDf0lWC awMEUcbDBR3ew5ftynZM2ESfP+fsLvJ+5AJN7XGH77zgYSgBpn5UK/LjSkPMlpOCJJVr tER7OoDhuJolLG/218U6iHQt1jIMv4bbkrFp3rGAmkp5xQdwB072Y2G3pF93X3n+SHAm Kdpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ge6F4ay+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170906794f00b00791a67e4c00si1846223ejo.835.2022.10.24.20.39.14; Mon, 24 Oct 2022 20:39:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ge6F4ay+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230476AbiJYCyC (ORCPT + 99 others); Mon, 24 Oct 2022 22:54:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231411AbiJYCxs (ORCPT ); Mon, 24 Oct 2022 22:53:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 524041211E1; Mon, 24 Oct 2022 19:53:45 -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 AD695616E6; Tue, 25 Oct 2022 02:53:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98A31C433C1; Tue, 25 Oct 2022 02:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666666424; bh=bgoqEEDvEzhJrh/4G88Q8OoiwieqsueEejZQ94ELqxM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Ge6F4ay+H3GfgnTrjb10k9mDv43jrwM/QSF6PXQSHbhGJPX5IMdTqcg1R3ndDvaiH MSavLeGVgqF5W6+GA6VgZwYTRqdfS4T9wIwwQZPKFvz1a47zG1wBLkYQ1kSzp1Obgn JlP/PDnAOOHusRrXQw/plpAvcVt8tqWFWdwspEGLjXTUeiiHeHGa7Mk9zHY30qdr5v FlOuicsgsX3HNnjz2F2LaRMm+gnyo9GvI9DNoTn9OaOl1oAyzUbKujnkaSzsYoUJIJ giaH18pI9jgEco/0K5QGVRxbqKgxxcPzESk2IzsbNdDxRHVp0+4ngj0WZf41IfnSUI Q0wcDytvVODqw== Message-ID: <1b9d6a6d-4e19-f455-bf9a-659b85a3206f@kernel.org> Date: Tue, 25 Oct 2022 10:53:40 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH 5.10 052/390] f2fs: fix to do sanity check on summary info Content-Language: en-US To: Pavel Machek , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Wenqing Liu , Jaegeuk Kim References: <20221024113022.510008560@linuxfoundation.org> <20221024113024.853480982@linuxfoundation.org> <20221024173012.GA25198@duo.ucw.cz> From: Chao Yu In-Reply-To: <20221024173012.GA25198@duo.ucw.cz> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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/10/25 1:30, Pavel Machek wrote: > Hi! > >> From: Chao Yu >> >> commit c6ad7fd16657ebd34a87a97d9588195aae87597d upstream. >> >> As Wenqing Liu reported in bugzilla: >> >> https://bugzilla.kernel.org/show_bug.cgi?id=216456 >> >> BUG: KASAN: use-after-free in recover_data+0x63ae/0x6ae0 [f2fs] >> Read of size 4 at addr ffff8881464dcd80 by task mount/1013 > > I believe this is missing put_page on the error path: > >> +++ b/fs/f2fs/gc.c >> @@ -1003,6 +1003,14 @@ static bool is_alive(struct f2fs_sb_info >> return false; >> } >> >> + max_addrs = IS_INODE(node_page) ? DEF_ADDRS_PER_INODE : >> + DEF_ADDRS_PER_BLOCK; >> + if (ofs_in_node >= max_addrs) { >> + f2fs_err(sbi, "Inconsistent ofs_in_node:%u in summary, ino:%u, nid:%u, max:%u", >> + ofs_in_node, dni->ino, dni->nid, max_addrs); >> + return false; >> + } >> + >> *nofs = ofs_of_node(node_page); >> source_blkaddr = data_blkaddr(NULL, node_page, ofs_in_node); >> f2fs_put_page(node_page, 1); > > So something like this is needed. (Feel free to test/adapt/apply). > > Signed-off-by: Pavel Machek > > Best regards, > Pavel > > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c > index 4546e01b2ee0..dab794225cce 100644 > --- a/fs/f2fs/gc.c > +++ b/fs/f2fs/gc.c > @@ -1110,6 +1110,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, > if (ofs_in_node >= max_addrs) { > f2fs_err(sbi, "Inconsistent ofs_in_node:%u in summary, ino:%u, nid:%u, max:%u", > ofs_in_node, dni->ino, dni->nid, max_addrs); > + f2fs_put_page(node_page, 1); > return false; > } My bad, thanks for fixing this. Reviewed-by: Chao Yu Thanks, > >