From patchwork Sat Jul 22 23:15:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13323058 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 8563FC41513 for ; Sat, 22 Jul 2023 23:15:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 837BD6B0072; Sat, 22 Jul 2023 19:15:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BF0C6B0074; Sat, 22 Jul 2023 19:15:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 649C06B0075; Sat, 22 Jul 2023 19:15:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 441636B0072 for ; Sat, 22 Jul 2023 19:15:18 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0CD8180672 for ; Sat, 22 Jul 2023 23:15:18 +0000 (UTC) X-FDA: 81040805916.10.996937D Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by imf17.hostedemail.com (Postfix) with ESMTP id 2D6314000E for ; Sat, 22 Jul 2023 23:15:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="bY/thvLc"; dmarc=none; spf=pass (imf17.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.182 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690067716; 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=Dz1WtFDUN503GFfPrb86//foDSemE6Fx12xrK89H/vw=; b=hjvIf0bYqKU/6Q4WovbYkq2umHIZgD81NfkeIFrfLQX2cHS/3N1NT+1qhQDt7Bq4PUFJYG Ei+N7Ok9K8g7G+ErRtoOC00zLtMJ7i2tKrPrZ70FPMrk0rBqEn5gvruTsdQxyzJAjlyNTH gZDU8psEW2qbZSP2k4AxbuFMIFdq75I= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="bY/thvLc"; dmarc=none; spf=pass (imf17.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.182 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690067716; a=rsa-sha256; cv=none; b=PLIXlnBBikru6k0amYnrBZrhSzgCidYAG4VfY48LLZ2KDM4GJXPfeBzHkfBQxBHHaSi6Fx nRAKkemTwp3mmRbHzo7B+LdVXX4+xCDP/7gx7qwZ8W6/BRX5iVk1Ivsgdqy5AucOyXUAhP mIkPOs2pcUCM5WXxWs/4Hp6RyOU6W9w= Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7679ea01e16so289751585a.2 for ; Sat, 22 Jul 2023 16:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1690067715; x=1690672515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Dz1WtFDUN503GFfPrb86//foDSemE6Fx12xrK89H/vw=; b=bY/thvLcgkc1kW1AiaCtDdgCl0GfMZRm3ZXHre3bwwItwa2QFP+rNHHQro/QmoOQff SI+ax91vPJVjZuEexwJ+NcNiJvh4ZD341RywPTp5zViX/QpyMlKvE3BatWDge2b9aXYf XRzErIo70NKB3/0lov6evFqbdQDftwlrF7WGfTt7v1ErLh86yDMTI1f/NmNREfl6eeu9 JT2qhvs7omUMVpT19OxD5mhUoM7yVse9sNIt+segHAFkLEZSDmqFDZIBfzvQJAbRxmEO dHiDwjGBelZXtngdm3adx169KFbtYBzX1XRUx1NX2rbo7fGIjG9wank6BOnumMU7frS0 bjlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690067715; x=1690672515; 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:message-id:reply-to; bh=Dz1WtFDUN503GFfPrb86//foDSemE6Fx12xrK89H/vw=; b=iZAP5j6Qz4SYrkJlufM4l8MhEWRyGTUFzmDJo9e+l64LiIn5bvpmTaIZTwCvd2lORH qhBd/SYhuRlEVwWEqog/izhtvZYtTdBLhiNb02mCgPRcXfWN7SRoQQEA9Uzt4KDtjV+F 1k1RgwZbu3M3F41FzpGBzXYFLVjqfnmDRHaRyZiNGEXyl8/eUA6qxYVnl+zlIcITrrE+ k9q/oW13Dnl2/KeTjT7YKXDa6A4LPYBEVz+wN0AHFDy1kWv+cXnItu0J1dUW9k80Vd3a YN4UD6prWpfZimxwYoovYzBUNGBmIhjygg1R0xK9i2FcVo+CtkXoIVjaEdztG2qqUp8h Kj1Q== X-Gm-Message-State: ABy/qLYsoYRUodwdZZhlt+cHp58arhkwEDfBjGWH1MIoF89saCfIN6cn JI346g2H7Q01xhpt7aWWszW5YA== X-Google-Smtp-Source: APBJJlHl+ww4l/5L3aVaKf+nyHJSNfnHmrmG6yrGFh/lnSNpYxDd9Cn/A23HI9OTbXjjHyktI1V6bQ== X-Received: by 2002:a05:620a:158f:b0:767:e27d:99fe with SMTP id d15-20020a05620a158f00b00767e27d99femr3915518qkk.29.1690067715304; Sat, 22 Jul 2023 16:15:15 -0700 (PDT) Received: from soleen.c.googlers.com.com (193.132.150.34.bc.googleusercontent.com. [34.150.132.193]) by smtp.gmail.com with ESMTPSA id u21-20020ae9c015000000b007675c4b530fsm2075957qkk.28.2023.07.22.16.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 16:15:14 -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 v2 1/3] mm/page_table_check: Do WARN_ON instead of BUG_ON Date: Sat, 22 Jul 2023 23:15:06 +0000 Message-ID: <20230722231508.1030269-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230722231508.1030269-1-pasha.tatashin@soleen.com> References: <20230722231508.1030269-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2D6314000E X-Stat-Signature: pcgmo38fsg8kp441hksybe6jmhfy4sco X-HE-Tag: 1690067715-34716 X-HE-Meta: U2FsdGVkX1/u9f07LMQWTkfOKG71o1vAYW7As0BIa3FUuB4r/vyIg+qgyFODJTQHoMZ9HnGR7MMIzUpfjaayvJrkn+q18JzYNA9fd7lih6VgAihiAGBGq6Zy4Zuzq/dkP7saQhE33Fa+QbnoKWwlKUAmrI8U7JhA65Kbx0G/YwM9nppR3gfNsmon9jxfPXOXhJlXDh7LYFz9d8/BSL9OvR0LAvtuF5SGA7b6jNMudzojqiJG2lhfeAL9gqgbts98S41oTYRVF6FQgAhu69tsjyGT90NXrtO0B4lTiK1jxUCUXgMMFd2HkU6sdmFd+0tA3qHVYUHmf+ZJtfOV7bawHra5Lp/NZa083gqbHYWAi66PpyQKLDpGoti235hgohb9+SHDhUbE3y6JjR1oyK3KRdSHJYUdhpZKgWdWX9FCcPIIonpD1oRZFcKoiG35zD+x7xTnh6uwmdTfNERE+J0nsNStEHMFIcqWcVDQEjEsFkxNoO+mm8xQWpYR894H/Kl4G79R128atxYJ5GKisTkOCAnHCvlh4caVu0Vzt9+hAu1dNe/mV67IhEAGkGKjxK8/mLuaeVbMmjZq5rz5I16X9VnjH63d/mRKWw5t2U5fxIAi8mCzcSV7fJ9f5C990BbDhSrw96K+mDgHkblpxkwJ/nBVvD5oJluBluLzYl10zB4Z1WwJX55rgZCquifm0UN3cK+EQ3VVIF/PTaxLqSul/n1B01g79e+z3gPEX6i74S9hgP5lXfYmrEURB1ccnVtCyQPOn/zjWhji0BKSQ0kNZI3mcM+loY5w1pIZvzyCmMZ0Ymv0G3lxz88X8h0WXqzWHL9GOfuLiEPeKBw52DBVa3Pg5MNEA7skog59FCSREP4Xb0bXv9Wp+iLbS3BiYx1jc7FLgV96khL5fjPAjIgaBWtw99w4DUwVUhH1Gzj2H11qgoYgPevyWXcL5dgiH2Kx1VK1de0d0w9vA4Sz42t Swkg1fIq I3z6HD6Oe8/BEh95N4yXXMP1p6kkTxzVzg5RYfBaJx2TqJx1X3KqvowDIEFQbDfWtz4wJeaWq5IY2BgIAq5zm1caBx5jiA+ZfKwfhOiW5TjRb8cCX+dITn1NUilv22Phwo+Rj3J1dKJ1hPqFNREP0ZvIm1CX0FrR6xFYV9kNFfqjvsnMHEWDi1+egf5VMkPd7S4wZqeyy+tSpdbkRreNrCmfNT54OjDn0DzB33GYZAS6xTdgt6qUpD/9/NF9Tn/XLa1dsrB0msc6AQcZj/wVpVVLm22KAUZQm+2O8vQZpxm9ZQlPpLdFyoFuiy4XM2hEs49+S0Y0q3VWcMLilD7nV67M80U8oYPZX6rmaq7+rN9PMx9y4TPgVz0q+Eylq74u1PM36mcwpvlYncfm1Y2QBs4/WRc8YN+QKjbKWrtrtdJDPBug= 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: Currently, page_table_check when detects errors panics the kernel. Instead, print a warning as it is more useful compared to unconditionally crashing the machine. However, once a warning is detected, the counting of page_table_check becomes unbalanced, therefore, disable its activity until the next boot. In case of where machine hardening requires a more secure environment, it is still possible to crash machine on page_table_check errors via panic_on_warn sysctl option. Signed-off-by: Pasha Tatashin --- mm/page_table_check.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 93ec7690a0d8..ad4447e999f8 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -22,6 +22,12 @@ static bool __page_table_check_enabled __initdata = DEFINE_STATIC_KEY_TRUE(page_table_check_disabled); EXPORT_SYMBOL(page_table_check_disabled); +#define PAGE_TABLE_CHECK_WARN(v) \ + do { \ + if (WARN_ON_ONCE(v)) \ + static_branch_enable(&page_table_check_disabled); \ + } while (false) + static int __init early_page_table_check_param(char *buf) { return kstrtobool(buf, &__page_table_check_enabled); @@ -50,7 +56,8 @@ struct page_ext_operations page_table_check_ops = { static struct page_table_check *get_page_table_check(struct page_ext *page_ext) { - BUG_ON(!page_ext); + PAGE_TABLE_CHECK_WARN(!page_ext); + return (void *)(page_ext) + page_table_check_ops.offset; } @@ -72,18 +79,18 @@ static void page_table_check_clear(struct mm_struct *mm, unsigned long addr, page = pfn_to_page(pfn); page_ext = page_ext_get(page); - BUG_ON(PageSlab(page)); + PAGE_TABLE_CHECK_WARN(PageSlab(page)); anon = PageAnon(page); for (i = 0; i < pgcnt; i++) { struct page_table_check *ptc = get_page_table_check(page_ext); if (anon) { - BUG_ON(atomic_read(&ptc->file_map_count)); - BUG_ON(atomic_dec_return(&ptc->anon_map_count) < 0); + PAGE_TABLE_CHECK_WARN(atomic_read(&ptc->file_map_count)); + PAGE_TABLE_CHECK_WARN(atomic_dec_return(&ptc->anon_map_count) < 0); } else { - BUG_ON(atomic_read(&ptc->anon_map_count)); - BUG_ON(atomic_dec_return(&ptc->file_map_count) < 0); + PAGE_TABLE_CHECK_WARN(atomic_read(&ptc->anon_map_count)); + PAGE_TABLE_CHECK_WARN(atomic_dec_return(&ptc->file_map_count) < 0); } page_ext = page_ext_next(page_ext); } @@ -110,18 +117,18 @@ static void page_table_check_set(struct mm_struct *mm, unsigned long addr, page = pfn_to_page(pfn); page_ext = page_ext_get(page); - BUG_ON(PageSlab(page)); + PAGE_TABLE_CHECK_WARN(PageSlab(page)); anon = PageAnon(page); for (i = 0; i < pgcnt; i++) { struct page_table_check *ptc = get_page_table_check(page_ext); if (anon) { - BUG_ON(atomic_read(&ptc->file_map_count)); - BUG_ON(atomic_inc_return(&ptc->anon_map_count) > 1 && rw); + PAGE_TABLE_CHECK_WARN(atomic_read(&ptc->file_map_count)); + PAGE_TABLE_CHECK_WARN(atomic_inc_return(&ptc->anon_map_count) > 1 && rw); } else { - BUG_ON(atomic_read(&ptc->anon_map_count)); - BUG_ON(atomic_inc_return(&ptc->file_map_count) < 0); + PAGE_TABLE_CHECK_WARN(atomic_read(&ptc->anon_map_count)); + PAGE_TABLE_CHECK_WARN(atomic_inc_return(&ptc->file_map_count) < 0); } page_ext = page_ext_next(page_ext); } @@ -137,15 +144,15 @@ void __page_table_check_zero(struct page *page, unsigned int order) struct page_ext *page_ext; unsigned long i; - BUG_ON(PageSlab(page)); + PAGE_TABLE_CHECK_WARN(PageSlab(page)); page_ext = page_ext_get(page); - BUG_ON(!page_ext); + PAGE_TABLE_CHECK_WARN(!page_ext); for (i = 0; i < (1ul << order); i++) { struct page_table_check *ptc = get_page_table_check(page_ext); - BUG_ON(atomic_read(&ptc->anon_map_count)); - BUG_ON(atomic_read(&ptc->file_map_count)); + PAGE_TABLE_CHECK_WARN(atomic_read(&ptc->anon_map_count)); + PAGE_TABLE_CHECK_WARN(atomic_read(&ptc->file_map_count)); page_ext = page_ext_next(page_ext); } page_ext_put(page_ext); From patchwork Sat Jul 22 23:15:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13323059 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 8799CC0015E for ; Sat, 22 Jul 2023 23:15:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F6946B0074; Sat, 22 Jul 2023 19:15:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 130436B0075; Sat, 22 Jul 2023 19:15:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC4C36B0078; Sat, 22 Jul 2023 19:15:18 -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 C59D26B0074 for ; Sat, 22 Jul 2023 19:15:18 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 99959A0418 for ; Sat, 22 Jul 2023 23:15:18 +0000 (UTC) X-FDA: 81040805916.04.2BFB66E Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by imf18.hostedemail.com (Postfix) with ESMTP id E33931C0002 for ; Sat, 22 Jul 2023 23:15:16 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=GEwr0q4z; dmarc=none; spf=pass (imf18.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.42 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690067716; 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=AN03s9OeFU4xgplmqM3lIZ6LlOvPnGJDa4y5aw2r6PE=; b=shmsdPQd+uciEL+1GnITREsxD+Upp1ZwwjXjWS1oRz70o/srEHwpnB/3MUzKGDwrQNVHPy q0lGOXPgPbiCu3rPu8uCuuq50soI3KOzVu+NgHVMkXy+cWJimMoQixij6FVxQv0DkIBdip +yIp7NHOgQJxcG7MwAH+j/3g8Rr+RNQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=GEwr0q4z; dmarc=none; spf=pass (imf18.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.42 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690067716; a=rsa-sha256; cv=none; b=8E089fxOsIdaOF7xU4Lje0rjjEwBbivhLf0DElNtbYwSPGX6Pv9/ClodKdWGpUdPmvJM5a 4DEbJHIdexD1KhucD03rodYcfYhfYEhgwuGUmC15ESc1FQ775xPDRVVktUaqpXjju9zbCc tn3XjgigQIUsWlChB+eC4GKYCEh9YL8= Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-63cf7cce5fbso1918456d6.0 for ; Sat, 22 Jul 2023 16:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1690067716; x=1690672516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=AN03s9OeFU4xgplmqM3lIZ6LlOvPnGJDa4y5aw2r6PE=; b=GEwr0q4z/KJrBbjpH9m4mksCYYGzhmQBkldWwvlrkzZPNUFMo+33zYjKWn236Rz5Jh mNrrcz1WM/1Zm1p4HZjzbp2iOD9Y5Thnv6+TJ4aBxLzCWX9PTygswuQC8+LqS2O5UYva zr3rAoGqN/oYoVNT6hMhFhQCZXGMeXDs3m3dALlQzfV5RH0/CbpIDYZ9GLKnBfbJeNrA fUkGhNpwdYXj8QTjTKXHA8gCo10j3oZij5KaRCcRWldrqMIvfZjg/UXbGDHeJUE/BZk9 3Wus6jWqwnVJyxWj53YeX8o6cUJ+8Ed98IR/js9MS6gJHzN9MVBtaCE912d72lqlkRm2 duUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690067716; x=1690672516; 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:message-id:reply-to; bh=AN03s9OeFU4xgplmqM3lIZ6LlOvPnGJDa4y5aw2r6PE=; b=jTtvfuppAypygbcLmpMv1IxLRblyDWPB+oJ0fX2M6Gr+zdU3uVMDPK1QkWE/sAl8Pc Ek5uvx+Z/wWAzON4CHyWL54HhkcqGbeNIF5I00uqrhJnZnkdwAcsn7OPymcF4R4sGSeG TZpSJsPPqxgt09wYEIPDyLPJVukv97bYyiEFiGEGOI2UU5FjcLYCrIkGlDWpN5Mco5Wl s7k8fEtxpUyJawKUxtqEezH7ZqSKeWBhjK4PabnRkMJm6GuqDiU00mQbo8kJpNdcncNF WENl2S0L7MA61By52G4TCy5PTJ2EDTBzEUi7mc8Kqw8FtVii8hG9Fg+HjJEVtoVwD/KQ I+4Q== X-Gm-Message-State: ABy/qLaZNAV667k1hwa9gQkEwuppmaUoL8b6JKBx0KBFD7MGcWfv4rlc Hca8Z5ocg3vlwER8qbu9moLnnA== X-Google-Smtp-Source: APBJJlFgPvVh9jusGtl/aMb2jHxgpWDCI2Ta53l5JgMLT6qMwivZP9ZENOy3ByIlqRkIvorgLDUVUQ== X-Received: by 2002:a0c:e049:0:b0:632:80f:4728 with SMTP id y9-20020a0ce049000000b00632080f4728mr3778989qvk.27.1690067715976; Sat, 22 Jul 2023 16:15:15 -0700 (PDT) Received: from soleen.c.googlers.com.com (193.132.150.34.bc.googleusercontent.com. [34.150.132.193]) by smtp.gmail.com with ESMTPSA id u21-20020ae9c015000000b007675c4b530fsm2075957qkk.28.2023.07.22.16.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 16:15:15 -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 v2 2/3] doc/vm: add information about page_table_check warn_on behavior Date: Sat, 22 Jul 2023 23:15:07 +0000 Message-ID: <20230722231508.1030269-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230722231508.1030269-1-pasha.tatashin@soleen.com> References: <20230722231508.1030269-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: E33931C0002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: b67yxn9718chnhgh6ixdcj8dymyhdnxg X-HE-Tag: 1690067716-251518 X-HE-Meta: U2FsdGVkX18TS5ZRlQQ25KkhqyRXLurvIqcCBokCQjJVEkjlQhtLBPn249Krl0rlKnQhf/DI02/rpDOBZPuN8xTnbdc419iKeKvRUMU+UhpIrA1/cVnLbT6bXVcA/CpBwiBT9rqPkxT38+bNJffV0s2DWIsQIWq3OHyyL8vcm0y0eFgzpEudxAb1Mw+4JVKunL5/GbJ5mhORxWUsdXMhhjhCGGRrvI+8oHo25BKmmsH5PLGiULl0PevJ0Fk851C6OZY9yQpqr0kpwT4RJiKVVdFnKl6t2wBSKWx//acNdKUUpT62q+Nm8/LU4Oev5vUnSzLXOYg3/SEKS9WjklKoT/scJRaa7joXrUhhGy4ZJujYb7GOGyPVFkoHWJ85nOUExSL0TLHv6qM6Gb/a+CYOj96+kMCDBhhVVHU8SLfQ6D1yRN0qPS5kcy/tWW5hH8zzJ9OZy5BxZ3UqtX9g0av4TKRdbobTLl38k6lLgMf3JmtgeVefWjEwooxZMm8GIN7Owak+OeKUIUgP2nEYH++k7k3MqyL02zVVZ7SFZgLvAvVEXOwCp1SMx/V3w4XuLVWpc7TWP5dQCZwN8q7Ym9RvvRycqYl8MZ7c3oukMKFBMzDoO5y7MbaIc8/hvn3uGE+lPLBHOMrrU1ry0rT19XcWI87TDnSf1F86ZI+BCbrNvRPFgV1U9uD1y3uRqUDvxtAwwamShC59jpjzl14Z/ahS6FyjhCbAIsq5FBYZH6KrhMr+qXSeQoCSWPNWjTlQDkLFKPTPbahWXQJ/Od/uQjxIAoDM5ym3a/qjypXDIndgoIphwtwqi2cc3Q7EAz3mOfTSZCqvFI/DXmC5u+FSNYgpeok5CMtCDxTTeYtoiseWUKYRmEAPA2GCzaNx/E8b6pMA3AUsjXeN2yHLzO/wUsNekmsAXw292YZfhmXdA1mcs4Px4QiQ4LZwHBrcC2XwkDbm1xcUr+4dv2odQ8BmF/Z XIaCYypv M3CFTmYAx3CIPuMLKvr8qJ3MvHnLR3XRjunhQZpvIiiZbkjymTDoyQ2SOfuFKA2xXD+tJRQqN1qcvRI125GcobOWMSoxx//pw1uoReJWIVaTztZwLV03CCNjCvy+WqfcC1iQoRhG2drAElbu/KCK3A5JfNrr8HcWMg77oCLUZLdTwU1uQ7i2snSqCkk64Mcb9oOkGLODvZuqNnlTC0f2dWRkVlbo4QA6qT32+3GTmTh32fmMLqIrPE2kU2UDSIbsJrafOMsjTvulgof+pYCeVHBsMRAbu5APbMsijRmV/jUpIt+0bLCAsp/dEQt1Prwf7Lo2H58gsHe71x2AcIVy6vWH23xW2liPrkYjuDVxNQ2kqk3peUuHmo9jb/317FzhpJdj2QiX7F6xsbXlJbQRoDWW2KikIEcSE0VrAN4dyeOC5JyY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000010, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The default behavior of page table check was changed from panicking kernel to printing a warning. Add a note how to still panic the kernel when error is detected. Signed-off-by: Pasha Tatashin --- Documentation/mm/page_table_check.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/mm/page_table_check.rst b/Documentation/mm/page_table_check.rst index c12838ce6b8d..f534c80ee9c9 100644 --- a/Documentation/mm/page_table_check.rst +++ b/Documentation/mm/page_table_check.rst @@ -14,13 +14,14 @@ Page table check performs extra verifications at the time when new pages become accessible from the userspace by getting their page table entries (PTEs PMDs etc.) added into the table. -In case of detected corruption, the kernel is crashed. There is a small +In case of detected corruption, a warning is printed. There is a small performance and memory overhead associated with the page table check. Therefore, it is disabled by default, but can be optionally enabled on systems where the extra hardening outweighs the performance costs. Also, because page table check is synchronous, it can help with debugging double map memory corruption issues, by crashing kernel at the time wrong mapping occurs instead of later which is -often the case with memory corruptions bugs. +often the case with memory corruptions bugs. In order to crash kernel sysctl +panic_on_warn should be set to 1. Double mapping detection logic ============================== From patchwork Sat Jul 22 23:15:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13323060 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 2831AC001DE for ; Sat, 22 Jul 2023 23:15:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C56576B0075; Sat, 22 Jul 2023 19:15:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B41DD6B0078; Sat, 22 Jul 2023 19:15:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 945616B007B; Sat, 22 Jul 2023 19:15:19 -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 7E33D6B0075 for ; Sat, 22 Jul 2023 19:15:19 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 43E97C06AB for ; Sat, 22 Jul 2023 23:15:19 +0000 (UTC) X-FDA: 81040805958.01.FE99676 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by imf05.hostedemail.com (Postfix) with ESMTP id 828DF100005 for ; Sat, 22 Jul 2023 23:15:17 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=h4VGOvKM; spf=pass (imf05.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.182 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690067717; 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=jqX+omN+4AV/jEW9gJWFZdBmlFQeDD8EFviSI3KwL+8=; b=zKmIHknLNegSvMXYuiIBZgyViujoC7NFeSpJCwgZfog5Ak6sK62fgtXXANZK2DFSy+Jtkp 3SV+7lIkX7kCHr2guR1Xo8FbfDPWGm6aoeXCBCcGK5SdQD+PSypFW3m0osYqtzX6XBDezF hnWoIecHBWfOydsoIjdKFy8vhP00YKo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690067717; a=rsa-sha256; cv=none; b=DfvOgWYQYKfUReaF64+9qkysLVX22cXhF5nlrJYTYjUghQV+QePvtmIdpPXO/A3MDB+lQr eZrIUlr4Jp9HEs54Ev/80s5OFhcuUafgroq8RI/Vn4YWbhqbHR+O3o5w3nji9W+H9bo13l JOY3mkHkmPYWIRyyTaC59OE9SwHeW7U= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=h4VGOvKM; spf=pass (imf05.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.182 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-76754b9eac0so292676985a.0 for ; Sat, 22 Jul 2023 16:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1690067716; x=1690672516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jqX+omN+4AV/jEW9gJWFZdBmlFQeDD8EFviSI3KwL+8=; b=h4VGOvKMgez+/NKOawppSiHt7934PF71iQ7qv8jvSgyoGVHQdeSp1JgcRIsn2D88hx g2qwPAuZJScjWF75Ou+qLGKjKOMoBD6KgtLtf0HDYfqszmZ+yCoggVBesEXvtWMjVL8g JpUjuA4gJbUNFr73GuH0FlWZrgf5yI6+x2LMQdtPiA8g0Av/6cdf1+CYfjPWtybKpcP9 eVd7uPFytoOlTw5R5xKtG9M76QYaPDi/SS5XihMN3binOTlJbuopN24pguAFSUKmGTZV KDBH4hbi0ALobtUZ6mlYQTvapei1p+n2u+rufzxhHrLS/TA6KLItQHUFRHlM6LpiyDgq m73w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690067716; x=1690672516; 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:message-id:reply-to; bh=jqX+omN+4AV/jEW9gJWFZdBmlFQeDD8EFviSI3KwL+8=; b=aOkGwZzQ0CiQzuzJglD0TkNZofAElOht7NWE3cmS9wFLgFefpwpriKF2D15E1cpbBD R5aweFYv6iQxAP3R+uy6KfPFdAGl4Uc2NPplM25itOaurBP+p/6Izr5zXobYRzOvi3s+ zvFA51RLpf9978jRkj2b5Y6YNICNVtN9iYtTfm18+POTC135oXMrJ1v3UNb14kOyZfKU HopOKDq2RI2Iypz5G5PZNs+uRTkLCaOqfmJSGo+D75iDr7Vb1Dyl79ucMF6S05n9Xx9L GwzHx+DooxalatVyI9jxYI8XBQw7lxAD5p5UbxmEGNp+ItDbVG/k48pEhiz+Wo9EYnWu XyWg== X-Gm-Message-State: ABy/qLaj5jVYs8gAu91cH4dS//JZZyU0xRRT5w8CR1jYDNUm0wum/qen CiGlW7dJ0D4IfWxK0TuO8+W/xA== X-Google-Smtp-Source: APBJJlFbRKGfdxJ0JTND8bD4QwfCFUoHWRvornko1ZnN1WHJ1NJtPHQPbc8oka0cm1metbm5E4tqEg== X-Received: by 2002:a05:620a:2807:b0:75b:23a0:e7e9 with SMTP id f7-20020a05620a280700b0075b23a0e7e9mr4800481qkp.74.1690067716634; Sat, 22 Jul 2023 16:15:16 -0700 (PDT) Received: from soleen.c.googlers.com.com (193.132.150.34.bc.googleusercontent.com. [34.150.132.193]) by smtp.gmail.com with ESMTPSA id u21-20020ae9c015000000b007675c4b530fsm2075957qkk.28.2023.07.22.16.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 16:15:16 -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 v2 3/3] mm/page_table_check: Check writable zero page in page table check Date: Sat, 22 Jul 2023 23:15:08 +0000 Message-ID: <20230722231508.1030269-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230722231508.1030269-1-pasha.tatashin@soleen.com> References: <20230722231508.1030269-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 828DF100005 X-Rspam-User: X-Stat-Signature: baog8bbqyxb1bo9mc8ryj98g6ari3chb X-Rspamd-Server: rspam03 X-HE-Tag: 1690067717-265278 X-HE-Meta: U2FsdGVkX1+V46zj+1GQKryg2BSB3fX81EIIBWmUyJC0Kdn7+uQY8wV0PLxSh9Lmro8PS+TtCaBT9g2Qb53Zb96kwxJDdhOlLbuM8tTjHX3vRDBMH4bLgRKz/mY7gzLUE0aQUost3RiTqfpzNp5tkVcJgO+qZEmhxqcBZiN4EWnM1jS+QIVemR5oilSUb+Ev2oPYASLaIGLkcUxZdwTKLSk70q8lWACKJtv1k2xSz2qAU1ug/RgT2wswJJ5KYeatDxkTqC88RujDnvOviOQV6lkbgz4xSatGxQGTnLtq71uejIkXQg4w+wD7X+tIbPV3SlZM6SF6L6oLKqKBYC1NsYVVSm7HsKHUuy34OwxsAE+O6P8rYUrcRyct61GkSH+gxwqUFg2zh4e9QzE03vgGDuNgsrQ0c5Gl4RTNghbN+r3YJ7fxEtVXLnkB5K44RMTCzM9ARPGn8frZ6GooqRGInYqIi6sW/RXOOJMhogo/zcNdyy+A949JLByUiK1cTuLngFf2U1XO6xhxlJ8pu7pm+whoYwgxesCq2gZvxlLkP1JysAClG59p7W4BTEbeaVKEZ0XCJrTFNff6ggl40CJVeEwkPma1DV2eWcQ7DdiO9zQFwCFn7xDLxI6qkiiZvk7IZ/nF4Ikph9YUFyyhYrOD5RDz1lbDS415qWUJIrHymzNY8K9NA8p5CSN/7sae706txWuzCwdD2ETVeihFkjTKPc7Gto7WshctMHAEJMcBLF2CdL2wes+UUJfTUWtQ9/4+RCYDz7SkT3qB5cWhrdpiS5Wd5i1yKRVPkD80e19fTrMEn4UB3GGVM3sTeMaM1Rqc5YPwyGGJ990HCyWdq+j399yFv9OJrRNPt9b7w3FUpbEGMgQlxPrA6hJBIYmRrGwjHBJTTNvbP93naK4H2e+wcceIaYImi+hvfLnwcPUnlooB/+TH88n5X4rkUKLzArVRXoF5dVQGc4CkRwdihkx KrLYZl5A wshEHLbnGWjfMeWyYwMJsA+BJDRMLeNLSKnCbHI89hS0Ka3cXz6Ou+jiTOeLhjvpa6zisAC0Ol4Ioc0inxJLPYNznyrAGYbeG1JG/5neYl6R/RVVSCDEd2secY+9mApdLBGiDpCOCX09WOWVbmc96fLPqLc9vNrgHc47ROF9OqcB+YHq5DlJHsEb2kZNZMyCgPNbxCcORn0Akws7c71lu/jFh9V2AxOOmMqTM7eUu+RpUGHUb8fLwItxms4PQTW8uxokc1+pn/Q0i1v0naMnZJ+pvUlqgV6MVxWoVNGi2T3gJxn0hlzavwlYqvnqMo/obRV/WRd0Xe+MmkE31yCUFAwZCp5PyJpmnZEZdNLFoxdDh1TRJV93I9j1aS5D/HtMZACKuUoijnF5XcNlAMdh7953eFQm2lDbu93bAKsJnn5W0R3UwoKJRuA9zxMeK9DoJeGoG 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 ad4447e999f8..db1ed36f7203 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -114,6 +114,8 @@ static void page_table_check_set(struct mm_struct *mm, unsigned long addr, if (!pfn_valid(pfn)) return; + PAGE_TABLE_CHECK_WARN(is_zero_pfn(pfn) && rw); + page = pfn_to_page(pfn); page_ext = page_ext_get(page);