From patchwork Tue Jan 18 23:52:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12716992 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 BD3D8C433EF for ; Tue, 18 Jan 2022 23:52:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5FF26B0072; Tue, 18 Jan 2022 18:52:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BE8436B0073; Tue, 18 Jan 2022 18:52:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3A536B0074; Tue, 18 Jan 2022 18:52:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 88B9F6B0072 for ; Tue, 18 Jan 2022 18:52:53 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 42362951A9 for ; Tue, 18 Jan 2022 23:52:53 +0000 (UTC) X-FDA: 79045060626.12.D2912BC Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf24.hostedemail.com (Postfix) with ESMTP id E178C180002 for ; Tue, 18 Jan 2022 23:52:52 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id o64so818629pjo.2 for ; Tue, 18 Jan 2022 15:52:52 -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=4/RjK8BN3JSAYkOl/QC9o65LtcnAhU3UXdD1BgVr6Dc=; b=I3JK5GxKJNosEutNRJEjnFEOYFwZ1QUsNrU8p+R6GhPQVxZou96OUTOJJJNUYvUXlI djYqsWuuEpIwlotwaIt6WThuRViY62QjMtOAC3oESQLeE07JPBa7iENB1R8NVtCdVozp KPhBoyoOoL+vLpnNDQRI2pTsZRefcPiWZD+vMtgXegOqwK8dmBlhC1pKrzn2n33WalQ6 u8I5lEIHn3e2WkVkySHo1yLDA/aqfeiJdTWy/oT2R7IK5/7BoD4gUBn88IlHzHMIwl5L tFptvPjevkIe/BK90fAKEO/eaOhkO2+zfCLCyHh4/USxnftehM/1SGXMrANgce6HlDQx gWXA== 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=4/RjK8BN3JSAYkOl/QC9o65LtcnAhU3UXdD1BgVr6Dc=; b=r0atC4iHDG0In+1htTlWZ4QqCrtZMkVxCxRiZb4pQuOX5LnkiHUk7enjBlXCVsMnNb 1NDDx2vjBsHv/PpaeGYqpdrL0xf1I93RtF5fWgsF6Eix5jgUWubAmgk8PtglYyc/PGPp 8WHbsqlYVKLehmrjaHz6c5bauC9KnELrwmkRInh3gUwnsABBR9DcuPkNuT2+gpI9vwqz 06G8a+7YA1APnUTPW8liXLuPoxdwfpfFVjHEscM4RvjMwZ9UgcbjhQ+SR4kv+csAyZm6 Cbz/izsj1HR9aCKNl85MnAwWMux9DQtKdRth2o740OxmtKAbGw/HVcsFVNS6IDFiRMOb BLtw== X-Gm-Message-State: AOAM532jRUGDJkDN4h53Sjeqwi068FzvGOJY7UKoiscAxTC0tdzf5Ise lLh4/FOnGm0F3bQtuNqYzLg= X-Google-Smtp-Source: ABdhPJxiD2bVrhbvfdZNgIib+nJd6p1sFBUR9Rc3MGJm0eXE85gtCHvnl1zU6KKl3ctqvAbPK7LMAA== X-Received: by 2002:a17:903:32c4:b0:14a:67ae:3e03 with SMTP id i4-20020a17090332c400b0014a67ae3e03mr29666243plr.111.1642549971771; Tue, 18 Jan 2022 15:52:51 -0800 (PST) Received: from localhost (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id h4sm18962329pfi.79.2022.01.18.15.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 15:52:51 -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] vmap(): don't allow invalid pages Date: Tue, 18 Jan 2022 15:52:44 -0800 Message-Id: <20220118235244.540103-1-yury.norov@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E178C180002 X-Stat-Signature: 176ti39pxmetzteyyzqxj4y5qh9u5k49 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=I3JK5GxK; spf=pass (imf24.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=yury.norov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1642549972-162821 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 DABT 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: use pfn_valid() instead of adding an arch-specific arch_vmap_page_valid(). Thanks to Matthew Wilcox for the hint. 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);