From patchwork Sat Aug 17 00:18:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Falcato X-Patchwork-Id: 13766882 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 7208AC3DA4A for ; Sat, 17 Aug 2024 00:19:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5CB26B0271; Fri, 16 Aug 2024 20:18:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D09F26B03D9; Fri, 16 Aug 2024 20:18:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5AF96B03DA; Fri, 16 Aug 2024 20:18:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 968266B0271 for ; Fri, 16 Aug 2024 20:18:55 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 369C1803E9 for ; Sat, 17 Aug 2024 00:18:55 +0000 (UTC) X-FDA: 82459827030.20.5EEDC6C Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by imf14.hostedemail.com (Postfix) with ESMTP id 524FE100007 for ; Sat, 17 Aug 2024 00:18:53 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nqmZufR1; spf=pass (imf14.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.208.176 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723853874; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yXNmIj+NcTYxWHoqolJZlZHTThjq2Cli8Ss2fpPQn+g=; b=esgHvY4oggGzYKNqmuho6C4fI215Gw/1ban2beTzdTgE8Mnn5lr8DqfAxy0OwB2j3kLfu0 aiMf3mduSXOh5mJQ1j0gNnvCNEwUiKDJoxlqKemNaa55CMwb2tSMtXefZrxVY5hA9htrGr nKJe3oBnWiLNjF12+6fGirL5vLnltI8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nqmZufR1; spf=pass (imf14.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.208.176 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723853874; a=rsa-sha256; cv=none; b=oNMOZ38ntInYKCu7CqwOqV8o616Y6ja0Aov8VFrGBbu0H8XISQrqrG8GAADCkmLSSH9MKb jA3dsj27ZMcy5EBJA9yRLCta4h6XPJk476uTJGLh0cWgjRn3T9kM9A5RRxmrnDoDIbsRKM WwF2zeHV5iXv1zd/wcodCVMXtZlZ11s= Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2f15e48f35bso26156011fa.0 for ; Fri, 16 Aug 2024 17:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723853932; x=1724458732; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yXNmIj+NcTYxWHoqolJZlZHTThjq2Cli8Ss2fpPQn+g=; b=nqmZufR1ZmNS4GvBM8ESsgQEQEhF38RTJbWzgFBgJhXpZpElwQ+mFI20QHpTleY5zL 1e2a8X+2H9OwqKKXuppEXyr0HbdZuIOyVkLYnMP+rKDluqLemhkJmmw6qMBF8bQ1n8CF aFMV1abfmdTn/OwUl3oJMS3KwodQTOQbrSh+NghmTveTc2In2PnWEfOvZJDutKZFub+A 9O6t+fLVY3NdDcOTO2Re60M5oJT+kE6swvitkQEYwAM5b846QKH0U5P4qP0+P8r2daJD 9tBqMWa62oVox/mw5vSBlGDXKAcfPyBCEZVkRUCEKz5FqqhxUdhwhFqXgGTjeU+EheWf ThmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723853932; x=1724458732; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yXNmIj+NcTYxWHoqolJZlZHTThjq2Cli8Ss2fpPQn+g=; b=tmDlb7tVJeGUzC2G0bkxz8IdSH2s0R9bTgAEsowVDn6XmqUGTimUUbCKLURqCvpr31 XpuXEltl2NsMtFAodvMSivX1Bc996cCc5VwUOFOgc1iQBqolaAzD6q/UeYXYskP5SrJr X/3PkeJnTPwtq3GkT3OZSGOzQeY8ISckA+xiEBk6SuNrRyhKgXjWoG3v+zl47xR5ZP+S Mi2MZdZLzmoHyhXTEycvhs+dAHGJz0rirSz18nDRhumSnWAXYziyUHBXE7Au5LfMirPM LnBxhfr/ESi3TNZTiVnna0wjt1j5JgsKPOv/22l5MiYy3/FLzEpowEzq1TPMzLxdF2yF YDqg== X-Gm-Message-State: AOJu0YxFbx8ZuXMig4+acDKaRkIicfMv43WSK3gGUycgweedFfSVNGHR Y3/CZpOIXJBs82jyul7gM2h5w38wo8FogcblWV43YDcBjpAKG6/Rftm3HAUO X-Google-Smtp-Source: AGHT+IFoYlT2c74A++INbVCxGR66uRuw0eMCD6t4X/oZJnDreC1ipLncpJI2gMf0RbWhFUUMPxAr9w== X-Received: by 2002:a5d:5a15:0:b0:360:7c4b:58c3 with SMTP id ffacd0b85a97d-371946a0b75mr5498311f8f.54.1723853920474; Fri, 16 Aug 2024 17:18:40 -0700 (PDT) Received: from [192.168.1.91] ([2001:818:e92f:6400:96b:aa92:afc0:2d3d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429d781047asm104842055e9.0.2024.08.16.17.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 17:18:40 -0700 (PDT) From: Pedro Falcato Date: Sat, 17 Aug 2024 01:18:30 +0100 Subject: [PATCH v3 3/7] mm/mprotect: Replace can_modify_mm with can_modify_vma MIME-Version: 1.0 Message-Id: <20240817-mseal-depessimize-v3-3-d8d2e037df30@gmail.com> References: <20240817-mseal-depessimize-v3-0-d8d2e037df30@gmail.com> In-Reply-To: <20240817-mseal-depessimize-v3-0-d8d2e037df30@gmail.com> To: Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Shuah Khan Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, jeffxu@chromium.org, oliver.sang@intel.com, torvalds@linux-foundation.org, Michael Ellerman , Kees Cook , Pedro Falcato X-Mailer: b4 0.14.1 X-Stat-Signature: 8woz18551nrdz1ps5fewt6wwmhkrnps5 X-Rspam-User: X-Rspamd-Queue-Id: 524FE100007 X-Rspamd-Server: rspam02 X-HE-Tag: 1723853933-147952 X-HE-Meta: U2FsdGVkX1+qE6NadW4Kc+LUcuw/WyAA5gV209dKwyh6C37r3hFgzWRTQF8RwRPwV/OfIakjodd1KPaHlv8brmS/eKuTaGy+qvrEMF8kjJPAF2fXxFGeQDWVjOwjLlWCeBdUfIwBzW1bzL3/jwZccqkHinHpuIPHWb+lrwHW9Z++oxHJVLQcom0kQQRnDhYaHlzrXFHkFM1uAS1euR8dxIsM+zq+NGTKjzcWAe2ExPbxyW7dWbBUsK8Ej2icpkCK5/Ut6ALxJ/H2Ak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udJqm+1OEVJpeeQd72sxfYdKiidTW7apTGKb89xMAD8+5kK+jhJf2bcGtNxrKps3eqZZtwnCIwp6PXLD2QpUn7O0zzeC7SyGtKMXa7ES9p63sK019q/qi001zmL4hCw3Bwn9aRF/vagh2hqoY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000059, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Avoid taking an extra trip down the mmap tree by checking the vmas directly. mprotect (per POSIX) tolerates partial failure. Signed-off-by: Pedro Falcato Reviewed-by: Liam R. Howlett Reviewed-by: Lorenzo Stoakes --- mm/mprotect.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index 446f8e5f10d9..0c5d6d06107d 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -611,6 +611,9 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb, unsigned long charged = 0; int error; + if (!can_modify_vma(vma)) + return -EPERM; + if (newflags == oldflags) { *pprev = vma; return 0; @@ -769,15 +772,6 @@ static int do_mprotect_pkey(unsigned long start, size_t len, } } - /* - * checking if memory is sealed. - * can_modify_mm assumes we have acquired the lock on MM. - */ - if (unlikely(!can_modify_mm(current->mm, start, end))) { - error = -EPERM; - goto out; - } - prev = vma_prev(&vmi); if (start > vma->vm_start) prev = vma;