From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8112C3E0C48 for ; Fri, 10 Apr 2026 12:21:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775823668; cv=none; b=Hh0J9Y/ffDZ3Sp01wBNFEoTw9D+Kpgr7HkIA3wgRviClapozV4Ki1YZSv1hzDHsZ4AgtuRIRscKRiNsmQBO0lEm3HPbcboCntM8fGG5M0uMuCgInu2l339b4NKuwPoc2E3nhfkkzZO/Od0xZ7jsa+AZGW6fAXaAp23MY4uBFqY4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775823668; c=relaxed/simple; bh=F/8AVZ2CbgyFNC1p5AHU8lPzxu8NMIDsvRDLHhDUNJw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AvZ3LHoUdvwxTtBGcV/LJueTNDC0irfvJNwQunVPZ1jkGLCBwQo6zL4nzrDh5rFubPUy7iEwMsry713hLdO8CSTs/5neD89LbaBjEyRIt5SRO116q7nE6F6yUtqcNBJhyFs1WxNIc+YhGVvYsAodIXxSwnMXM4BAN8eHxN3mxi0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ot3Jb3/R; arc=none smtp.client-ip=115.124.30.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ot3Jb3/R" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1775823661; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=7jd40Vyoz/C8/8hlu3IWoHDYU/k9DOsf7STa3E9MOI8=; b=ot3Jb3/RBBhDfKXUjgZar7PzRfLw10k36hWPwsWTmx7vD5oKbVqIeIYG1PaMtgzy6LwPtN1RwcOdoMYvfVBK0LWQKgLp/9kW9fv/vhh9zmUvfFO9gBneyznKrc2ErPBSGYOyleCQWuTew4LYo+6WCydZHSKZ89ysFGFSGFnzdaA= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032089153;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0X0lGJnj_1775823660; Received: from 30.41.54.139(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0X0lGJnj_1775823660 cluster:ay36) by smtp.aliyun-inc.com; Fri, 10 Apr 2026 20:21:00 +0800 Message-ID: Date: Fri, 10 Apr 2026 20:20:59 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: erofs pointer corruption and kernel crash To: Arseniy Krasnov Cc: oxffffaa@gmail.com, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, kernel@salutedevices.com, Gao Xiang References: <4a2f3801-fac1-42fe-ae75-da315822e088@salutedevices.com> <2e916997-0557-45e7-831a-b436c07c5ba4@salutedevices.com> From: Gao Xiang In-Reply-To: <2e916997-0557-45e7-831a-b436c07c5ba4@salutedevices.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026/4/10 19:37, Arseniy Krasnov wrote: (drop unrelated folks since they all subscribed erofs mailing list) > > > 10.04.2026 11:31, Gao Xiang wrote: >> Hi, >> >> On 2026/4/10 16:13, Arseniy Krasnov wrote: >>> Hi, >>> >>> We found unexpected behaviour of erofs: >>> >>> There is function in erofs - 'erofs_onlinefolio_end()'. It has pointer to >>> 'struct folio' as first argument, and there is loop inside this function, >>> which updates 'private' field of provided folio: >>> >>>    do { >>>            orig = atomic_read((atomic_t *)&folio->private); >>>            DBG_BUGON(orig <= 0); >>>            v = dirty << EROFS_ONLINEFOLIO_DIRTY; >>>            v |= (orig - 1) | (!!err << EROFS_ONLINEFOLIO_EIO); >>>    } while (atomic_cmpxchg((atomic_t *)&folio->private, orig, v) != orig); >>> >>> Now, we see that in some rare case, this function processes folio, where >>> 'private' is pointer, and thus this loop will update some bits in this >>> pointer. Then later kernel dereferences such pointer and crashes. >>> >>> To catch this, the following small debug patch was used (e.g. we check that 'private' field is pointer): >>> >>> diff --git a/fs/erofs/data.c b/fs/erofs/data.c >>> index 33cb0a7330d2..b1d8deffec4d 100644 >>> --- a/fs/erofs/data.c >>> +++ b/fs/erofs/data.c >>> @@ -238,6 +238,11 @@ void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty) >>>   { >>>       int orig, v; >>>   +    if (((uintptr_t)folio->private) & 0xffff000000000000) { >> >> No, if erofs_onlinefolio_end() is called, `folio->private` >> shouldn't be a pointer, it's just a counter inside, and >> storing a pointer is unexpected. >> >> And since the folio is locked, it shouldn't call into >> try_to_free_buffers(). >> >> Is it easy to reproduce? if yes, can you print other >> values like `folio->mapping` and `folio->index` as >> well? >> >> I need more informations to find some clues. > > > > So reproduced again with this debug patch which adds magic to 'struct z_erofs_pcluster' and prints 'struct folio' > when pointer in 'private' is passed to 'erofs_onlinefolio_end()'. In short - 'private' points to 'struct z_erofs_pcluster'. First, erofs-utils 1.8.10 doesn't support `-E48bit`: only erofs-utils 1.9+ ship it as an experimental feature, see Changelog; so I think you're using modified erofs-utils 1.8.10: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/tree/ChangeLog ``` erofs-utils 1.9 * This release includes the following updates: - Add 48-bit layout support for larger filesystems (EXPERIMENTAL); ``` Second, I'm pretty sure this issue is related to experimenal `-E48bit`, and those information is not enough for me to find the root cause, so I need to find a way to reproduce myself: It may take time; you could debug yourself but I don't think it's an easy task if you don't quite familiar with the EROFS codebase. Anyway I really suggest if you need a rush solution for production, don't use `-E48bit + zstd` like this for now: try to use other options like `-zzstd -C65536 -Efragments` instead since those are common production choices. Thanks, Gao Xiang