From nobody Sat Feb 7 05:14:58 2026 Received: from unicom146.biz-email.net (unicom146.biz-email.net [210.51.26.146]) (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 A0F8B22D785 for ; Wed, 31 Dec 2025 05:57:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.51.26.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767160680; cv=none; b=QuTgbaGRp7wvRCsqFpqN08h8rttkECmDItPEATEjnXL7mC5mnizkW90yHXhfqeFeaC3zjrPU5QFE+1dnkvh4z7tCilnZudv2PcBfmfrvV9ct/vbE4o15Q4qnZpOoISu4AzGT2SedhaW7xv+w1NEicPQzlYjiXLbjHRbT1bc52gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767160680; c=relaxed/simple; bh=AmEhnRvmuFlx6G2l+VaLG9z/h+rQa1omHtCi/8RYxrc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=i2+GODpKU/RTO9vHrUSmYorejeWMPR72eQzu5SzHXrEco93yIILGpOwXiUp3x6/UfkwT4yNb7yP8TFvNQQgwlm7U/FkHBVEILxhbnNQaajW6/I17yE/X4LmhK2KY9S8UYU0/bUZOGhrRT4QL4CfROvV4VPjwlbQldfMsHZxp9nk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=inspur.com; spf=pass smtp.mailfrom=inspur.com; arc=none smtp.client-ip=210.51.26.146 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=inspur.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inspur.com Received: from inspur.com by unicom146.biz-email.net ((D)) with ESMTP id 202512311357429751 for ; Wed, 31 Dec 2025 13:57:42 +0800 Received: from anolis.. (unknown [10.94.11.57]) by app9 (Coremail) with SMTP id cQJkCsDwbvhWu1RpD60NAA--.27572S2; Wed, 31 Dec 2025 13:57:43 +0800 (CST) From: Aaron Yang To: sj@kernel.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, Aaron Yang Subject: [PATCH v1] mm/damon/pa: initialize 'folio' to NULL to prevent use of uninitialized value Date: Wed, 31 Dec 2025 13:57:37 +0800 Message-ID: <20251231055737.73325-1-yangqixiao@inspur.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: cQJkCsDwbvhWu1RpD60NAA--.27572S2 X-Coremail-Antispam: 1UD129KBjvJXoW7KFy7Kw4UGFykuFWrKFWfZrb_yoW8Ww4xp3 WxG34kKrWUtrWkuw1DXF4xZry5u3y3GF9IkFWfGFyvkanIqw1kKw12y3Waqr1UZrWUWF1f Zr40q3y7XFn8CaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkm14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26rxl 6s0DM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkF7I0En4kS14v26r12 6r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI 0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y 0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1l IxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUehL0UUUUU X-CM-SenderInfo: 51dqw15l0lt0o6lq211xuou0bp/ tUid: 202512311357424a74c73258332d6bb6c345215257ab0e X-Abuse-Reports-To: service@corp-email.com Abuse-Reports-To: service@corp-email.com X-Complaints-To: service@corp-email.com X-Report-Abuse-To: service@corp-email.com In damon_pa_mark_accessed_or_deactivate(), the local variable 'folio' is declared but not initialized. If the region [r->ar.start, r->ar.end) is empty or invalid such that the while-loop body is never entered, 'folio' retains an indeterminate (garbage) value. The function then unconditionally assigns this uninitialized pointer to s->last_applied (line 239), resulting in undefined behavior. Subsequent dereference or folio_put() on s->last_applied may cause crashes or memory corruption. Although DAMON regions are typically non-empty, zero-length regions can arise during region merging/splitting or due to address unit alignment =E2=80=94 making this path reachable in practice. Fix by initializing 'folio' to NULL. Assigning NULL to s->last_applied is safe and semantically correct: it cleanly indicates "no folio was processed in this invocation", and callers are expected to check for NULL before use (as per common kernel practice). No functional change for non-empty regions; only hardens error/edge case handling. Signed-off-by: Aaron Yang --- mm/damon/paddr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 07a8aead439e..32d8024d130e 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -212,7 +212,7 @@ static inline unsigned long damon_pa_mark_accessed_or_d= eactivate( unsigned long *sz_filter_passed) { phys_addr_t addr, applied =3D 0; - struct folio *folio; + struct folio *folio =3D NULL; =20 addr =3D damon_pa_phys_addr(r->ar.start, addr_unit); while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) { --=20 2.47.3