Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp250669lqb; Thu, 23 May 2024 17:55:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX7xS1vZZ/2sUzORPFDcr9GsgLrVHyphFKLdlUl4sEvDk1NU0f6kVCzq9Ti6dRnCt4nK/1QOHmrMLQCRWY+XV1eU0Ch6QhZXU02vx7JPQ== X-Google-Smtp-Source: AGHT+IFO9/vSlaEJgzWsWL83+LNHOieuXOVaGNo1FXwK7lsOkIH32BZ3T+4RRYFHLL2y7a8XM9nx X-Received: by 2002:a17:902:da88:b0:1f2:fc05:c179 with SMTP id d9443c01a7336-1f4497e5a29mr11089465ad.47.1716512110839; Thu, 23 May 2024 17:55:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716512110; cv=pass; d=google.com; s=arc-20160816; b=CAOamZe9/tGg6GqUqDLQz0LpqErxV5PrWDhX1Jdv4sy7rXbLbN5mCkHALEyrIO2t/8 o/norlPhVu7RpdiBsnfM137TzZEuM90hGw12Zsiom5INRgBExda2gAEtjXi/o0XE31El dK3Av+xzHwLmM1Aex/qxnkxkTGu/7ZsxPhlchQYyGvZ1XF9y1/SaNxCidCdH+pK1Gfy+ Mq08BAk5kf+HzEb8SMEWHcDrE6waX9XKDRkX+Ea/IYQhv4HjySxd2cuFot8fVTPgtDb5 /p1nQ0oxmPH2qeAzozSg3zZwTzRvCNrH+XLOQaRa9ePnAz4YrPzqyezpoh7wq6h9e/30 PuFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=btdOk87mswYXidZeRThBlXVYcnXj0Y1fcw2iEYiTWQ4=; fh=okjiEB6IpwwX0NthwEC8CUJOh2CgfCXEyUgjMHi6TcU=; b=krI2Rluab7E5zcyHnTA57AwI4uev2SOj/rXeguldzOfKbKHQbu4FoBDYWLzn8Wxvk0 Lc0jIhlvIgAMAShAXeiVbfDV5kVnd8qj8HcGjw8tlACUM8FFG2nSt8VBCRu2SNeKS1lN bcJ0j4XYc3DbDCwRy6tVhGUxir+r9lE2jy2joFXc4TqSoYyalmKgwrgrna5omgW3jcKO LpFgBHDGDBHttCXI+8yhUVbbH7uCpr1C1unioGhGWr83k3/llCduAw4JHpX2C3VCE6Mm Bqdc6gCv22KypWD0GVtnMov8n0kMaQNSQs2ukjYziEFfl/yDTciEDCUGr6kNEBytUl/Q dLUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bC3bwDM6; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-188191-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188191-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c9733c3si2911655ad.320.2024.05.23.17.55.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 17:55:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188191-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bC3bwDM6; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-188191-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188191-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 22D842824C5 for ; Fri, 24 May 2024 00:55:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 511FD6FBF; Fri, 24 May 2024 00:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bC3bwDM6" Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 029302C9A for ; Fri, 24 May 2024 00:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716512105; cv=none; b=G8aqta8UUqKOgdd8KgyfqDVg0ifGo4uHBnMjkS9QJ5Sy+g65BdF9/Qpo70fVTklN7rtbTZRooCjvw/Mo9bZX+GFAmuirDIKS+T3iVxZN+UOu4Od2aAlti25TcrSXFEVoBXM1CP+MgRFoi9kLAvL46qe51G853rpl39wgKMUpoFE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716512105; c=relaxed/simple; bh=i/X7vfVzszREoH7LEU3tywFJJJRVwFpzHn/HKGf+APM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=joNGefFjvvzT/wC6x6rlKu2ywcJNr0CL7AbpMwRBOjP6mZK7Z5vyWLv7ICsNn3ly7V0FCFphr9n7hJIJC4rgzu6+Pd2SL0Vm9bSanWOTQtoyFLBEvEvuBnweAGD5pbb4gKp46xQdda/Iik31Ze123Yw4Sl5CqSKtrokApYXyc/E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bC3bwDM6; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6f6a045d476so2757599b3a.1 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=vger.kernel.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=bC3bwDM6xIFalUabyQ6wMvIc6AKNIDBzy6sEO6ZAXq1JKubfaawbO1IiM+EY6GP+TC AOv6mk8MZnWvD7ieFz2k5NmkNZDTLLPV7cnUWOrOnZz6mzJrW48DweE43RjB39StKRVs jiTp22L4Q0haaUGpxu0V/MP9IGTX2StbF3Re+6nLgL7sNazEENRlv9Y782KuHyUsBWwb +MEiadJzK3ol+YuMGDE6Oi32ONs+TKEKAygKmxikDvcRFJBZU5D4oAhB8bmAIyqjHxwv PIhW3OVHkJjDNwn+v5zd+FZjjhmSbx8zG/WseA05wNvDOvOsnUGzSxzbtmJQRqEgdBLA Xjzg== 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=kz6vZ9Imn/KMczoOS3gKMuU8B0YmVyA5iSXck6HSKJA7ZVLgdrmudOxgQUuivjr7Xo Z7oKBJQpzY0iuqiR6TFTG9cxDvIgEyh0QLVM/zm/hUYQEilFYUP+2atxKghpLmCa4/UW hPMUsvyiUT47162uebO0AnX57Izx26L0lYUtLMiYpWm1aRyI7nonYxkVqWrnlmsmXYVI oJ5CGt8/sP3cQXj8VEXBU922Ru8ib1sOpJLyg2y1SWCYSYNDgxoqgQLZ3ygEb8JGg/JL fDXPgQ39E5xzy9m2QB15jAJTRcvqruVvgImxGmoAc03D1opxAYF3SMUyw6/WhpE0b4gM vebQ== X-Forwarded-Encrypted: i=1; AJvYcCVWyzv/i74BKod5c0edrXsqM1N5PB+qHDmFqcFKtOuRyUH9gK2Jr7qWa/eNvFezYqq3IL9u8csDCK78wT2/HDNWvzTrO4/NC5GV2rFC X-Gm-Message-State: AOJu0Yw7LamhwxgR8F4e5tKpFNySsw+EoZMbKFIhfy4G+3gjAT78DSFb L2xOpiiPkUraDQZiYCfWU2YBbl61orhvUEPa+3GOemNYsw2BXbiw 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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); -- 2.34.1