From patchwork Fri Feb 23 23:57:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13570153 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 3C1DDC5478C for ; Fri, 23 Feb 2024 23:57:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9F056B007D; Fri, 23 Feb 2024 18:57:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C26B96B007E; Fri, 23 Feb 2024 18:57:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA1726B0080; Fri, 23 Feb 2024 18:57:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 956226B007D for ; Fri, 23 Feb 2024 18:57:39 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 603F412124C for ; Fri, 23 Feb 2024 23:57:39 +0000 (UTC) X-FDA: 81824733438.12.E71DFE4 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf23.hostedemail.com (Postfix) with ESMTP id A61CB140008 for ; Fri, 23 Feb 2024 23:57:37 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iIjIDhNc; spf=pass (imf23.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708732657; 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=A7v8QcQGKEfLwaJltNJW0mYz5w9KdmkVXr/8REE7aG4=; b=P8IvlQlz3dHl0wg/LhztCmdAmJ77x9s8BT6z4EVCeZfxcmIHFdZyTmoWqcWlTWb42mD85Q vg8gov27pHX1OGvxEOEPAtGL4qk0vEFsSxoNudLoVulHQMSsGJrwd/iIdVuGw8obVvnlea 1mncznrVov6wN2g+4bFS6gY30hlRAdw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iIjIDhNc; spf=pass (imf23.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708732657; a=rsa-sha256; cv=none; b=5jHOwAAaOJHueUBTceRu+zlHQSjaoyqqnILYzpe4ANq5NLUJ7LXycz5Fv0S9mAMPFCXGgv 164OWZ2ysa+iU+rGBM69zN3imjPhyux9qgGOtrI9hyH6h5NRYjUd1aOcxPD8SZqthH39TR G+h9UCQhYly2aZ1z+cKwG/TE9k6TUcw= Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-29a74c88f74so910955a91.3 for ; Fri, 23 Feb 2024 15:57:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708732656; x=1709337456; 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=A7v8QcQGKEfLwaJltNJW0mYz5w9KdmkVXr/8REE7aG4=; b=iIjIDhNckyj0w78CuclqmockKfw21I2IrZBh+2h7JjeXDrEfvuZqjl8z4vLATUP2gB K58DiMytyu5XEWLDTfr5tHO7W/byJNeoZYqIRxtHU7RibQ782cTCfeWSVXn+4QthSOTx WBMGKaDuTpVc/cbqgUWHSy4p8pA2m6g/u89CVMahL8yiWxyk+iCZb+RknxSxfxioz2vj ZFDbAVPOAw+vXBUJOJgDT0kC3YBiIsCjAr+1hLfGFeYXaPzfCPcwjSfBrpOFM5VHZjBO KjviioDG4ttQDrEZQM+tiwCryYhBbVJnIvvGVfJea9ZNK/J346H0q5rm5yc1sZ2rlehn bE2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708732656; x=1709337456; 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=A7v8QcQGKEfLwaJltNJW0mYz5w9KdmkVXr/8REE7aG4=; b=B3rScWde+WCHFcBD8l6Y32paA6RJo96IVIkLxHNOZ8tX6DCueIrNdxBkTW3M+gylb2 lPDI3ICzr7xwRfGhOCZvtcXBZftRHkGo8Ua6aohhrqFNQPhZSMhIZ2xWmB/EWlPYt90z lyJpYMuy7Pe8UmJ9j9idMdyrsdW4RBZIX2LcPX2o9YGNrdswTC3N0GSR9GNKW77U4e6F G/b8gD72s2ABOklwPgmjtHX+biTqczr57Lu3neM4T769HejavC5mJO0M7tyb5849JEgX DQMXp/vftdn2kbagPsj1PQeNmgdtnQOsqWrYxsFQICvdo3eFGeyFni2z0mL8ZIQk+ETi YxEg== X-Forwarded-Encrypted: i=1; AJvYcCUahZWDM4nyREXb6D8Xftv6uhDPXJSNUqAbwnlxPFNL+O40ZeDPZ64ypS2FFUbqkUAfR4YVYXvaSuOWtlwXguuuu5A= X-Gm-Message-State: AOJu0Yy2mmNPr6LamhzMO/gLhhaeZ6Lf9YGfmwUIGzOBoMbYh71sMeZv 7QHdf4yRCwhWSHgY77gYSuNUlNS5bhH1xAfXoe/GM6Sq0fjQLw8o X-Google-Smtp-Source: AGHT+IHG/DO/OVIktjtp11/4CHtLMBPBSMQzb2KGZX31cgPqxxDf+7H9BLoJUXmr0UjElOG7XOtMJQ== X-Received: by 2002:a17:90b:1050:b0:29a:9ba0:8a5b with SMTP id gq16-20020a17090b105000b0029a9ba08a5bmr411918pjb.5.1708732656476; Fri, 23 Feb 2024 15:57:36 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::4:45de]) by smtp.gmail.com with ESMTPSA id si4-20020a17090b528400b002963cab9e2asm2161658pjb.2.2024.02.23.15.57.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 23 Feb 2024 15:57:36 -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 v2 bpf-next 1/3] mm: Enforce VM_IOREMAP flag and range in ioremap_page_range. Date: Fri, 23 Feb 2024 15:57:26 -0800 Message-Id: <20240223235728.13981-2-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240223235728.13981-1-alexei.starovoitov@gmail.com> References: <20240223235728.13981-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A61CB140008 X-Rspam-User: X-Stat-Signature: du13r7enbdxngayhptmc3dkbi448iad6 X-Rspamd-Server: rspam01 X-HE-Tag: 1708732657-53238 X-HE-Meta: U2FsdGVkX1+dr+LwEwc5dWzXSiwJtluV9/0mbfeTGz/bDHe/iAWbD5cEqzWy3fu7VkQJhHbfqLnYTm02AT7BTaXRCUNgFQ6iA/h9865SmOfY05eD8A73YIDDN2qyMGRdYp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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. Signed-off-by: Alexei Starovoitov Reviewed-by: Christoph Hellwig --- 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);