From patchwork Fri May 24 00:54:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13672594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D674FC25B7C for ; Fri, 24 May 2024 00:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=exqTBFail2wnYgsksTshTuBaJAhAb5oJMuvf6DquP5M=; b=Kx0Pmm7p7/74h5 /k0uprfnjBUi66lG7pUVxSoMUWuneOojgeJ3VYyKw+F6uJnRrtmWuczmK1e38kIj+sfb6xAlop6vc Piv4TpcMnEXI3WDXYBMvHla+MKStGKFbdguE0i6bujqsjE72RrRICQ2G22bPpNqdl/u9KXcB47Peo oZV3nlvftoE5woVZGqDaLdfK2yYerNeSasKuW631ZBj256ZjinuvWNp+lTqTxrJi35yVX70ZtRdr+ 0xmvUo6eYgtN2+mnwtrox7h5O3AvO4KcMM1bDJsENrppZ+RK4tLY6TPdjFRdczx2Rti8+eySVqqBM lnBJuR44weJLVwZO7BQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sAJDB-00000007joS-3epD; Fri, 24 May 2024 00:55:09 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sAJD9-00000007jnQ-3gr8 for linux-arm-kernel@lists.infradead.org; Fri, 24 May 2024 00:55:09 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6f8eba8f25eso332809b3a.3 for ; Thu, 23 May 2024 17:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716512103; x=1717116903; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=btdOk87mswYXidZeRThBlXVYcnXj0Y1fcw2iEYiTWQ4=; b=R10jKhaELnb1pBQFHQ4es695qXJABCl8z5j0oGGxNjsdmMvQv6cNh3pi94P7MxsvE6 iQbDiinXqRZZ06zx9CiV3vZxktpFEvntWfYc7Of+0u/GOMLhC5S0A5JIAD5R8NaQZsCg omafa4N/+b+nB4F430JKDmPGGZMIATkD7KZTjz/mdOpmP/I4mj1LsXdkd8W6dqfOctR0 yxQVEgKzqGwdDa17pNIeB1ncCTwvdu3EZ+qIckdYcMW7XfKhZk0T/f2W9sxRcrrxh5Ho dhsWgDBHCLR8+Y7teeUlcfu5ygGUe9CHgLBd0xhGD5o79scA2hcKZezgN9KNyLbRv77b monA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716512103; x=1717116903; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=btdOk87mswYXidZeRThBlXVYcnXj0Y1fcw2iEYiTWQ4=; b=IYHCY1GUEFmEP9ZPkELR68peFatRZHiU+6w1CFSnCdoFX67JYIa34TCG6HX8n9N33F ANAJd2yYwZARaOjccHKHbV9YMroBuqjjKWOcuoiuk4t+0p/07k6PwGMUjNffUpaErs2v PywcI9UnHXez7ChS5OWZGCd7MFDNGhazVBYNL0pa/EiHn9sbAgHdE6MR+zrPHgmK0TeG Fl0Aboe0hHqalUrP/RQ1TTYElCTLZB6qomZE8vMtpR4Ag6//ttKA5nzfoYDAreeXGESJ 8tIqXyGcyxDUJAlHqwQT8uP+c/WaNyXF0EpC5uQ89XId4q2TCeLX1fZ6g4ARqljzt9pn ba8w== X-Gm-Message-State: AOJu0Yxa6i8FcjY3Hj71oHlSsYWbK7kEJdtO/o6wrg5H/KIPo6idRjW2 7bzToc6tAputfHH3EhNnYsmfssx89SEW8snkboTmdWty4rl0GONa X-Google-Smtp-Source: AGHT+IFvwAGrb1aoG1lN2VJQK7/vDKkqVmBwD8ukAXrSTWGhK6vhiW+LH9ZzbgawCxVlb6aETJ7N1w== X-Received: by 2002:a05:6a20:9684:b0:1af:aeaa:6db4 with SMTP id adf61e73a8af0-1b212f19e21mr994255637.47.1716512103027; Thu, 23 May 2024 17:55:03 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c9c9065sm1881425ad.280.2024.05.23.17.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 17:55:02 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Barry Song , Lance Yang , Barry Song <21cnbao@gmail.com>, Ryan Roberts , David Hildenbrand , Jeff Xie , Kefeng Wang , Michal Hocko , Minchan Kim , Muchun Song , Peter Xu , Yang Shi , Yin Fengwei , Zach O'Keefe , Catalin Marinas , Will Deacon Subject: [PATCH] mm: arm64: Fix the out-of-bounds issue in contpte_clear_young_dirty_ptes Date: Fri, 24 May 2024 12:54:44 +1200 Message-Id: <20240524005444.135417-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240523_175507_967870_CB5187E0 X-CRM114-Status: GOOD ( 12.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Barry Song We are passing a huge nr to __clear_young_dirty_ptes() right now. While we should pass the number of pages, we are actually passing CONT_PTE_SIZE. This is causing lots of crashes of MADV_FREE, panic oops could vary everytime. Fixes: 89e86854fb0a ("mm/arm64: override clear_young_dirty_ptes() batch helper") Cc: Lance Yang Cc: Barry Song <21cnbao@gmail.com> Cc: Ryan Roberts Cc: David Hildenbrand Cc: Jeff Xie Cc: Kefeng Wang Cc: Michal Hocko Cc: Minchan Kim Cc: Muchun Song Cc: Peter Xu Cc: Yang Shi Cc: Yin Fengwei Cc: Zach O'Keefe Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Barry Song Reviewed-by: Baolin Wang Acked-by: Lance Yang Acked-by: David Hildenbrand Acked-by: Chris Li Reviewed-by: Mark Rutland Tested-by: Mark Rutland --- arch/arm64/mm/contpte.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c index 9f9486de0004..a3edced29ac1 100644 --- a/arch/arm64/mm/contpte.c +++ b/arch/arm64/mm/contpte.c @@ -376,7 +376,7 @@ void contpte_clear_young_dirty_ptes(struct vm_area_struct *vma, * clearing access/dirty for the whole block. */ unsigned long start = addr; - unsigned long end = start + nr; + unsigned long end = start + nr * PAGE_SIZE; if (pte_cont(__ptep_get(ptep + nr - 1))) end = ALIGN(end, CONT_PTE_SIZE); @@ -386,7 +386,7 @@ void contpte_clear_young_dirty_ptes(struct vm_area_struct *vma, ptep = contpte_align_down(ptep); } - __clear_young_dirty_ptes(vma, start, ptep, end - start, flags); + __clear_young_dirty_ptes(vma, start, ptep, (end - start) / PAGE_SIZE, flags); } EXPORT_SYMBOL_GPL(contpte_clear_young_dirty_ptes);