lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a3a6443f-2351-4e55-a12e-4d1f28ba7ca4@oracle.com>
Date: Fri, 2 May 2025 10:49:55 -0500
From: Mark Tinguely <mark.tinguely@...cle.com>
To: Zhiyu Zhang <zhiyuzhang999@...il.com>, mark@...heh.com, jlbec@...lplan.org,
        joseph.qi@...ux.alibaba.com, gregkh@...uxfoundation.org
Cc: ocfs2-devel@...ts.linux.dev, akpm@...ux-foundation.org,
        linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [External] : [PATCH] ocfs2: Fix potential ERR_PTR dereference in
 ocfs2_unlock_and_free_folios

On 5/2/25 10:37 AM, Zhiyu Zhang wrote:
> When allocation of a folio fails (e.g., -ENOMEM), ocfs2_write_begin_nolock()
> stores an ERR_PTR in wc->w_folios[i]. ocfs2_unlock_and_free_folios() later
> walks this array but only skips NULL entries, thus passing the error pointer
> to folio_unlock(), which eventually dereferences it in const_folio_flags and
> panics with BUG: unable to handle kernel paging request in const_folio_flags.
> 
> This patch fixes this issue by adding IS_ERR_OR_NULL() to filter both NULL
> and error entries before any folio operations.
> 
> Fixes: 7e119cff9d0a ("ocfs2: convert w_pages to w_folios")
> Reported-by: Zhiyu Zhang <zhiyuzhang999@...il.com>
> Closes: https://urldefense.com/v3/__https://lore.kernel.org/linux-fsdevel/CALf2hKtnFskBvmZeigK_=mqq9Vd4TWT*YOXcwfNNt1ydOY=0Yg@mail.gmail.com/T/*u__;KyM!!ACWV5N9M2RV99hQ!O2QZFrLv_PvhBiQH1Ak3ZDOIFOQG2RgkiOSogyy_3n0ZsLL_GXVwf0aiu7ti71LagUjWpF54NlvjjQP7IfPUT2vS0yY$
> Tested-by: Zhiyu Zhang <zhiyuzhang999@...il.com>
> Signed-off-by: Zhiyu Zhang <zhiyuzhang999@...il.com>
> ---
>   fs/ocfs2/aops.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
> index 40b6bce12951..9e500c5fee38 100644
> --- a/fs/ocfs2/aops.c
> +++ b/fs/ocfs2/aops.c
> @@ -760,7 +760,7 @@ void ocfs2_unlock_and_free_folios(struct folio **folios, int num_folios)
>   	int i;
> 
>   	for(i = 0; i < num_folios; i++) {
> -		if (!folios[i])
> +		if (IS_ERR_OR_NULL(folios[i]))
>   			continue;
>   		folio_unlock(folios[i]);
>   		folio_mark_accessed(folios[i]);
> --
> 2.34.1
> 
> 


yes, this was my bug in the folio port.
I submitted the patch with subject "ocfs2: fix panic in failed foilio 
allocation" as a solution.
In the old page allocation code, a NULL was the failed allocation. Folio 
returns an error code. the patch put the NULL back into the folio araay 
location:

  https://lore.kernel.org/ocfs2-devel/7de24670-89cc-4502-adbe-308bd5786f1d@linux.alibaba.com/T/#t


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ