From patchwork Sun Sep 11 09:59:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12972821 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 71E7BECAAA1 for ; Sun, 11 Sep 2022 09:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC46C8000B; Sun, 11 Sep 2022 05:59:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B72CF80008; Sun, 11 Sep 2022 05:59:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94F578000B; Sun, 11 Sep 2022 05:59:30 -0400 (EDT) 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 8650D80008 for ; Sun, 11 Sep 2022 05:59:30 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5D2C01C6051 for ; Sun, 11 Sep 2022 09:59:30 +0000 (UTC) X-FDA: 79899357300.23.2ECA000 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by imf30.hostedemail.com (Postfix) with ESMTP id 22DED800B0 for ; Sun, 11 Sep 2022 09:59:30 +0000 (UTC) Received: by mail-qt1-f171.google.com with SMTP id s18so1350991qtx.6 for ; Sun, 11 Sep 2022 02:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=OPh2SoeDJ39bM1Jn5fFI8VsUd8dRA2153uVq4iTm5YA=; b=Cm/iwBj9qSxR6hNh4WkGnlY2rIhzISZ52M2GqSDfU7xNlfLTD1kDBK3GW4JyIWLpbF vFCNPAJLgXJtsglJR9PAeKY44F6cjvaw6tuS4MXxA20nHmxmD/wqzebHgdbHMGmAD61N ZV4Tr5DVsNuioBerAQQDoJ4+a5mniKGiZRxoUQiZlNMllJ4sclh03nAFz08cVB8ODhMT Skx+FX/f8czauTMll515ktdu7gVSZJA1f7251v/yIj0BzYslEFQQtKX5F2MkHK/8CwmU Hx7spxOmVfuUwec09wkdbVsfFyOD1wVjfc69FUWeWsnCvU5bgK+iVzVBPk9GSB7Lao7h VxvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=OPh2SoeDJ39bM1Jn5fFI8VsUd8dRA2153uVq4iTm5YA=; b=shzdpmtfF05M6JNU6Zie/vYB2m6+iNn0a86YBhN/o4CqEaMQYdGoNYszXkOoKBIBlU 0jEq2ZWvyfKqeAovjJ/XYwJ7O1rZ0S972ekoXdbAadqysg2dx264gYqKZ/mXdl7aEErv HYU7cgW7cWHyWuoJ8XVobRyIiHVcUE8OorhFkhLHpF8E5gBpcanbNQx2UlF+2C/j/kBf vX0GGfGO+CiSHg8koAc/gvQyvhPFpY0MjGjN0RspiOlciiJmRA/iS98wBTqRkcY7/a5c KX6odksxUnP6ncdEW14wfbrUhsxZrgbHf/OUkHnQCPvbWFz33pX/vnHAdd53Fr2dSLM/ H4Aw== X-Gm-Message-State: ACgBeo3N79LNUWEC5KRAN71YLR6E9leeqSX57wRtUKV/7QDbavLjDgyU j1jrY4gu/Y5ddfh82vJtOYI4dQ== X-Google-Smtp-Source: AA6agR5J3Cn9HvOjdYaL72tcgWTBN3wcKIFFTOLz4o2e2o7b+hMrlixH3K7CPiJSXhwkuBn1HYdkSA== X-Received: by 2002:a05:622a:609:b0:35b:acd0:21ff with SMTP id z9-20020a05622a060900b0035bacd021ffmr3764909qta.321.1662890369441; Sun, 11 Sep 2022 02:59:29 -0700 (PDT) Received: from soleen.c.googlers.com.com (240.157.150.34.bc.googleusercontent.com. [34.150.157.240]) by smtp.gmail.com with ESMTPSA id y29-20020a37f61d000000b006cbd60c14c9sm4625233qkj.35.2022.09.11.02.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Sep 2022 02:59:28 -0700 (PDT) From: Pasha Tatashin To: pasha.tatashin@soleen.com, akpm@linux-foundation.org, corbet@lwn.net, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, rick.p.edgecombe@intel.com Subject: [PATCH 1/3] mm/page_table_check: Check writable zero page in page table check Date: Sun, 11 Sep 2022 09:59:21 +0000 Message-Id: <20220911095923.3614387-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220911095923.3614387-1-pasha.tatashin@soleen.com> References: <20220911095923.3614387-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662890370; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OPh2SoeDJ39bM1Jn5fFI8VsUd8dRA2153uVq4iTm5YA=; b=Fo99dHk8rDr44Axq50PAkvEuXZTfpseZO2CBkR1P84hY16Uzt0eQ3YQs86t0NLV3MXB6OL v2I85To/zpYkN1ZGaMqf87gNNFBlV4aZs4iiH7bMeXzFnLQoRfOQtViAyhLTIiHtRn8cO0 CA6uupI1c+oU0agnGilY6lG2JB09fKY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="Cm/iwBj9"; spf=pass (imf30.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662890370; a=rsa-sha256; cv=none; b=lpVFuN06RCUfF86fl4vTqW5bs8VXNtrqcFNbCnpydsgyDiXMzJumWAUYVQ+s5PWiriU97Y WDvyDFBOUc+MXj4sMcHIUTLbWGpurVLHwGSthzYQHF2hxh1BfK91qsvzq41Smrqh9ErHyN DsLsOmwsyU+MEtCM8vyhwu5pLFZ3mfM= X-Rspam-User: X-Stat-Signature: mq566qm7ekenmosm9n4om1edra5eoeuk X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 22DED800B0 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="Cm/iwBj9"; spf=pass (imf30.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-HE-Tag: 1662890370-736339 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: From: Rick Edgecombe The zero page should remain all zero, so that it can be mapped as read-only for read faults of memory that should be zeroed. If it is ever mapped writable to userspace, it could become non-zero and so other apps would unexpectedly get non-zero data. So the zero page should never be mapped writable to userspace. Check for this condition in page_table_check_set(). Signed-off-by: Rick Edgecombe Signed-off-by: Pasha Tatashin --- mm/page_table_check.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/page_table_check.c b/mm/page_table_check.c index e2062748791a..665ece0d55d4 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -102,6 +102,8 @@ static void page_table_check_set(struct mm_struct *mm, unsigned long addr, if (!pfn_valid(pfn)) return; + BUG_ON(is_zero_pfn(pfn) && rw); + page = pfn_to_page(pfn); page_ext = lookup_page_ext(page); anon = PageAnon(page);