From patchwork Wed Aug 28 22:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13782072 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 E9062C71150 for ; Wed, 28 Aug 2024 22:55:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4100F6B007B; Wed, 28 Aug 2024 18:55:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 398C86B0083; Wed, 28 Aug 2024 18:55:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 213866B0085; Wed, 28 Aug 2024 18:55:50 -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 01A8C6B007B for ; Wed, 28 Aug 2024 18:55:49 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8C4861208BF for ; Wed, 28 Aug 2024 22:55:49 +0000 (UTC) X-FDA: 82503163218.05.EAC139A Received: from mail-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176]) by imf16.hostedemail.com (Postfix) with ESMTP id C693B180018 for ; Wed, 28 Aug 2024 22:55:47 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=DcSjJ5UK; spf=pass (imf16.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.166.176 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724885703; a=rsa-sha256; cv=none; b=dN5V2wS4yQJt4CVzXEOunfHgBTbczXBz610Z1bKiOMy++pTs4e+wEJMQyFN7GJdUfArhm/ GWwafaQdJlqzZn/d0DzZtaGX8cV0qkqaccnfx62AiKcrkvmK9f/JX5tZFvSjFGYw92hDlT F1IS7XbyVYVJsYbRbXnSJ0kHLaa9MA8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=DcSjJ5UK; spf=pass (imf16.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.166.176 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724885703; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=J8Z5eLbpis7e7vvah9IbIM7PmbksM6DKcbwvEGDpiWE=; b=hMIkLlQD4RA0oKqBT/4wlGpd8jCjFBmb8Ubm6lSx+v+qRvFKdKEEcWvlKAOw37afwSSWgi ISRhIIu/LoYxTHQTRRQIgT0LhqwjxO/muhnnHE2yKI3kAooHXLLbXqvR7KfcNX34AgVzsd KBib+1nPpb48B9uSwocSqh/Bb2QDR+s= Received: by mail-il1-f176.google.com with SMTP id e9e14a558f8ab-39d41836c23so3904995ab.1 for ; Wed, 28 Aug 2024 15:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724885747; x=1725490547; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=J8Z5eLbpis7e7vvah9IbIM7PmbksM6DKcbwvEGDpiWE=; b=DcSjJ5UKhAHuufWE5e13UgySoN9KljUGHJAS7+xN3MfbXe67VEtrPGnDjn28qpgzRg iMrO6l7w/0KxhB+40OY9knPcR/UqoNzdxreh+3MumW9rJ+Ubjd59+0K8DHDCv5n0JSJD n2dByHodKq+b+jEpH7Zm9K4p0yCYK0eHj3qrM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724885747; x=1725490547; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=J8Z5eLbpis7e7vvah9IbIM7PmbksM6DKcbwvEGDpiWE=; b=XsssRU93//pTcrgB04aqyBcv/Ng+HI4GqXdYoAyj2vzGSNUWkhvFbncrhE6TdiTYZP 5IKS/FSLDROeZ3v8oYn2FWVAS/CsYaB2dGJub9/xsz+CW1i9TiCNX/oEM54ws9M74EwT j8ZDqAWb3rVLcR2ZkKZpQrBsUB1gOyDFoCxFVQDImS1vXJKWFokzU2Co0yrpw5AJFXBp gaBJVjOscujp/njc0ivlWA43CeMRRaaGU2Hhwv0RkwQ8EEcjfvviTRzJJFollNb0MVkD xAFbgvfm9Km1ivXF+Zgpxhn4TtCaH1QTQyp84oXYkPyCPx/8OWRN2G9HNK3yM9SKlkcG 4Pog== X-Forwarded-Encrypted: i=1; AJvYcCXGDu7k8aEdBJdF9NXmL9TMuJxIXyl8IxDLA7Ls9dCiNk8F37NovVMvnmj8E2n4SlZDJ+qWZOVOGQ==@kvack.org X-Gm-Message-State: AOJu0YwNxGdVMZ/S9qx1ax8MonlpYX+XtVZycQEiljFS0IMZaODxE+1i 2aT4FNLSyeS4RJFAodGzQaYIYR8KXdmT3QQRhxLoApNlL+p5YMcJsYxtbfKiHg== X-Google-Smtp-Source: AGHT+IHyK6DcyWgUYRaw70EC9IGthnky5HvMQ2dXz+d303B4Lbji+yOFjXtPk96YXoJ4u+Ta5Vb8YQ== X-Received: by 2002:a05:6e02:1524:b0:39d:1234:9433 with SMTP id e9e14a558f8ab-39f37710be2mr9394955ab.0.1724885746519; Wed, 28 Aug 2024 15:55:46 -0700 (PDT) Received: from localhost (150.12.83.34.bc.googleusercontent.com. [34.83.12.150]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7d22e77438dsm20314a12.27.2024.08.28.15.55.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Aug 2024 15:55:46 -0700 (PDT) From: jeffxu@chromium.org To: akpm@linux-foundation.org Cc: linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, pedro.falcato@gmail.com, rientjes@google.com, keescook@chromium.org, Jeff Xu Subject: [PATCH v1 1/2] mseal: fix mmap(FIXED) error code. Date: Wed, 28 Aug 2024 22:55:21 +0000 Message-ID: <20240828225522.684774-1-jeffxu@chromium.org> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog MIME-Version: 1.0 X-Stat-Signature: szozgpud4nqb58uhspa1gqr1eq6f4a3x X-Rspamd-Queue-Id: C693B180018 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724885747-999741 X-HE-Meta: U2FsdGVkX19IAH3BWJX7PUlgwM+PRAcHg+UlhqGTP73OeXSVEJDwUQiY2gRwkBp5DCSgebWBIU+S376NToR881fxP2wGAdIwdQd6zI9Rxh8xM3XSTAt4APFkNwruW6gpVgtZg8nwH+eyrMB36CxKUtUS1ywe8mgR5H20cFpNIGz1FZ4BvlW8T6SARjTanksKdEMMmhRqFfOJHkYuMyG5zlVlkKiy3tdXdHQFLj4fbwUvEmhfabMBMbYBNbj+H5orLkuchV29gTYVi9NF+juIO55BmOrnlGntcpZ3VlFhSxJO1TWipCZqvqDOGVXbprbhk3JI/Wp4FwaGMcmYgo4Vn17F64EGcfYlOpL6i7QotgpdBdxn4LI0fP2hY1r4aI/DPwkwxTOxdtbMOHHz29Tvr5SijBVqtPGpdspdUPYDEOAngGBLGI/2T63gLt4UeeKTmvpTBim7UrkmpVHYAi43SVT14RVD+S5pgJjC3igzgBfCFhuHg1SGALpXfUcjyE1vxUxq/LjELfDZL6ZwJKDdVFc4hn7u7WdMPKpSCqiHnPOfvI+RkGwqcXeZeUNfSnV+d/5+bdQEOCZJrUJoOJaUjiwH3fbjaM33oGZL9h8PxFDSmxdU+edGxwjXXqdONXycYthPqmpIsoSfTPgCV0xBE5rxYgcw0bUaKzflDIQbziu8MaZBjyTRbmwo5INZ04fIOpNJln+FdOKdyN84m4GXD/Bsaubx281eF2DcpvQO7Tj1BSVUjTwXTtlBMoGC3jm4JeQIBzO+NISeTp1NV0hXFN6WRXAnZHBTR36f2vaVPd4WclIRe4lJkYo7B+cU160QfUDIDQSjW/o/ZoiYndszAdGH/eoyw+Y/ZPYFmAPIRKzSPC4N4Xa2fdnxHIpVSkcgLAyIGBYhumSEMnQYE4mWX5IzmD0dH0TwuU7yjunoIpAxi86mWQejrS10RqNLJMfXCWRC3ZDfzD851hmty6U Y63b8XxH 1wCru8kLv9PA5bco3Oc77uZxqoQLWpfJa7FYWNLpbhlfGIFpbVZELnLnezJ0l0rdUhM9QIHvroov1ORC0pqR/FwndDs07ePhphC9+CNEhRJKTz8X5mufBS7F04nuBNLjHUR0gIeEPmpbJ653XjaJb/wuZnJtgoULXSpwo9dlH1r00QPyZpGnHjvs75TFextVcbEY2U6RN8NbMlwxAVQgho/xuRlkOEiTLR291OvqwdWR2qmonYgiTU+05odNODYptUgFdXrBbFOXadtSrh8yPsySE7HGJ5rqJZJbNAKorVeTvp3KbEXBwPV0JyreGLkyZbqhK61ioTB/HKLl9schsLXZ7kJol15y41zPgDlM+R03q6Ao= 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: List-Subscribe: List-Unsubscribe: From: Jeff Xu mmap(MAP_FIXED) should return EPERM when memory is sealed. Fixes: 4205a39e06da ("mm/munmap: replace can_modify_mm with can_modify_vma") Signed-off-by: Jeff Xu --- mm/mmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/mmap.c b/mm/mmap.c index 80d70ed099cf..0cd0c0ef03c7 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1386,7 +1386,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, mt_on_stack(mt_detach); mas_init(&mas_detach, &mt_detach, /* addr = */ 0); /* Prepare to unmap any existing mapping in the area */ - if (vms_gather_munmap_vmas(&vms, &mas_detach)) + error = vms_gather_munmap_vmas(&vms, &mas_detach); + if (error == -EPERM) + return -EPERM; + if (error) return -ENOMEM; vmg.next = vms.next;