From patchwork Sat Nov 30 00:14:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13889014 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F020DD735EA for ; Sat, 30 Nov 2024 00:14:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 655D66B0083; Fri, 29 Nov 2024 19:14:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6045B6B0085; Fri, 29 Nov 2024 19:14:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CBA86B0088; Fri, 29 Nov 2024 19:14:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2FBA36B0083 for ; Fri, 29 Nov 2024 19:14:32 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 13A6D1215F6 for ; Sat, 30 Nov 2024 00:14:31 +0000 (UTC) X-FDA: 82840839732.15.FEBEA2F Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf29.hostedemail.com (Postfix) with ESMTP id 9CB0F120018 for ; Sat, 30 Nov 2024 00:14:16 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="WpVj/PWZ"; spf=pass (imf29.hostedemail.com: domain of 341hKZwYKCP4y0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=341hKZwYKCP4y0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732925663; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=Msn5ydSsXJvK7W3o2JvmJ38LPMa5eKoJY2o5aCZVyQY=; b=rmOSfNDllECvlVze21o5cItCoLdTjFi/qwN3V/+CnvuSWm0dyzvuIyxYcebzWvlaryDg2X 8Y6h1EZt/98TZy1hsh1/vWFtuCytyx2q4nojxr0ipvrL4J7/KaEFtRnw/S6DLyxXsU19yM OVFZ/0hm6SblO1ewuJnY894rZV1CzWI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732925663; a=rsa-sha256; cv=none; b=3erTLvq2JR9M+xEKVf24wwyJLFyolrVxbXD92Cn4kNIA6UI7c9kkYyThamFuLMU+21Ft0e zNcxNjYqlMbXd18s7nqE73zp2Weyb7PtcP/ChgeuNCVxlwwaaDJbLesORzvRdOhgYs/Pnp gNbLJGhTSt4560u7Wyx2fdo88SFEvzg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="WpVj/PWZ"; spf=pass (imf29.hostedemail.com: domain of 341hKZwYKCP4y0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=341hKZwYKCP4y0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7f72112de23so1667698a12.1 for ; Fri, 29 Nov 2024 16:14:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732925668; x=1733530468; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Msn5ydSsXJvK7W3o2JvmJ38LPMa5eKoJY2o5aCZVyQY=; b=WpVj/PWZux/spyJjxNmJQ5W3qMwoiX/uC1a5M0wLOKA4Elt0/J8FfFpoA41SuKVfmW RfHlntpOV9+xqr9BMTsx7yKHnAcZhEIMgyY08tKnlP7+vGEyaE/Dn7uqJvjf2rYoo1wt UdEbR4kE58KA0ldRULMu+tG3N7lRMWg4iN5tn82Wc2rKr2Bj5uEbWuVmFUcjBX/o0ZUn iBzcaAS+GXGL6wM/nEI8evnxpzHsZsAunamZltn6wA4Cm/kVwdXBuLJb1MHlsK2QqLGG o8kJaOffwBJr4TzJXxA1HucJAL2XRVt7IQDGdX10cHu4PSvfzPg6wWEIrLyCsvUhJMvW WgGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732925668; x=1733530468; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Msn5ydSsXJvK7W3o2JvmJ38LPMa5eKoJY2o5aCZVyQY=; b=v2yPId64v4naztLWsVy8Ntvthsy7sQUg3YW8uEzZ+RW/H3MrZos7RBdA7EYrApAiSI qo0M0jhQnv/XwCAX4509xk94T7/1Z4DG7z/7ins5l2dLzkvVDewdjGFh8W4hOBX5mLRK q5f/YIDN4L+DM0XkZ2jdm0DxP7iNqGGrjUG1/wJnb1Pz5kY7M1UKPGzCDFbPZr2uREEM SKBTvVIUoM8aAk9ErSE4gPAZkqpnzYceQRFkMsme94MV3nOTBZsiDkIDnUnieQqsjKGn 33jq4Rt/XuhpEMBThlRZ9r+BBd8In7ztGEpV08XGKmvaWx6cO2q5yLo2GdbgShQ2izP5 /59A== X-Forwarded-Encrypted: i=1; AJvYcCVupg/o78LMidzFDXQXIK3JCkZ6j9lnXd6PdyMlQQoksNwAxeB4WNe+d8RQD2oq06MtqXPgTQiVKQ==@kvack.org X-Gm-Message-State: AOJu0YwgU40pp3eFYCpprfzYXF+Lx8iUukLpf0ixx9g72GmaJmMrk/tv QXGruwC2K28NaWIK1okb5a3b/0xgRqfiZ27v14EtdXaNy9uc/2cPId9X2ZyuVaiWDAskWG8cm+Q 4nA== X-Google-Smtp-Source: AGHT+IEZ5ARDUBAksQwZjcJ+vr4ytuA3q37Am5GZLCfm/nnP/vqItHhnwL+g58/Cgk/lpSFI0Dl6QgR1MCA= X-Received: from pfaw9.prod.google.com ([2002:a05:6a00:ab89:b0:724:fde8:58a]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:a10f:b0:1e0:cc21:19a2 with SMTP id adf61e73a8af0-1e0e0aaf55bmr19045608637.1.1732925667676; Fri, 29 Nov 2024 16:14:27 -0800 (PST) Date: Fri, 29 Nov 2024 16:14:22 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241130001423.1114965-1-surenb@google.com> Subject: [PATCH 1/2] alloc_tag: fix module allocation tags populated area calculation From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, pasha.tatashin@soleen.com, rppt@kernel.org, yuzhao@google.com, souravpanda@google.com, 00107082@163.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com, kernel test robot X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9CB0F120018 X-Stat-Signature: nzciyeos1pzstk8wi61zhgyn4c54f77a X-Rspam-User: X-HE-Tag: 1732925656-417610 X-HE-Meta: U2FsdGVkX1/ug+BCozMGMA26aFTAdPYXRr3lCM5ILoWNq3bNOwPqCqjxeSzL3BiyNmz9yZ/1c54L1C3pp9B2pPGwBd3aNbt4GDdX7b0mcYVqhNH6RA1MmARkcLwCcQYcK+Cnn/M6gwxhQDOdRUmRwwaUuQz/5506/AX3SyhU+vSEVsY2emZe7ZH5j9BNkCdP6UxZrpzD/B6DsCwcggqBnlS4EZoL0+QIp4nz/k9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V47P7vppSQMLHYWosbvmWEvKBjocYt94uV4c8MSmEXursYwa+bxEbfCvtNw6va/+35YEBWi7RWs8YTeGo35YImrCl+on7g2mvIgsiVO9qDYWeb/A4LxJTW+Z9rwEbV3V6k6jnH+M1ye7VZYoi80yN0un8yqKyIVramvJ1VvvM0XzyK1LxxgkbDYXUrEAp81w6O5Tk3TEKcaBF1rZ33I4SalQ4NocjAOZm91I0sggCr96Agp4ng66yUGCHRol5sDdfPy+mOZmLhOV9qVmZCn/EOTJ8llHmkXGP4y3MxdsnxrHC6w/rZh2RhMZVeINrDFnTi4Cp X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: vm_module_tags_populate() calculation of the populated area assumes that area starts at a page boundary and therefore when new pages are allocation, the end of the area is page-aligned as well. If the start of the area is not page-aligned then allocating a page and incrementing the end of the area by PAGE_SIZE leads to an area at the end but within the area boundary which is not populated. Accessing this are will lead to a kernel panic. Fix the calculation by down-aligning the start of the area and using that as the location allocated pages are mapped to. Fixes: 0f9b685626da ("alloc_tag: populate memory for module tags as needed") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202411132111.6a221562-lkp@intel.com Signed-off-by: Suren Baghdasaryan --- Applies over mm-unstable lib/alloc_tag.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) base-commit: 539cd49425a4e9a66d601d9a8124f5c70e238d56 diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 2414a7ee7ec7..668c4e128fa4 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -393,19 +393,20 @@ static bool find_aligned_area(struct ma_state *mas, unsigned long section_size, static int vm_module_tags_populate(void) { - unsigned long phys_size = vm_module_tags->nr_pages << PAGE_SHIFT; + unsigned long phys_end = ALIGN_DOWN(module_tags.start_addr, PAGE_SIZE) + + (vm_module_tags->nr_pages << PAGE_SHIFT); + unsigned long new_end = module_tags.start_addr + module_tags.size; - if (phys_size < module_tags.size) { + if (phys_end < new_end) { struct page **next_page = vm_module_tags->pages + vm_module_tags->nr_pages; - unsigned long addr = module_tags.start_addr + phys_size; unsigned long more_pages; unsigned long nr; - more_pages = ALIGN(module_tags.size - phys_size, PAGE_SIZE) >> PAGE_SHIFT; + more_pages = ALIGN(new_end - phys_end, PAGE_SIZE) >> PAGE_SHIFT; nr = alloc_pages_bulk_array_node(GFP_KERNEL | __GFP_NOWARN, NUMA_NO_NODE, more_pages, next_page); if (nr < more_pages || - vmap_pages_range(addr, addr + (nr << PAGE_SHIFT), PAGE_KERNEL, + vmap_pages_range(phys_end, phys_end + (nr << PAGE_SHIFT), PAGE_KERNEL, next_page, PAGE_SHIFT) < 0) { /* Clean up and error out */ for (int i = 0; i < nr; i++)