From patchwork Wed Jan 19 01:21:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12717043 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 0D797C433F5 for ; Wed, 19 Jan 2022 01:21:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 808186B0072; Tue, 18 Jan 2022 20:21:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B7996B0073; Tue, 18 Jan 2022 20:21:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A64F6B0074; Tue, 18 Jan 2022 20:21:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay025.a.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 5B21F6B0072 for ; Tue, 18 Jan 2022 20:21:16 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0B6DD20CC0 for ; Wed, 19 Jan 2022 01:21:16 +0000 (UTC) X-FDA: 79045283310.01.097E16D Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf07.hostedemail.com (Postfix) with ESMTP id 91E6340003 for ; Wed, 19 Jan 2022 01:21:15 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id r5so1007855pfl.2 for ; Tue, 18 Jan 2022 17:21:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OvyGOIk3qoZc/SMHBDXTbJ3GLngZKOnDGVStpr5hHTo=; b=k5sSR4jfneG9GyQNvw3gViTRq7zruzJwjGwN9dPWvF6JxApZsVZdIs4xJKGBMzs9zE VT90XUSyDqNF2duMambNQoML34MfdJYJEsIdcfaTFLNKpOyxg2PAugKv6DoBFGJPOs/C 3WRCzywJqNRAXecxI8xlixNzAtVHNEm0mFhtjL6NKmhRuHIaVtjuB5CfW25tKNXtWuGc 4ZNUWmAqeUwx24d5hUU5hAWSgMKioAFRCMcA9Ahc26sUTp1VnRYD/UjNp2gYm4UaZsrD 35O3tnw2z7hRs9tjZEsuMoXQenhaVZEO9Dw7X7pyBExsjUk46AFMM2aoJVV7ysDVScb1 Ivyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OvyGOIk3qoZc/SMHBDXTbJ3GLngZKOnDGVStpr5hHTo=; b=yaVCEUeZEjOleM25nf5CdAHqpN85RatUkphQfiLzmiIqFLRZRaeF/+JexVws/3FAMv isnyC2a8us7PQR9IUBvSEzUrxlZ2UOLu31ObJ/qZT5SWEh4R2ZaKpvjG1D7VqioURfPT tw5tzUo0Gk7DqzrklLTOWgWNeRODXBAD4TcYxVGrWVdfXl0sFoo6xmsX0aCBelzqzxJZ hzJ/6puw18+6NXLUNYZLTwGkWFla+rpf4unKDgP1Z7gNargu5i0P4KSneXfja/lo0mv+ s5JwQnXT/h4KVmiMvQNKW27Z712U5bbZqrtjkQGzmEax+4cZLxXPtm+8o15QNQqW/8KC fDcA== X-Gm-Message-State: AOAM533JVbxwBHXkY0zhZbnuht86FX4jWCRM3II2wmNPd9IpzAxY9SHR i9uBRarL98chWAU1bNA0RPs= X-Google-Smtp-Source: ABdhPJwlgOaGkDW/htbDV7Ii8N1D21oQGFHjKAzpx671/y8exjCTt4K+oFxMvz6rzbReXfPm4j6eNQ== X-Received: by 2002:a05:6a00:21c2:b0:4bc:fb2d:4b6f with SMTP id t2-20020a056a0021c200b004bcfb2d4b6fmr28112341pfj.62.1642555274457; Tue, 18 Jan 2022 17:21:14 -0800 (PST) Received: from localhost (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id f185sm12462961pfg.159.2022.01.18.17.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 17:21:13 -0800 (PST) From: Yury Norov To: Catalin Marinas , Will Deacon , Andrew Morton , Nicholas Piggin , Ding Tianhong , Anshuman Khandual , Matthew Wilcox , Alexey Klimov , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Yury Norov Subject: [PATCH v2] vmap(): don't allow invalid pages Date: Tue, 18 Jan 2022 17:21:09 -0800 Message-Id: <20220119012109.551931-1-yury.norov@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 91E6340003 X-Stat-Signature: ke33zxfhipeu9mr4yj83a6mi4fxyfmid Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=k5sSR4jf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-Rspamd-Server: rspam08 X-HE-Tag: 1642555275-685382 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: vmap() takes struct page *pages as one of arguments, and user may provide an invalid pointer which would lead to data abort at address translation later. Currently, kernel checks the pages against NULL. In my case, however, the address was not NULL, and was big enough so that the hardware generated Address Size Abort on arm64. Interestingly, this abort happens even if copy_from_kernel_nofault() is used, which is quite inconvenient for debugging purposes. This patch adds a pfn_valid() check into vmap() path, so that invalid mapping will not be created. RFC: https://lkml.org/lkml/2022/1/18/815 v1: https://lkml.org/lkml/2022/1/18/1026 v2: Patch description changed. Suggested-by: Matthew Wilcox (Oracle) Signed-off-by: Yury Norov --- mm/vmalloc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d2a00ad4e1dd..a4134ee56b10 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -477,6 +477,8 @@ static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr, return -EBUSY; if (WARN_ON(!page)) return -ENOMEM; + if (WARN_ON(!pfn_valid(page_to_pfn(page)))) + return -EINVAL; set_pte_at(&init_mm, addr, pte, mk_pte(page, prot)); (*nr)++; } while (pte++, addr += PAGE_SIZE, addr != end);