Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3025899rdg; Tue, 17 Oct 2023 02:09:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFposOlgtlUGAyUVGmii0hLjU2298Q994aE5n9lj9Tam0V94eI/C6Us0joapPZsykv10Ti5 X-Received: by 2002:a05:6808:3009:b0:3a7:6d64:aa68 with SMTP id ay9-20020a056808300900b003a76d64aa68mr2282208oib.18.1697533751951; Tue, 17 Oct 2023 02:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697533751; cv=none; d=google.com; s=arc-20160816; b=gMjfA6b2XCAtbf06/1gnku+nY1NImFzMO+Nd4IZGA5Oudfvyl7zD2SIPyy/61xiWEQ PtmYMaOgYbPWetdk0hlismZWb7T/Jwz4bDDWz8SJX2zWq+022GWcYH0cg2x3X5eCQK+g 9DM2u4LVj5v1kd4gCH1GOMhMDJrFBxtHGM+88P6zRSSAEJtMkDa5rJJ7dLrbotg4jY9I yboNUvwRnBcCZiVAG4DTr/MnTtnVQfkSnSXW+IGuuMJP28lEVU0OBZLJDlVkR56aqADA ZPVwuc/L8f4BKVgm+dhyAi5g9FruSQXxxM/cmnVKkzASJhfFnj995U18m8c37ELwK++x AtkA== 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=4llBoLvRHSRPhxaAVX+Xew1tpI9xPqxP9ssy5QguIl8=; fh=YfLPDZx8HxHxm+Z3vj79olb721eA39QQcBnmwbHQL5g=; b=TCNdXQmw+CY36QIPuW4PJwsBwO1dCpjGjF+KnBdYKxa+XRblZDEZwQhG4P2svEGldE uDj0S3sKF4tKo0wqSQzaOSvT9DPM74HQNuhoSHHs7TDSfXBRd+n+giZNl3sM6P40LAeB /n4IqV2xXQrwrtdwiRev3uES3dH0elWVke+LirzmkMpIFa2W3dROsban32m6bE41yHyw hURwK1/2lJHdjfJN12TZXVAiz2ILrRzYS2fKKepr/YJPZvk73O8hgAQQkpzUVmWFgFrf Mu4w23rseCdLSd158F4rY2Bug2V+Qv185eIq9xMhleOrO4g6kWCX1fVvCE93bsaDl675 OFcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VDQppkk8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id w3-20020a63f503000000b0059779ae58a0si1382115pgh.465.2023.10.17.02.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 02:09:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VDQppkk8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 9A4C880309AD; Tue, 17 Oct 2023 02:09:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234888AbjJQJIp (ORCPT + 99 others); Tue, 17 Oct 2023 05:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234816AbjJQJIY (ORCPT ); Tue, 17 Oct 2023 05:08:24 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34D038E for ; Tue, 17 Oct 2023 02:08:23 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c88b467ef8so37116155ad.0 for ; Tue, 17 Oct 2023 02:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697533702; x=1698138502; 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=4llBoLvRHSRPhxaAVX+Xew1tpI9xPqxP9ssy5QguIl8=; b=VDQppkk8b9oCirBVlMxquQtLBR6oq+NEIUW991fieiIzfnXy0uSyhDmOQ/pFCxsfTk vNq0/t+GaIHx3RbgU+O+OsbqxmLJ+QfIBiRFL8ZupoXc2g2kM3tDfchfxPLkpoUW6Cks mSwqs/n3UF4MnYQ4QiXTGmby2Ib/D07ubXtK8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697533702; x=1698138502; 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=4llBoLvRHSRPhxaAVX+Xew1tpI9xPqxP9ssy5QguIl8=; b=epXg8B9+Go41KSaPEcmSJKrbqRpWg0hFtfhUX4qlBMjpoCX4lbfOHHrx4rhYN+GC4h Dq+PEJnPADRVzExr6ORUylZIjZ+ELhQmytGq8oZA7BEqYpyB7ptCXBTTXMUOtIHZxFLe LlfUEzdKBVIcjEt8BkdUcLYEBRWR0nNgiYfZGDv+xrFVqAPmN1mCDIm3JZgHBz/4hKBj JWG6ilsayTHIpeo/vEirZa4XzREy6AEx8Orark1Hl9w5bXfItorAr+vyzg3L0PaTkRCE 9u1sy1a+WzcoA6gpPepztnGPSOdCt8p7h/QanVkLlS7tFjO0vY+hZc9XDiIWvjDkmCvv 448g== X-Gm-Message-State: AOJu0Yz98ffbbBa+fREsc4meBC8iHnJMt3b/U/2ANZCplHasz8sfpn29 35bTnpRaMksTuFqBgMvHr7sHt/PqkcXOaTIUX1c= X-Received: by 2002:a17:90b:124a:b0:27c:f21b:6342 with SMTP id gx10-20020a17090b124a00b0027cf21b6342mr1443714pjb.22.1697533702687; Tue, 17 Oct 2023 02:08:22 -0700 (PDT) Received: from localhost (9.184.168.34.bc.googleusercontent.com. [34.168.184.9]) by smtp.gmail.com with UTF8SMTPSA id t13-20020a17090ae50d00b00277326038dasm868586pjy.39.2023.10.17.02.08.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Oct 2023 02:08:22 -0700 (PDT) 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, 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, lstoakes@gmail.com, 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 v2 4/8] mseal: Check seal flag for mprotect(2) Date: Tue, 17 Oct 2023 09:08:11 +0000 Message-ID: <20231017090815.1067790-5-jeffxu@chromium.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017090815.1067790-1-jeffxu@chromium.org> References: <20231017090815.1067790-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 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, 17 Oct 2023 02:09:08 -0700 (PDT) From: Jeff Xu mprotect(2) changes protection of VMAs in the given address range. Sealing will prevent unintended mprotect call. What this patch does: When a mprotect(2) is invoked, if one of its VMAs has MM_SEAL_MPROTECT set from previous mseal(2) call, this mprotect(2) will fail, without any VMA modified. This patch is based on following: 1. do_mprotect_pkey() currently called in two places: SYSCALL_DEFINE3(mprotect,...) SYSCALL_DEFINE4(pkey_mprotect, ...) and not in any other places, therefore omit changing the signature of do_mprotect_pkey(), i.e. not passing checkSeals flag. 2. In do_mprotect_pkey(), calls can_modify_mm() before any update is made on the VMAs. Signed-off-by: Jeff Xu --- mm/mprotect.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/mprotect.c b/mm/mprotect.c index 130db91d3a8c..6321c4d0aa3f 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -753,6 +754,20 @@ static int do_mprotect_pkey(unsigned long start, size_t len, } } + /* + * do_mprotect_pkey() currently called from two places: + * SYSCALL_DEFINE3(mprotect,...) + * SYSCALL_DEFINE4(pkey_mprotect, ...) + * and not from other places. + * Therefore, omit changing the signature of do_mprotect_pkey(). + * Otherwise, we might need to add checkSeals and pass it + * from all callers of do_mprotect_pkey(). + */ + if (!can_modify_mm(current->mm, start, end, MM_SEAL_MPROTECT)) { + error = -EACCES; + goto out; + } + prev = vma_prev(&vmi); if (start > vma->vm_start) prev = vma; -- 2.42.0.655.g421f12c284-goog