From patchwork Thu Feb 29 23:43:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13577756 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 CE929C54798 for ; Thu, 29 Feb 2024 23:43:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 603696B00AF; Thu, 29 Feb 2024 18:43:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 58EB56B00B0; Thu, 29 Feb 2024 18:43:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4307D6B00B1; Thu, 29 Feb 2024 18:43:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1BAEE6B00AF for ; Thu, 29 Feb 2024 18:43:30 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EF2FF16041B for ; Thu, 29 Feb 2024 23:43:29 +0000 (UTC) X-FDA: 81846470538.28.BD05E4A Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf03.hostedemail.com (Postfix) with ESMTP id 20CFC20008 for ; Thu, 29 Feb 2024 23:43:27 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PuvTyAPh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709250208; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZYaENkYQ4G5HZw66zLSCBAz4c9QdNSpOW86RMIeSYNk=; b=HPauMpzKfLFVV9DX/UzpqKhMw2+Eh+El/kakgG3EyTxBIZS7qGjSTmwI1TaDGxq77TxZtD wMizWNi+VZ2fUnSXaGYV7GeKqD5Zr0S3HF6fxO2J39XqX1N5uULRPip0FIhEthzLa6EoB9 NB9YOHuLkJtifmjZel/xkqaOQ10kBEg= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PuvTyAPh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709250208; a=rsa-sha256; cv=none; b=KiqtQ0ETLl3ZyOHvcO1b7BgcVuUJa34SEfYcu189p8wyBuTKn/Hxnp8mK3HaAL4CyorZNC mUg92EmD0DXQRI6ER/CWYp54+12uktYfcum7AQ4fO4t2M7PmOl+RlQ/8XXZIrqGPi6xJ4R 6ePXRQET8o4jvpkJ7rE51aHoR0QCKxg= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1dc09556599so14088305ad.1 for ; Thu, 29 Feb 2024 15:43:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709250207; x=1709855007; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZYaENkYQ4G5HZw66zLSCBAz4c9QdNSpOW86RMIeSYNk=; b=PuvTyAPhKomVGEGPJKwTS9ZJ35xi5DY0+CRw65JFTzNzNtUZwnneQ4GzLZfsA9aZa/ RU6HteCAT2kZaMIY8w5+2wBDv0Is9H53TXm5p4EfuJBjJsR94EkebMQ+HyQ54xnmpVNe lb6Zd1Ddm0Pu6fX8DKvFp0evW4VXUx6CX/+vcVx6EWNvv5pt/2uamfTu7sJu8CCOpVmf wFlYGaJ/caNwfiMFtq1nggdC3Z6M0ujSAONZwJo+wYNubMiwLbN57ZrY56PNiv6SuUr8 /7GFlQbpSacdl9awUFBUuOulMDk5Jna0cAlQUWsuEDrS3zdbGVv0Pba8qdLsVESLzAGd x0jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709250207; x=1709855007; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZYaENkYQ4G5HZw66zLSCBAz4c9QdNSpOW86RMIeSYNk=; b=UJvjMoxWImnozcl8JktacFsxyCeTjBi0GmzTJFJ8dWo+fUc227YkuKIwbGRSUQCAmZ llCyoHCVYdyaCk9Z+h9CQD8s0Pj2NZnNzXQn9hafi5/Jl8w+VhlBseOIoWSj48itGifP g5UgxNgVdwgPwVENvTQCzYHnJjc+O1D3oS+aTDmcA7/xc/C1MzDQGwLlyDbKDADSBWL2 HHBnVv7Fm4TRWitLmMu8zsB/pZ2JaWMlbJePV+MldBBAtoDFT+uiwD2tsaFZetGy2L43 oMt7Quiu/UhDgVk2/vFEDJSDggKMvoiggomcNVC8pbTQMhJHOTmOZQB/Tf8WGIKjm+yu N77Q== X-Forwarded-Encrypted: i=1; AJvYcCVTScECkyg2fFq1HNGQiVMP/LtzaEi+bZFBCgTZFuLMy3lHTQThhVIBwIQEA9LDDwCkgKA1kAmOIWS8B6PiZscoLsk= X-Gm-Message-State: AOJu0Yyp8UDWbbbPppLiPx+6dsn/xzGF3ryO4xLcL/WFdiSYTwo85YD1 BQpP33TLhbP9o3LT5UMzL2/lUCoA3f7JwR0WH7yU/66EaO0x1MSD X-Google-Smtp-Source: AGHT+IGkWYefSAJiD6V3UAHJP4h3dcMjAtD7ol2bRxxY1LAVjzWJTomMlC/1P8AOvCsvxgL62Mpd0g== X-Received: by 2002:a17:902:6847:b0:1dc:8790:6824 with SMTP id f7-20020a170902684700b001dc87906824mr50051pln.15.1709250204830; Thu, 29 Feb 2024 15:43:24 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::5:8f17]) by smtp.gmail.com with ESMTPSA id e12-20020a17090301cc00b001d90a67e10bsm2081312plh.109.2024.02.29.15.43.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 29 Feb 2024 15:43:24 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, torvalds@linux-foundation.org, brho@google.com, hannes@cmpxchg.org, lstoakes@gmail.com, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, boris.ostrovsky@oracle.com, sstabellini@kernel.org, jgross@suse.com, linux-mm@kvack.org, xen-devel@lists.xenproject.org, kernel-team@fb.com Subject: [PATCH v3 bpf-next 1/3] mm: Enforce VM_IOREMAP flag and range in ioremap_page_range. Date: Thu, 29 Feb 2024 15:43:14 -0800 Message-Id: <20240229234316.44409-2-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240229234316.44409-1-alexei.starovoitov@gmail.com> References: <20240229234316.44409-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 20CFC20008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ej4hf76ssqojths1fhstbi9pa8wg6hmb X-HE-Tag: 1709250207-894728 X-HE-Meta: U2FsdGVkX1+aRUEjD3feTabd3g+9ROgT0AeRr8YnvyoCQrQG+mMzax09QTDAQyQfExTwt6XQeiY8als2inX8gfWiqfrLty1i5nrIPJttlw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UndVQWHGTLJdKqeJB/RrLUoAPsVlaFioSVknM9/Fo0DCEQIlFqlE9RfoudJ1n7vY8dAXvep2tQchomATWqI2DTVpyuC6q5RRJ+pc+Vtza2GXII07svWwvWYAnrsHTNiKwvYUNZEkP6G7L6l+nYt/1aYtnN4n/7uxq97sMn2RTcFU2MMhfiPsxUkNxytCBH0wU3HvOHevH+Z/JvEOBTL+RzXWqrOM41YIT0cj/nHSNhLhMmYzosjROGViYKQ0U7dqGLunrlNZfsmJZoyWYLnbS+RCT4wll6n9Etuu0YOSe4y83gfT23ulA6fNTt60RjpNtAMJMBA9vquzEeEYJO6FhKFcAcN6a3Ttf4tyjdgNc7k8wUbPR4vEgFKwgFEwOKttNjunp7/LwMqYw0oK/L0KjLyebk+NBpIloghRgAgzvbG+Nbi+NtYXWz7bgIH+R/CHbZ7Lo0eBR3w= 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: From: Alexei Starovoitov There are various users of get_vm_area() + ioremap_page_range() APIs. Enforce that get_vm_area() was requested as VM_IOREMAP type and range passed to ioremap_page_range() matches created vm_area to avoid accidentally ioremap-ing into wrong address range. Reviewed-by: Christoph Hellwig Signed-off-by: Alexei Starovoitov --- mm/vmalloc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d12a17fc0c17..f42f98a127d5 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -307,8 +307,21 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end, int ioremap_page_range(unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot) { + struct vm_struct *area; int err; + area = find_vm_area((void *)addr); + if (!area || !(area->flags & VM_IOREMAP)) { + WARN_ONCE(1, "vm_area at addr %lx is not marked as VM_IOREMAP\n", addr); + return -EINVAL; + } + if (addr != (unsigned long)area->addr || + (void *)end != area->addr + get_vm_area_size(area)) { + WARN_ONCE(1, "ioremap request [%lx,%lx) doesn't match vm_area [%lx, %lx)\n", + addr, end, (long)area->addr, + (long)area->addr + get_vm_area_size(area)); + return -ERANGE; + } err = vmap_range_noflush(addr, end, phys_addr, pgprot_nx(prot), ioremap_max_page_shift); flush_cache_vmap(addr, end);