From patchwork Tue Dec 12 23:16:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 177667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp8061048vqy; Tue, 12 Dec 2023 15:18:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnnAj+CXYy/LoKP+ZD99imzRW8Iq3hs0YPyx/JXKArbNm3QC57MAaFGpLbMbOkmDmumQac X-Received: by 2002:a05:6e02:1be5:b0:35d:59a2:a32c with SMTP id y5-20020a056e021be500b0035d59a2a32cmr7087520ilv.46.1702423100531; Tue, 12 Dec 2023 15:18:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702423100; cv=none; d=google.com; s=arc-20160816; b=WaT/2fzd+Vkkr0vYfyPDhxLNBRrrn3/pL59F6zufDnWJn4tBhN6aNAOB/Z0XvRN5fQ ds3iAYO/xjQx8hC7IJ9YhswQl9Rq4+6Rmu8l5fM5bIii/R6zm3l9XMeK4p7l3L09aPee otYRNCw9mCUtLkwR1L/+2d+inT/gNDe4Unz6KJ+PweavBolOAsoSt88jq235AiFD2lNv bEGRw26tr05n3UyjJZ+X9meIc08jT9ofA6smWh9QG3HFUgYAROjVf1YRhkPXOC8V/s6k cG9zyMmS74LA+RYBXfUnhIAXgBtFkQwATYUegl6gPjUYnz6kqZBw//kbSif6kDxsrska OGgA== 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=nL+BTz2K9JmfgWW40zZKnYHQ0fFwxEyXyS5r4SraM1c=; fh=0mRPlJo0PPrkJQqE76MB2W/JiJzBa9Y7evJmiT9T7OE=; b=XUaOjC6e9YRH2NuMC/RwkdnrNBTnsiA+8L2SDoWoc7cJM/wOXYE+AE1kkeNa7dMmSu y7RohC2nr3hECji0EQeEZdqTm8Jno1ZmQxwklKz1pJIyKohFUMtnCHgHhjKf3V9nUU91 VATkpwI4EPsGg6kJssbUVdfeinuJDyxDPdPiJlpoFJFit82jMBifNuHPbiXJKLsWc4EB PrWXGX7XTTC1MCdRZ+/xVqQWNhih7IEETBN2RE7qdWvsS2jg6S4PU5oERVU0E0fJ4WuT 7W9vIEdY8W0qmxH17voq1DhdYwLddWKaJS4p5vjozvZYT3w+zsOkC+IAs90nO9bAbBMQ 9N7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TyBjuWlz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id y31-20020a634b1f000000b005c635a9d1f2si8300793pga.156.2023.12.12.15.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 15:18:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TyBjuWlz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 7631C80B26DF; Tue, 12 Dec 2023 15:18:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378020AbjLLXRS (ORCPT + 99 others); Tue, 12 Dec 2023 18:17:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377983AbjLLXRK (ORCPT ); Tue, 12 Dec 2023 18:17:10 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10091DC for ; Tue, 12 Dec 2023 15:17:16 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d03bcf27e9so39463435ad.0 for ; Tue, 12 Dec 2023 15:17:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702423035; x=1703027835; 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=nL+BTz2K9JmfgWW40zZKnYHQ0fFwxEyXyS5r4SraM1c=; b=TyBjuWlz2QWPbohiHkWTUANQfk4hCqqFjbNhgTsqEpaS3knwjlCsXJVWKWwzvBHIyV iew2Ew/6Ai7U/QGnuhP/wf45FSx+1sw8siUl2EpanVEvmZsyDwijfgEO/P33jP7y+b/S 4g95Imryk63/kRG8ozB3rZyt10UIxvTHCM6ak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702423035; x=1703027835; 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=nL+BTz2K9JmfgWW40zZKnYHQ0fFwxEyXyS5r4SraM1c=; b=iEL/D4GuAHRS8/LpqW58OdXTNxuWIb8HdbhtwodqJ1DzN1n1pUTy/XB2bZlawFbuzu F4f7TwJvwDmj+wHJ1R+dGH8DY1V+pEObxne/s4o4ogl4tE1IU9Z5URGTeYpcX4swoeCM dHkPjSimUTo1ANoLlOuNiQOA/MLEjnWrnH14WjAm9X0cEKZJjDSj6G7ntdSPssvBqLkd 99HcnCd36AqKtk4VaiAJY9eQMM91XFGX2UPczrzR7n77v7y4QX8g6ncsPj0zXsoUWDEK yFVQVQSlyMHfk5rteH5NF7f6nSdjdfZqsfPi8QeC8ToAzJYGZ7ssKYHZ8N18SUcqveZz eyFA== X-Gm-Message-State: AOJu0YzT1ff+x+V000Vi/1RkFJ7nK6wwu88O472/tQL0G15xdJqFQ8pD 5aoQgLTvq0l9vDXmHcrXoi/yIA== X-Received: by 2002:a17:902:b702:b0:1d0:7d83:fdd9 with SMTP id d2-20020a170902b70200b001d07d83fdd9mr3543832pls.122.1702423035559; Tue, 12 Dec 2023 15:17:15 -0800 (PST) Received: from localhost (34.133.83.34.bc.googleusercontent.com. [34.83.133.34]) by smtp.gmail.com with UTF8SMTPSA id h2-20020a170902f54200b001cfc67d46efsm9074320plf.191.2023.12.12.15.17.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Dec 2023 15:17:15 -0800 (PST) From: jeffxu@chromium.org To: akpm@linux-foundation.org, keescook@chromium.org, jannh@google.com, sroettger@google.com, willy@infradead.org, gregkh@linuxfoundation.org, torvalds@linux-foundation.org Cc: jeffxu@google.com, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, pedro.falcato@gmail.com, dave.hansen@intel.com, linux-hardening@vger.kernel.org, deraadt@openbsd.org, Jeff Xu Subject: [RFC PATCH v3 05/11] mseal: add MM_SEAL_PROT_PKEY Date: Tue, 12 Dec 2023 23:16:59 +0000 Message-ID: <20231212231706.2680890-6-jeffxu@chromium.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231212231706.2680890-1-jeffxu@chromium.org> References: <20231212231706.2680890-1-jeffxu@chromium.org> MIME-Version: 1.0 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 12 Dec 2023 15:18:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785120005377952318 X-GMAIL-MSGID: 1785120005377952318 From: Jeff Xu Seal PROT and PKEY of the address range, in other words, mprotect() and pkey_mprotect() will be denied if the memory is sealed with MM_SEAL_PROT_PKEY. Signed-off-by: Jeff Xu --- mm/mprotect.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/mprotect.c b/mm/mprotect.c index b94fbb45d5c7..1527188b1e92 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -753,6 +754,15 @@ static int do_mprotect_pkey(unsigned long start, size_t len, } } + /* + * checking if PROT and PKEY is sealed. + * can_modify_mm assumes we have acquired the lock on MM. + */ + if (!can_modify_mm(current->mm, start, end, MM_SEAL_PROT_PKEY)) { + error = -EACCES; + goto out; + } + prev = vma_prev(&vmi); if (start > vma->vm_start) prev = vma;