Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2545277rdg; Mon, 16 Oct 2023 07:39:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBBNB2sv+PlJPw8prEtBJoeuxXZiExMcpEcxlcqC8Hg1uOeqR1PCkQHj2WbtO5WEdXheNc X-Received: by 2002:a17:90b:1d09:b0:27d:549b:3e65 with SMTP id on9-20020a17090b1d0900b0027d549b3e65mr5653813pjb.49.1697467194336; Mon, 16 Oct 2023 07:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697467194; cv=none; d=google.com; s=arc-20160816; b=tyA6Bjkd34oVKo9eWdBEko6QUTygeXNYzEf1GdTLSvfolaU5hpk35vGCS1pTGOPiI8 6PjLKzO/f0Xj9QJCEzPGxt0ZMAZt63NvKTIz/nszVpHRYSEBl/1ju4ASeJ4W062NkAgU TMMQIs/KVLe0F5h7zRS/XSpymeMdeqCU4OftreRtbABZjarvsQGrCcBZd5Fyelde95eu k1jV+6gBFas/uA0IVF5CcaYHo1zGJG0/sK7Q8K1qZZ94n3+ODdFQ9w0FC1LiXanAXoLf f6HCS/VIAy9e3OTbXY2KpPGGK3yKclxYUrwb96fmi+lW/I3WLh2SuT/BPTO+O1dTFW2E gCog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+0Sn/gKJWR6siX+0KJWM5lAESAe3sWf60qybDDt1Pys=; fh=wJt2vb9KzEoDMQtLcj0GhnYB2FPMxiy/u0FWfD8Wss0=; b=WDLEGOWSC7cyuHnuc08A6A8vmdWZxZ7wrRaVMpq6/kCCpC9c68UNJWIw2wxORyYB22 8HQKuSxU4p8YOFtAHNafaMN14WijXQVAy5R5qj5ZUlTwJWa9G/P3xa7/poVgbQGG7ZeZ ch/Fpo3CsMKObh0Ce8iKEhbWXFpYDI7wTRLDsKaydpZs9o0gt9qQ/rCjDgjYWeoiJxDW PYeE+iLMRdz2a8v6zMOt1An9+akh5D+OlWwstrCfLGChI+xe+gJvME8Qs6DQExkrEjrH y69URmUY86OpmAogIZkIzta7eL08a0bMoxUsQRQJoAnqpu3GmuYzzslHXkb5HQElqRnB Op0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SyHIg9Dz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l5-20020a17090aec0500b00276c4e7b5e2si6330783pjy.146.2023.10.16.07.39.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 07:39:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SyHIg9Dz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id F09DF80225AA; Mon, 16 Oct 2023 07:39:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233708AbjJPOjX (ORCPT + 99 others); Mon, 16 Oct 2023 10:39:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233411AbjJPOjH (ORCPT ); Mon, 16 Oct 2023 10:39:07 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B780EE for ; Mon, 16 Oct 2023 07:39:05 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c8a1541232so39548665ad.0 for ; Mon, 16 Oct 2023 07:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697467145; x=1698071945; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+0Sn/gKJWR6siX+0KJWM5lAESAe3sWf60qybDDt1Pys=; b=SyHIg9DzLy+zp4y+Yjhwxt7wJqC+tl1u18o8eoNRpREPgA952TWGap3RWoHe48fL/B lmPrS1T+aBpXzrmOxFFdrcwxUHbvE7dcFfK2m3qQPckUiVWb4eLDa+6NG1GMgzX8Lhtv Tl8DP06YSVWn5f2JDlapE7Je/kQQC73QZ0XpQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697467145; x=1698071945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+0Sn/gKJWR6siX+0KJWM5lAESAe3sWf60qybDDt1Pys=; b=LPb1qFUAJLVrV/WNWslGqjXQoCqbZUDbOKEzznQzbMDf5PlSiIWJsjLQjvPvnf2psN /70H2bFV6oEsNrjicoxwJBgjI0ygQx7HzD+fjAx6HPKEtfAIbsJPezJoBRwE9L7h0uP7 hqBCHWi4MXqpBE6guc9lzS1C0+DHzWiS4Cw+sZklT/HVU2YDY4s6IBqrG0BRt4pJopBn +Hj4ReWK+IJLmv4yeTQMEVAe6x1cQf41ox0fvtCVooj72U3J4/Az/kVRkyjevqJISu3R VhWagfGBV7+j2yyMPLLuJaYOhWvNyixc22aW/7jh6KAk4QqeNDnwtoBqD1P4XqWllTSK i1eg== X-Gm-Message-State: AOJu0Yx512a2KFo+9JjVT+I8TXtlGKaHTO6qPKLSIZOY1P/5lqc/qFOc ebImlr4BUg4wHuD+fY0UXIeLwg== X-Received: by 2002:a17:90b:1fc6:b0:27d:4283:b8a2 with SMTP id st6-20020a17090b1fc600b0027d4283b8a2mr7510538pjb.14.1697467144783; Mon, 16 Oct 2023 07:39:04 -0700 (PDT) Received: from localhost (9.184.168.34.bc.googleusercontent.com. [34.168.184.9]) by smtp.gmail.com with UTF8SMTPSA id nh24-20020a17090b365800b0026f39c90111sm5008030pjb.20.2023.10.16.07.39.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Oct 2023 07:39:04 -0700 (PDT) From: jeffxu@chromium.org To: akpm@linux-foundation.org, keescook@chromium.org, sroettger@google.com Cc: jeffxu@google.com, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jannh@google.com, surenb@google.com, alex.sierra@amd.com, apopple@nvidia.com, aneesh.kumar@linux.ibm.com, axelrasmussen@google.com, ben@decadent.org.uk, catalin.marinas@arm.com, david@redhat.com, dwmw@amazon.co.uk, ying.huang@intel.com, hughd@google.com, joey.gouly@arm.com, corbet@lwn.net, wangkefeng.wang@huawei.com, Liam.Howlett@oracle.com, torvalds@linux-foundation.org, lstoakes@gmail.com, willy@infradead.org, mawupeng1@huawei.com, linmiaohe@huawei.com, namit@vmware.com, peterx@redhat.com, peterz@infradead.org, ryan.roberts@arm.com, shr@devkernel.io, vbabka@suse.cz, xiujianfeng@huawei.com, yu.ma@intel.com, zhangpeng362@huawei.com, dave.hansen@intel.com, luto@kernel.org, linux-hardening@vger.kernel.org Subject: [RFC PATCH v1 6/8] mseal mremap Date: Mon, 16 Oct 2023 14:38:25 +0000 Message-ID: <20231016143828.647848-7-jeffxu@chromium.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231016143828.647848-1-jeffxu@chromium.org> References: <20231016143828.647848-1-jeffxu@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 16 Oct 2023 07:39:50 -0700 (PDT) From: Jeff Xu check seal for mremap(2) Signed-off-by: Jeff Xu --- mm/mremap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mm/mremap.c b/mm/mremap.c index e43f9ceaa29d..2288f9d0b126 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -836,7 +836,15 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len, if ((mm->map_count + 2) >= sysctl_max_map_count - 3) return -ENOMEM; + if (!can_modify_mm(mm, addr, addr + old_len, MM_ACTION_MREMAP, + ON_BEHALF_OF_USERSPACE)) + return -EACCES; + if (flags & MREMAP_FIXED) { + if (!can_modify_mm(mm, new_addr, new_addr + new_len, + MM_ACTION_MREMAP, ON_BEHALF_OF_USERSPACE)) + return -EACCES; + ret = do_munmap(mm, new_addr, new_len, uf_unmap_early); if (ret) goto out; @@ -995,6 +1003,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, goto out; } + if (!can_modify_mm(mm, addr, addr + old_len, MM_ACTION_MREMAP, + ON_BEHALF_OF_USERSPACE)) { + ret = -EACCES; + goto out; + } + /* * Always allow a shrinking remap: that just unmaps * the unnecessary pages.. -- 2.42.0.609.gbb76f46606-goog