From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (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 578AB3B0AFE for ; Fri, 10 Apr 2026 08:59:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775811583; cv=none; b=OoEOzpxeqZnLd2n2Z5BJFCXE5Pzpkv4iaEWryR++iHXLFeC7cEob5Jv95ZTjarBn9/ArzORvHqTtvZ/wcaZpX8tKEeXcIyy1K6mlS619S2vJllDAJ79xPrXrGFqYcGtCyuLnMnvRbDIlFMEuR+GoCOLKfGN5vzfdIpgHwdgpCvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775811583; c=relaxed/simple; bh=gKm8j1L6ILnuyuH+DQR6v1gP0JsXLjRXvnvbIgMNhCc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AwkbMKYFkYgi7p/SADNuMVH3OcaXhQA4TlLlE0Kr+BFb7mtiqw6SgRkRzn/1Ge6lEjPWApsuJ7V6Sz98DFbYaD4YY0HOOGDOM8fO0FDMRhVEF904zE/ernFsupoIZw0tIlCB52ITo+V/BZoIP7HSY0ZIdjkL9auEf8ql3Nl3BjM= 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=VZtJLCM9; arc=none smtp.client-ip=115.124.30.130 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="VZtJLCM9" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1775811576; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=sLBoAw220Ntlzz3l6qGwv8yMQ3uBi7OQZXVrEWMuzGw=; b=VZtJLCM985tqpoP1bxUoCz0WcLYe7CPJuVP96jdsSeBk+rlOvWxICyaCcLxzYaqibYEJSTOaNzln3DQ3tu53kRfN/qQfTTWQAYrF7a4aCyruF+nBQt+h/QioEUDHs5KN8OAxXGpDb+ke0RpUpUN2H07E7NQUfD6U9eqCLFLTwwY= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0X0kq3Lr_1775811575; Received: from 30.221.132.105(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0X0kq3Lr_1775811575 cluster:ay36) by smtp.aliyun-inc.com; Fri, 10 Apr 2026 16:59:36 +0800 Message-ID: <181cfc04-1147-483f-b56f-b6b0119803cf@linux.alibaba.com> Date: Fri, 10 Apr 2026 16:59:34 +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 , Chao Yu , Yue Hu , Jeffle Xu , Sandeep Dhavale , Hongbo Li , Sheng Yong References: <4a2f3801-fac1-42fe-ae75-da315822e088@salutedevices.com> <31735f62-2008-4898-b548-0d546efb9120@salutedevices.com> From: Gao Xiang In-Reply-To: <31735f62-2008-4898-b548-0d546efb9120@salutedevices.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026/4/10 16:51, Arseniy Krasnov wrote: > > > 10.04.2026 11:42, Gao Xiang wrote: >> >> >> On 2026/4/10 16: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. >> >> btw, is that an unmodified upstream kernel "6.15.11-sdkernel"? >> Currently I never heard Android phone vendors using 6.12 LTS >> for example hit this. If it can easily reproduced, is it >> possible to reproduce with the upstream kernel? > > Yes, this is just upstream kernel, no vendor modifications. It is not android, just > buildroot. I know, I mean for buildroot workloads, it should be less pressure since it's just for embeded use. > >> >> And is the "0xffff000002b32468" pointer a valid pointer? what >> does it point to? If it looks erofs pointer, the only one I >> can think out is "struct z_erofs_pcluster", if it's not the >> case, I think there should be other thing wrong if the kernel >> is modified. > > Yes, this is valid pointer, need to check about that pointer. I'll feedback here. Anyway, if z_erofs_decompress_queue->erofs_onlinefolio_end() is called: - the folio should be locked, and folio->private should not be a pointer; - it seems `PG_Private` is set on the problematic folio (otherwise try_to_free_buffers() won't be called), which is unexpected too. So what I need for some further analysis are: - the folio structure (folio flags, mapping, index, count, etc.); - what does folio->private point to? Also is it possible I could get the memory dump if possible? Not quite sure if it's possible in buildroot environment. Thanks, Gao Xiang > > Thanks > >> >>> >>> Thanks, >>> Gao Xiang