Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3758475rwb; Mon, 5 Sep 2022 18:30:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR5SGbe3qpnulyNR1rEAvTezpmPmQ9OA8yberu6sqdPSGlCodL9tg8iR9yU7faSeCnoO+APw X-Received: by 2002:a05:6402:248d:b0:437:dd4c:e70e with SMTP id q13-20020a056402248d00b00437dd4ce70emr44364649eda.75.1662427819086; Mon, 05 Sep 2022 18:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662427819; cv=none; d=google.com; s=arc-20160816; b=hvm+/ATsu0joJpF6RQ6fz+c4EvUm1X9unouDIey4tfPGX4uWKrQkiNe/n/3bRTEhWl 5F5cIgoLqKjO24KWVtMfmASmCrVI3aq2yWoR9jdALi3zJtAh6pz9K7HE4RSJkzGprqHP Gi+7jT64YfpVnXXp5H0V4mw7JTBbDHt73fT3gPWl1tjQbjO+6pufgh8c+xumX3WVzD1t GFrMfJFlkrL7jTq/Tcp24338TPb6+Iy1PTdSTEfcVCg4qN9Iu+lIHuAid+3t2uLnHHhd rl53tDP8/bqn2ZwZ+pjWT3YUJlEfr4f13wOvD9/G3dvjpPi45QVePHwLKBvEDwaBE/qt 5jtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=i2orbtExQlccm1w/BNraKCbJoQoonFPa3RMVK51xch0=; b=JL6knK2JlTiCJQnThsDkbMqL9+krwlhK+gOT4tyV6MkaIqjboqSHwOm1lREEWTI68d bAggvcFFYKQtA4oFxk4bHUHxlZnfU9A14qW59f/lNGXBJ+LCe+vf3iKhy7be5ObYDZLx VbgMWtnIK7UiuP0arwmDe33u9ejmSFsjnhw2yqbzYNZY3N9skavhGeCbUxfXQXddG5z+ fE+Q9UoVZ6sjeS7VycnXL8vDyY8BgWxtKXi178WcbRHB0JdxsNREGtrzmQkpsp3XuwfL WYWeB48g1WTQ1QxioDq6UzWXtfJvIVyLk+8wQTjQgUpRgP52RqannPxvoXjPnRkk/wlH sUWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=Y1GCnRYV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y3-20020a50eb03000000b0043bc19efc0bsi6951390edp.136.2022.09.05.18.29.54; Mon, 05 Sep 2022 18:30:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=Y1GCnRYV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236536AbiIFAjz (ORCPT + 99 others); Mon, 5 Sep 2022 20:39:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233073AbiIFAjw (ORCPT ); Mon, 5 Sep 2022 20:39:52 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 470E210FC3 for ; Mon, 5 Sep 2022 17:39:46 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id y3so19930363ejc.1 for ; Mon, 05 Sep 2022 17:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=i2orbtExQlccm1w/BNraKCbJoQoonFPa3RMVK51xch0=; b=Y1GCnRYVDCZj/JilpGzJOPsi8VHlBxjzp/rCB5CLIbFSPdgUEYE2ahS03ZdUE+sJDU 8NJy4IHaYFrTzV+0+ESZIta0w7sl0uA3Ixc5yMl/YSH1VpLqVsyJq9STwfY4Y1XcSUn7 fbBq6WzStegaXoRA+5Z/afUG5AbMoeZUmJR0Gtp2NitJXBAbyRkwkOdOXtt8tSaLYV9F 5x1lHIiSTQNgbkmTvUG4byhR8u9Slp49luKoi/qlTxzxD0iVLRnhCltvxAQI4U8nWKmn 7wN7hif782eRJ60efS3E1o+O0TxX7axnYh9ZZIAh8Q1va6JJGmXZtGhmZx6oVmotLXFN ZZpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=i2orbtExQlccm1w/BNraKCbJoQoonFPa3RMVK51xch0=; b=Ru8BeVZSafEBL12brZgUGYi1zGcI23unXuRBfgQi9tsOHxkQ8T0fFNnr63vFcFZKR5 NfI6N7sDCDtQ3wwg/KYqPrsZHr5KpLl+251NuOPctf8/fqG80+w91HYCTk8h7UaTg3jF hEreGJEpNcaURwbqIs67yrSzYOnmq5dEzzJs0wroERPhtZTS9FUOAxV/4NEmRrS4xrHf k3cQ0+iep/O+Vq2zDi6OEllan5XHImuYvhpxqMaTqNymOfRHFTZrkLGhU+GNqIjKHVF8 Gb9goj7FSNFzpQea5tjOXCppncXP6jdMFs6WkjguOEplsHNwsTeFSg/pMas6v94xL26A xq9Q== X-Gm-Message-State: ACgBeo2UqoBLQBPqBCVvTM17LIeSRvkSZFPTb7hKIJrEZh8Su82Aeon0 6+qudzU00VHuZydXHByCc4RZbSDGVIaYHK8JRAdaFKuzOEo+AQ== X-Received: by 2002:a17:907:842:b0:731:3310:4187 with SMTP id ww2-20020a170907084200b0073133104187mr35019845ejb.578.1662424784840; Mon, 05 Sep 2022 17:39:44 -0700 (PDT) MIME-Version: 1.0 References: <20220902232732.12358-1-rick.p.edgecombe@intel.com> In-Reply-To: From: Pasha Tatashin Date: Mon, 5 Sep 2022 20:39:07 -0400 Message-ID: Subject: Re: [PATCH] mm: Check writable zero page in page table check To: Rick Edgecombe Cc: Andrew Morton , linux-mm , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sorry: s/Rock/Rick :-) On Mon, Sep 5, 2022 at 8:38 PM Pasha Tatashin wrote: > > Hi Rock, > > Good idea to add a check for write access to zero page. Can you please > also update Documentation/mm/page_table_check.rst ? > > Thank you, > Pasha > > On Fri, Sep 2, 2022 at 7:31 PM Rick Edgecombe > wrote: > > > > 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(+) > > > > 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); > > > > base-commit: b90cb1053190353cc30f0fef0ef1f378ccc063c5 > > -- > > 2.17.1 > >