From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27EF3C4332F for ; Tue, 15 Nov 2022 19:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zXHAx9oO0WA1mjZZc/bT3R6oa8QcLmVfb6AYeOLEg84=; b=wWTU9z1Il0NwnO SvEaweTk6byndkl1akQA4CbO3Jnod+mkIwWkam7gsF5vnsCV1YOHvZXQviV1eBH6b/O+HznC88hcz 3Dg7opz4PCn1Std8Vmds1Iw7rWi76q5s+7leu02BDnGuMIUXfZ5toG/9P534FAJjodl41S657cyF/ leWRs8yZCxzC0Byk57i7S4DTjf5HyonX2jOW0yg68U7O9lq1Ysa5VXuXVMos1ho46Cbbl73Uaw7Fb FFZ74xmKJA4FcZpDlZipIy9l3ffkktYOTV6V8QtaUIK5ZB1iMxNp+bG5eCEOnTWpynVt/jeZpm0eF xJLRQLQ4iz/o7J/Trp5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ov1eK-00EIBh-Bh; Tue, 15 Nov 2022 19:31:12 +0000 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ov1eH-00EIAP-GW for linux-arm-kernel@lists.infradead.org; Tue, 15 Nov 2022 19:31:10 +0000 Received: by mail-lj1-x233.google.com with SMTP id d3so18942726ljl.1 for ; Tue, 15 Nov 2022 11:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=GyIes3iMStNxnqC1zOqI35/7e76O5dm/XUcc8xXZAU0=; b=BwbnG2RfwynQyF60LQWulCgZz/hWVDpZdDS/W4Afc0GwH9VaX/6v6MpM6FEicoD3qh kBXdUWCdP5DC6h8mf/mrnzxSXR4bYpUaF5FDGkrw4k+jZpzvIlkdVAYAv1nLUyuYgfAa nEvcfHM60NM+upX/oP3JL3COzv02zmik+Pjw0Z14qW+f0Lheo2gLM/N6Pi02pMo9NDzy 0QGl5Wq9Kh0BxozfGXGpDQFXzOb7LZVCPt0TCIbTR3OFcM2+VLvFGmB5tryDDYgYbyj3 mYi1eHd+nMCdFvqLKrmEhIi/rAvyUgVf2Mo6BvxaGGwhBLq+b+71j38DXgdOyLej9R2A 4vtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GyIes3iMStNxnqC1zOqI35/7e76O5dm/XUcc8xXZAU0=; b=rh5pyN/JQ7J9w8OF42bFzID2aPYZ40p3MrhnmqduYN3kcI5eSofJ2ZEwzqfZsgfKjJ hUHjG1hFKL9wL5cQ9U7GIclpmprjS15WwYNfs9kNh4DigXMoxSUZ1uOnIDbth1ZgzT4f CWJ41lslmSr96l1dEpo0eB9KjO14Snp5L1ZWz7OcbJytNEwVuV6Ceo9HS06G0Qh+68RF TfnWlU2TBZF8YOaZbCeI49sRuElldW7fnwqRBqps9ke/pdNRw2Prc50MCneV74DL4bn/ FVa6w98m54OZpkwGK6wMLIXt3pMQ9NkwuUOoTwJOgPsrAx7CVB+Omwz/mSU+v3qeh1/8 r6hQ== X-Gm-Message-State: ANoB5pnnloUeSy2kkywZF0k9Vl1sUFWUbIZ5V51V4Bul3gzyljN0IUQu NeEDDTW/AJjC1eqwADbH2d2K4SEDljc= X-Google-Smtp-Source: AA0mqf5E7tedpNnEAREDyyxzme4BhAXLv4FsoAZtAChSVnsk1YdNBoZXKk4qdoZLXnO/ckEuuwCskQ== X-Received: by 2002:a05:651c:220f:b0:277:1d5b:74b with SMTP id y15-20020a05651c220f00b002771d5b074bmr6339410ljq.522.1668540664883; Tue, 15 Nov 2022 11:31:04 -0800 (PST) Received: from [192.168.1.12] (91-159-148-109.elisa-laajakaista.fi. [91.159.148.109]) by smtp.gmail.com with ESMTPSA id g25-20020a19ee19000000b004ac393ecc32sm2304658lfb.304.2022.11.15.11.31.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 11:31:04 -0800 (PST) Message-ID: <3238cc28-218e-ae73-2e12-a7c1a08bc353@gmail.com> Date: Tue, 15 Nov 2022 21:31:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH v1 1/2] mm: Implement memory-deny-write-execute as a prctl To: Catalin Marinas Cc: Joey Gouly , Kees Cook , Andrew Morton , Lennart Poettering , =?UTF-8?Q?Zbigniew_J=c4=99drzejewski-Szmek?= , Alexander Viro , Szabolcs Nagy , Mark Brown , Jeremy Linton , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-abi-devel@lists.sourceforge.net, nd@arm.com, shuah@kernel.org References: <20221026150457.36957-1-joey.gouly@arm.com> <20221026150457.36957-2-joey.gouly@arm.com> <202210281053.904BE2F@keescook> <20221110112714.GA1201@e124191.cambridge.arm.com> <45419a7d-04dd-2749-2534-6ba3bbd5d060@gmail.com> Content-Language: en-US From: Topi Miettinen In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221115_113109_584486_65138D5C X-CRM114-Status: GOOD ( 25.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 15.11.2022 17.35, Catalin Marinas wrote: > On Sat, Nov 12, 2022 at 08:11:24AM +0200, Topi Miettinen wrote: >> On 10.11.2022 14.03, Catalin Marinas wrote: >>> On Thu, Nov 10, 2022 at 11:27:14AM +0000, Joey Gouly wrote: >>>> On Fri, Oct 28, 2022 at 11:51:00AM -0700, Kees Cook wrote: >>>>> On Wed, Oct 26, 2022 at 04:04:56PM +0100, Joey Gouly wrote: >>>>>> diff --git a/mm/mmap.c b/mm/mmap.c >>>>>> index 099468aee4d8..42eaf6683216 100644 >>>>>> --- a/mm/mmap.c >>>>>> +++ b/mm/mmap.c >>>>>> @@ -1409,6 +1409,9 @@ unsigned long do_mmap(struct file *file, unsigned long addr, >>>>>> vm_flags |= VM_NORESERVE; >>>>>> } >>>>>> + if (map_deny_write_exec(NULL, vm_flags)) >>>>>> + return -EACCES; >>>>>> + >>>>> >>>>> This seems like the wrong place to do the check -- that the vma argument >>>>> is a hard-coded "NULL" is evidence that something is wrong. Shouldn't >>>>> it live in mmap_region()? What happens with MAP_FIXED, when there is >>>>> an underlying vma? i.e. an MAP_FIXED will, I think, bypass the intended >>>>> check. For example, we had "c" above: >>>>> >>>>> c) mmap(PROT_READ); >>>>> mprotect(PROT_READ|PROT_EXEC); // fails >>>>> >>>>> But this would allow another case: >>>>> >>>>> e) addr = mmap(..., PROT_READ, ...); >>>>> mmap(addr, ..., PROT_READ | PROT_EXEC, MAP_FIXED, ...); // passes >>>> >>>> I can move the check into mmap_region() but it won't fix the MAP_FIXED >>>> example that you showed here. >>>> >>>> mmap_region() calls do_mas_munmap(..) which will unmap overlapping regions. >>>> However the `vma` for the 'old' region is not kept around, and a new vma will >>>> be allocated later on "vma = vm_area_alloc(mm);", and the vm_flags are just set >>>> to what is passed into mmap_region(), so map_deny_write_exec(vma, vm_flags) >>>> will just be as good as passing NULL. >>>> >>>> It's possible to save the vm_flags from the region that is unmapped, but Catalin >>>> suggested it might be better if that is part of a later extension, what do you >>>> think? >>> >>> I thought initially we should keep the behaviour close to what systemd >>> achieves via SECCOMP while only relaxing an mprotect(PROT_EXEC) if the >>> vma is already executable (i.e. check actual permission change not just >>> the PROT_* flags). >>> >>> We could pass the old vm_flags for that region (and maybe drop the vma >>> pointer entirely, just check old and new vm_flags). But this feels like >>> tightening slightly systemd's MDWE approach. If user-space doesn't get >>> confused by this, I'm fine to go with it. Otherwise we can add a new >>> flag later for this behaviour >>> >>> I guess that's more of a question for Topi on whether point tightening >>> point (e) is feasible/desirable. >> >> I think we want 1:1 compatibility with seccomp() for the basic version, so >> MAP_FIXED shouldn't change the verdict. Later we can introduce more versions >> (perhaps even less strict, too) when it's requested by configuration, like >> MemoryDenyWriteExecute=[relaxed | strict]. > > Are you ok with allowing mprotect(PROT_EXEC|PROT_BTI) if the mapping is > already PROT_EXEC? Or you'd rather reject that as well? > I think that it's OK to allow that. It's an incompatible change, but it shouldn't break anything. -Topi _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel