Re: [PATCH 2/2] ocfs2/dlm: fix off-by-one in dlm_match_regions() region comparison
From: Joseph Qi
Date: Wed Mar 18 2026 - 01:57:09 EST
On 3/7/26 3:21 PM, Junrui Luo wrote:
> The local-vs-remote region comparison loop uses '<=' instead of '<',
> causing it to read one entry past the valid range of qr_regions. The
> other loops in the same function correctly use '<'.
>
> Fix the loop condition to use '<' for consistency and correctness.
>
> Fixes: ea2034416b54 ("ocfs2/dlm: Add message DLM_QUERY_REGION")
> Reported-by: Yuhao Jiang <danisjiang@xxxxxxxxx>
> Signed-off-by: Junrui Luo <moonafterrain@xxxxxxxxxxx>
Reviewed-by: Joseph Qi <joseph.qi@xxxxxxxxxxxxxxxxx>
> ---
> fs/ocfs2/dlm/dlmdomain.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ocfs2/dlm/dlmdomain.c b/fs/ocfs2/dlm/dlmdomain.c
> index 0a28cb5ded2a..dc9da9133c8e 100644
> --- a/fs/ocfs2/dlm/dlmdomain.c
> +++ b/fs/ocfs2/dlm/dlmdomain.c
> @@ -1002,7 +1002,7 @@ static int dlm_match_regions(struct dlm_ctxt *dlm,
> for (i = 0; i < localnr; ++i) {
> foundit = 0;
> r = remote;
> - for (j = 0; j <= qr->qr_numregions; ++j) {
> + for (j = 0; j < qr->qr_numregions; ++j) {
> if (!memcmp(l, r, O2HB_MAX_REGION_NAME_LEN)) {
> foundit = 1;
> break;
>