Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3307064rwb; Mon, 5 Sep 2022 09:24:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR70ggo7V6HOb1Cp8y1W8pPVd1OK3OqTOC3rLNMBwJ37ryCwgaPx03uWp/FOiIKvmRBfO35Q X-Received: by 2002:a63:83c6:0:b0:42b:bb27:91a4 with SMTP id h189-20020a6383c6000000b0042bbb2791a4mr35588901pge.61.1662395048550; Mon, 05 Sep 2022 09:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662395048; cv=none; d=google.com; s=arc-20160816; b=XBZbhCHbHuso3H1i3r7581gtEDKSP+5LoBSCE85eNk9+LITTFo4Zux6ghrRpFoNA2Q OMnd5dGNjWCCnvRVNbBuCmUuRS/yaZyA5QfCxGJIJtM2sE22MK9Da6kWs/4Ze5Gk+H9M DDvEjiubNdMUVZVziBP/tNc2H/V494NrvNzHk0ANBtH14Fwz+jPuPg5/4AcsBFyjswEF LuOi+JLi3dBgEJFyjoijm41gu9tmsXGycY2prEKHmRSVwmCA3CH8GYG11Jq1Bz6DGHwB qf13EV+ykLTRAekBFyP6vhTkjvj1wgcHL3SY/Wt4u9oNYXF0dvQfW44dxJKgfau/rmOy TUIg== 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=/NX4s/aAyIMeIyZErgl55P0ixTErF3LNbMteGJL8rZ0=; b=dcqlpHh/irhbKNdhP4UDbtKCMwijkq8rL/wFBBqYtKMkn+gPKgFNbTc3tOhntyVtH1 0gI3QdJaKSTjNk0Bbw58P41b5+FPUmFIcAuUSo1VHDKOBOtNAikHOhLOGBqO1rc+DLTR 6yghh1rdDR6fOieWyq5VCWB75TuKLuncyzfVBgKq8aZj23qT/4+FnUL7C/Tv63C8WlmD 2mJ1D+IHB7AUbPh2OaTZt8UJ/hlKfELm0J5n51oLT5dV8jckzXKPtJaKhGUxQ0mXhFjd YXgy+FwUjsZHg4IxM9EePfnqyMErRNFcJLK8J6nOLSWy8qTP57eu9Lfc7HJCwOjPmy0f Iomw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gy66a6AZ; 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 q1-20020a170902dac100b001725e847c6asi113751plx.302.2022.09.05.09.23.56; Mon, 05 Sep 2022 09:24:08 -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=gy66a6AZ; 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 S238719AbiIEPOs (ORCPT + 99 others); Mon, 5 Sep 2022 11:14:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238752AbiIEPOi (ORCPT ); Mon, 5 Sep 2022 11:14:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E6B6B7D9 for ; Mon, 5 Sep 2022 08:14:32 -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 1D9B160F5B for ; Mon, 5 Sep 2022 15:14:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75EE3C433C1; Mon, 5 Sep 2022 15:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662390870; bh=CP4NcXDfCymQFvUZRnFGWcms/v7Hz+fmcT03tOXmkiM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=gy66a6AZYzpOdaqzupomz3qx4JCM+cE1iAPogPai1oyAvfMtl5IP+1KCgOMuFyL9f O4lgmpBdLCe6YrtNCpoHV1V9pPS4xlY9MFw/lZnNXRG7v+Jn53Lz3+0eKI0JhDe6Sl bjjdMG3jAVE1SH62Y8+epSUV4Omo0HLQkrwXmgx1sBxnhIb51OfFhoLcyjHGdiPOEn Ip+XDgX5jtQyz4gpVhqmMVm3xh2e76zsbVsMtJpYdnMAGgnhUpZCK+QhgoOFkr1JLl a2Bx0UKJBVrjnJIeaxSvUXC83FJUemak9Xy7j62FG7WNe6MZqwlghAx34S+G53YwuC DRwaqnj7pJohw== Message-ID: <977a4e45-43e7-485e-fb31-7fd0754f888d@kernel.org> Date: Mon, 5 Sep 2022 23:14:30 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH] erofs: fix pcluster use-after-free on UP platforms Content-Language: en-US To: Gao Xiang , linux-erofs@lists.ozlabs.org Cc: LKML References: <20220902045710.109530-1-hsiangkao@linux.alibaba.com> From: Chao Yu In-Reply-To: <20220902045710.109530-1-hsiangkao@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.8 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,T_SCC_BODY_TEXT_LINE 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/9/2 12:57, Gao Xiang wrote: > During stress testing with CONFIG_SMP disabled, KASAN reports as below: > > ================================================================== > BUG: KASAN: use-after-free in __mutex_lock+0xe5/0xc30 > Read of size 8 at addr ffff8881094223f8 by task stress/7789 > [ 3482.258885] > CPU: 0 PID: 7789 Comm: stress Not tainted 6.0.0-rc1-00002-g0d53d2e882f9 #3 > Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 > Call Trace: > > .. > __mutex_lock+0xe5/0xc30 > .. > z_erofs_do_read_page+0x8ce/0x1560 > .. > z_erofs_readahead+0x31c/0x580 > .. > Freed by task 7787 > kasan_save_stack+0x1e/0x40 > kasan_set_track+0x20/0x30 > kasan_set_free_info+0x20/0x40 > __kasan_slab_free+0x10c/0x190 > kmem_cache_free+0xed/0x380 > rcu_core+0x3d5/0xc90 > __do_softirq+0x12d/0x389 > [ 3482.295630] > Last potentially related work creation: > kasan_save_stack+0x1e/0x40 > __kasan_record_aux_stack+0x97/0xb0 > call_rcu+0x3d/0x3f0 > erofs_shrink_workstation+0x11f/0x210 > erofs_shrink_scan+0xdc/0x170 > shrink_slab.constprop.0+0x296/0x530 > drop_slab+0x1c/0x70 > drop_caches_sysctl_handler+0x70/0x80 > proc_sys_call_handler+0x20a/0x2f0 > vfs_write+0x555/0x6c0 > ksys_write+0xbe/0x160 > do_syscall_64+0x3b/0x90 > > The root cause is that erofs_workgroup_unfreeze() doesn't reset > to orig_val thus it causes a race that the pcluster reuses unexpectedly > before freeing. > > Since UP platforms are quite rare now, such path becomes unnecessary. > Let's drop such specific-designed path directly instead. > > Fixes: 73f5c66df3e2 ("staging: erofs: fix `erofs_workgroup_{try_to_freeze, unfreeze}'") > Signed-off-by: Gao Xiang Reviewed-by: Chao Yu Thanks,