From patchwork Fri Aug 21 15:12:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11729727 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 39603138C for ; Fri, 21 Aug 2020 15:12:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 06387207DE for ; Fri, 21 Aug 2020 15:12:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VBgyPhP1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06387207DE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 315F28D0028; Fri, 21 Aug 2020 11:12:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 29EEE8D0022; Fri, 21 Aug 2020 11:12:41 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1671B8D0028; Fri, 21 Aug 2020 11:12:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id F09028D0022 for ; Fri, 21 Aug 2020 11:12:40 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B5E501DFC for ; Fri, 21 Aug 2020 15:12:40 +0000 (UTC) X-FDA: 77174917680.25.lunch08_5c1433b2703a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 6BF551804E3A8 for ; Fri, 21 Aug 2020 15:12:40 +0000 (UTC) X-Spam-Summary: 1,0,0,7e9a77b26b880339,d41d8cd98f00b204,npiggin@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:2898:3138:3139:3140:3141:3142:3354:3870:3872:3876:4117:4321:5007:6119:6261:6653:7514:9413:10004:11026:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:13255:13894:14096:14110:14181:14394:14687:14721:21080:21444:21451:21627:21666:21990:30054:30070,0,RBL:209.85.210.193:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yfa4bdnc7r7u44iu5k1w1eiazriyc8ha73weaf89ri6wxbpwnor6cnz96zhuc.k5zb8tn96h53dqjjz8hkp78kt4b6bke8qzh9q9bohhy3mrobuwdfjzmmw19tdmr.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: lunch08_5c1433b2703a X-Filterd-Recvd-Size: 6180 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Aug 2020 15:12:39 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id d188so1213990pfd.2 for ; Fri, 21 Aug 2020 08:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UY3nHiN8pgkQXggDgWgnBUQkjwXub5T9CsJzFX8rSpk=; b=VBgyPhP1+Sl/ttwJwVQxq7xmnvzliKnqHCmayEmnyxdcPFsr1octp/TFFnWKIEgvRt 294S6aSmYr6+teDwU/0oFVzm4wO8+Ym1+jXMpbnFTPBYO+2xzGlknVi7FAcl88wBr/Kn jSZkAndm5y1hxR9jtTL3QmJ/7YVnKPSdfMQyRZU97E1JDVGr3HV4RCBEpAOa/BCvA9ew PzNoQdId4cgj4lGg/uVYeDkwqO1XRV789Gm96zPIqWeFF2ms2ljOEpvTkeA0JKPRXdMQ yE1d22vcwtb7CcTa4Q/ntF/Qt3GIPcHPi4IxgVwof5EEpCPKIlnt9saulwv9E1MnoSxk SlGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UY3nHiN8pgkQXggDgWgnBUQkjwXub5T9CsJzFX8rSpk=; b=CAwoqGdxdxQsJvcpqGMuXcR1rRzv6R6l9CFfR0NMBTOGrrS5VHhZpmJ99jt2bd6tRw /SQWhKWw51ndNFn2hTL374d2tRkv0f5IhAa1Vm2C4CGB3a6rKejvN4u55LYDQUV1E50s FP4K7uW3/IsMRqTInS311+5HapgnZmItWikBe5lLQkzEZ45VbFSXiS4JwQV7RkyO0mn2 ggPOzr8vphhXX8/pasklj1xafXCGhcz+fypiWRLdGQScQUiTyIpVPAG1SxDUxwRag+XD DIMzdwGyYxqTAUIr1ERc3yJXV67hx8j8VzQLFplQYUS1J2xtTw2e5DajY4P1k0Z9lBgg qMbg== X-Gm-Message-State: AOAM532iILjEOXEOvcMyqGJh6O7SXRpdSH1DZkCu77dxM7EkbWWSqMMO 1Xawa56G1KER89kluZx1tqZi+wpJvO8= X-Google-Smtp-Source: ABdhPJyCXdSqBEAC0kFcsNvD5EqD53KjatKAQFKOQvMLJcOoi8k3fLMlmfj8qhPEMS+C8bwc9rHuyw== X-Received: by 2002:aa7:9556:: with SMTP id w22mr2775906pfq.245.1598022758914; Fri, 21 Aug 2020 08:12:38 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (61-68-212-105.tpgi.com.au. [61.68.212.105]) by smtp.gmail.com with ESMTPSA id s8sm3126985pfc.122.2020.08.21.08.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 08:12:38 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org, Andrew Morton Cc: Nicholas Piggin , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Zefan Li , Jonathan Cameron , Christoph Hellwig , Christophe Leroy Subject: [PATCH v6 02/12] mm: apply_to_pte_range warn and fail if a large pte is encountered Date: Sat, 22 Aug 2020 01:12:06 +1000 Message-Id: <20200821151216.1005117-3-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200821151216.1005117-1-npiggin@gmail.com> References: <20200821151216.1005117-1-npiggin@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6BF551804E3A8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 this might mistake a large pte for bad, or treat it as a page table, resulting in a crash or corruption. Signed-off-by: Nicholas Piggin --- mm/memory.c | 60 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 602f4283122f..3a39a47920e2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2262,13 +2262,20 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud, } do { next = pmd_addr_end(addr, end); - if (create || !pmd_none_or_clear_bad(pmd)) { - err = apply_to_pte_range(mm, pmd, addr, next, fn, data, - create); - if (err) - break; + if (pmd_none(*pmd) && !create) + continue; + if (WARN_ON_ONCE(pmd_leaf(*pmd))) + return -EINVAL; + if (WARN_ON_ONCE(pmd_bad(*pmd))) { + if (!create) + continue; + pmd_clear_bad(pmd); } + err = apply_to_pte_range(mm, pmd, addr, next, fn, data, create); + if (err) + break; } while (pmd++, addr = next, addr != end); + return err; } @@ -2289,13 +2296,20 @@ static int apply_to_pud_range(struct mm_struct *mm, p4d_t *p4d, } do { next = pud_addr_end(addr, end); - if (create || !pud_none_or_clear_bad(pud)) { - err = apply_to_pmd_range(mm, pud, addr, next, fn, data, - create); - if (err) - break; + if (pud_none(*pud) && !create) + continue; + if (WARN_ON_ONCE(pud_leaf(*pud))) + return -EINVAL; + if (WARN_ON_ONCE(pud_bad(*pud))) { + if (!create) + continue; + pud_clear_bad(pud); } + err = apply_to_pmd_range(mm, pud, addr, next, fn, data, create); + if (err) + break; } while (pud++, addr = next, addr != end); + return err; } @@ -2316,13 +2330,20 @@ static int apply_to_p4d_range(struct mm_struct *mm, pgd_t *pgd, } do { next = p4d_addr_end(addr, end); - if (create || !p4d_none_or_clear_bad(p4d)) { - err = apply_to_pud_range(mm, p4d, addr, next, fn, data, - create); - if (err) - break; + if (p4d_none(*p4d) && !create) + continue; + if (WARN_ON_ONCE(p4d_leaf(*p4d))) + return -EINVAL; + if (WARN_ON_ONCE(p4d_bad(*p4d))) { + if (!create) + continue; + p4d_clear_bad(p4d); } + err = apply_to_pud_range(mm, p4d, addr, next, fn, data, create); + if (err) + break; } while (p4d++, addr = next, addr != end); + return err; } @@ -2341,8 +2362,15 @@ static int __apply_to_page_range(struct mm_struct *mm, unsigned long addr, pgd = pgd_offset(mm, addr); do { next = pgd_addr_end(addr, end); - if (!create && pgd_none_or_clear_bad(pgd)) + if (pgd_none(*pgd) && !create) continue; + if (WARN_ON_ONCE(pgd_leaf(*pgd))) + return -EINVAL; + if (WARN_ON_ONCE(pgd_bad(*pgd))) { + if (!create) + continue; + pgd_clear_bad(pgd); + } err = apply_to_p4d_range(mm, pgd, addr, next, fn, data, create); if (err) break;