From patchwork Fri Sep 2 23:27:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 12964788 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 C2FCCC54EE9 for ; Fri, 2 Sep 2022 23:31:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42CC280145; Fri, 2 Sep 2022 19:31:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B57680120; Fri, 2 Sep 2022 19:31:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 255A180145; Fri, 2 Sep 2022 19:31:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1132A80120 for ; Fri, 2 Sep 2022 19:31:09 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E16D71A0A1B for ; Fri, 2 Sep 2022 23:31:08 +0000 (UTC) X-FDA: 79868743416.15.E547A58 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf13.hostedemail.com (Postfix) with ESMTP id E32ED2004E for ; Fri, 2 Sep 2022 23:31:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662161467; x=1693697467; h=from:to:cc:subject:date:message-id; bh=qLq0yeIaO/mvA3cm8hCykqt3PIzVE68HdER9lamMWV8=; b=XiTAure7RJkNoDskjPK37b/gyeh9Kxu4JrxoiiMzBbr8Ueu+R1BcZUzE mmxQ9/FKmw10UsqjO3swVXAipRlEgi54w93MpwdXhP1yvW1MOvJAxF4DJ pncE1C0bnFKwchyWwcXYou8/HtU81RrY8znyK/lgk8YDnw9cYV/KAVPnf +YVaCLUD/tPD1Z6wpCazpPmcFCdguQuqXsxzGEJVyisLwQhLQNgz5/nQv B0NgqTFbuSqd+Stos+zH7QK0nPxz6Z5brhLIjvK6AtQVBmdgBva2R4NDt lh0vh7qdocIgVD7epaNYiN2spdAqELabFCwry8mwj4ljaaXlWO+U5bNiw A==; X-IronPort-AV: E=McAfee;i="6500,9779,10458"; a="296113070" X-IronPort-AV: E=Sophos;i="5.93,285,1654585200"; d="scan'208";a="296113070" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2022 16:31:06 -0700 X-IronPort-AV: E=Sophos;i="5.93,285,1654585200"; d="scan'208";a="643103273" Received: from gescaler-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.116.199]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2022 16:31:06 -0700 From: Rick Edgecombe To: pasha.tatashin@soleen.com, akpm@linux-foundation.org, linux-mm@kvack.org Cc: rick.p.edgecombe@intel.com, linux-kernel@vger.kernel.org Subject: [PATCH] mm: Check writable zero page in page table check Date: Fri, 2 Sep 2022 16:27:32 -0700 Message-Id: <20220902232732.12358-1-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662161468; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=UkeJ55bFpKX+2T453unDEXiB/Ss1McYOOP8pEP365QQ=; b=e8U0OvXVD6zV+F5ayqrwEGAFNrsWqgAlVhrmWS/mf7PA1kKnwGqc7mCz1xbf4oR0tDNBhb jUimQ5AQDo5XbBVti4xC56djd07FTMZOodBACH7445Ym+481cUVlFBXGc+HkiqngncHhvi GNJtEYsWNVBUSU3KhpUkpqwxUOi2eIA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=XiTAure7; spf=pass (imf13.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662161468; a=rsa-sha256; cv=none; b=2zrKbKDk+qjeTYG7q/a0ehX3QYnB+w59e+4GcKGM9OyNnd78l6RKCwYIteczPRcCDWUCd+ YkaHlqS8TCtMQB82tPEHco+GORizAj0hGF1oSEOwSoz0zcSmE9+EwSPyHH9/5mujAyW8rw OpFp4UkUfk0mUu0y9/jihFEy5JjsxDY= X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=XiTAure7; spf=pass (imf13.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E32ED2004E X-Stat-Signature: 3somfw6b8dxpnyw1ukwn7i3s3zbiu6mf X-HE-Tag: 1662161467-255498 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: 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 --- Hi, CONFIG_PAGE_TABLE_CHECK is pretty explicit about what it checks (and doesn't mention the zero page), but this condition seems to fit with the general category of "pages mapped wrongly to userspace". I added it locally to help me debug something. Maybe it's more widely useful. mm/page_table_check.c | 2 ++ 1 file changed, 2 insertions(+) base-commit: b90cb1053190353cc30f0fef0ef1f378ccc063c5 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);