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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B82F1EB64D9 for ; Thu, 29 Jun 2023 21:05:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A2BD8D0005; Thu, 29 Jun 2023 17:05:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 553298D0001; Thu, 29 Jun 2023 17:05:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4429A8D0005; Thu, 29 Jun 2023 17:05:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 328DE8D0001 for ; Thu, 29 Jun 2023 17:05:31 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D7474160CF9 for ; Thu, 29 Jun 2023 21:05:30 +0000 (UTC) X-FDA: 80957016420.04.AF951C9 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by imf25.hostedemail.com (Postfix) with ESMTP id 092DCA0018 for ; Thu, 29 Jun 2023 21:05:28 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=rOm8Rha2; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of jeffxu@google.com designates 209.85.208.42 as permitted sender) smtp.mailfrom=jeffxu@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688072729; 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=OtqC5U06rpgElL+2bahbcyOiaEJkZ6SnNFt7jo/MOuI=; b=QhDsxsJtcVB3LhvOX0dpsFqf03T29fkdbmca/bwdhGispL+sgkAeu14Eu4YfuT6RCMvZlV PwN4Qew/i7XlW38ozNFc1pbHFd0GIkUKYxgTr7oaMdFRDZa+F9Yp2EdBAypNzjMYCGIX0r 50zNJmu9Ivp7CKSgokRqy27LjfbVsUE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=rOm8Rha2; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of jeffxu@google.com designates 209.85.208.42 as permitted sender) smtp.mailfrom=jeffxu@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688072729; a=rsa-sha256; cv=none; b=pXdCpGScF+HqCG/V3qsff2AK+hk6Xj3F2awkj0KAg5DXOCfbPh5E+x4lJYaZZVkJXcTqwQ BpgdCwsuIs0Vvc252dxvqCM1RDfM952JtBKt0aklRf8q+FvCyc7eeQGpWFnc0AzT53dpVQ 0gUaVJY1sKf0HizM1V5jJMOSQJGVY7o= Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-516500163b2so774a12.1 for ; Thu, 29 Jun 2023 14:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688072727; x=1690664727; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OtqC5U06rpgElL+2bahbcyOiaEJkZ6SnNFt7jo/MOuI=; b=rOm8Rha28FTOFOHSJ4pnBUfd88CBGxDDkHvCX9orLeRV9Nhd/sglXEJd9xFznwQwHd 5VlVBjdmO2LahD1b6cH3urkETtnXQfY/PbKiucJ5ryGf2a6JyzHzZEvRRXX4lmUUj7Yt 3Ua2g9qSC0sJjbtn1YD0JRohiBcpvGdV38pmMwau+r/H8ubR7PjdpvEeCKtsU6Yjwqck XqKuFnhUZod82aios1qhFvFAHUziSU8mO29aziPIaf34KZcJJwoSdwZr/EOzJ6YOYyI7 j1sqKAOtQND52d+TYHNgKyFWag50AjMTuFYSYOL3uOXYYoV7VSCOU/H2qn6tiR53l3n6 9tcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688072727; x=1690664727; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OtqC5U06rpgElL+2bahbcyOiaEJkZ6SnNFt7jo/MOuI=; b=Kw/fcH68iDgChVl5QkHAspoL3GSJFBVRC7AYt4cPWUsNRy57zh6mOxjUTpC+MP8CPF 4LjBSqTkNPqLDvVzIiVHgsiD1ejCaM2M+t/RisQg32vimEzWaXRb7ViwK8OITcCDQPqM uU0+rrL977/JxQ+B0JgtYa44xkLIzO68bhijM8aYC6Mhott1IIbQiz1THruWH5dj4RXk FC2zJVrJdpMVtFD5Ut1wDzgAuA8NHgZ0DoXQCUqJdC1hRyPd8/iiTGd48ZUE54bkAPaA GS+7rgs1heSNmSMA/Vs/jM6FDjSjfCHbDzP6kUZYBcCkIjRvilQIf2H0Zcx7WWfpoamY qQYg== X-Gm-Message-State: AC+VfDyWUmlgSbxZdDJ858e6c/ihqMFtUYnZMov6dV3FgbMBC8K6iUbj NPaeW8HJd/x/xOqXDkgGJu8o2vGNcID/8SAE8hSsKw== X-Google-Smtp-Source: ACHHUZ7GbEWD4nWGsAzJazQOkKf5PEoLuhvKRiEGkpHOQkEqtf1+QVWBi7bo8ZkwYTh5iQe+Oky1ZmARdNPs7TuWi+w= X-Received: by 2002:a50:9f85:0:b0:51a:1d77:e69d with SMTP id c5-20020a509f85000000b0051a1d77e69dmr166118edf.3.1688072727376; Thu, 29 Jun 2023 14:05:27 -0700 (PDT) MIME-Version: 1.0 References: <20221215001205.51969-1-jeffxu@google.com> <20221215001205.51969-4-jeffxu@google.com> In-Reply-To: From: Jeff Xu Date: Thu, 29 Jun 2023 14:04:50 -0700 Message-ID: Subject: Re: [PATCH v8 3/5] mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC To: Dominique Martinet Cc: Jeff Xu , skhan@linuxfoundation.org, keescook@chromium.org, akpm@linux-foundation.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@google.com, jorgelo@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jannh@google.com, linux-hardening@vger.kernel.org, linux-security-module@vger.kernel.org, kernel test robot Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 092DCA0018 X-Stat-Signature: n6145n413sf3u54noa5oz8ua8z4ytb5q X-HE-Tag: 1688072728-953895 X-HE-Meta: U2FsdGVkX191YGBU5oR9qeGtWggve5NnUTqjVXwtd+K8LS0X4E2zZyer+nNGI0E3DcwvDAJQ6/QATZH/tt8K44URXQkhMroHRlw6e+4kIEiN4rkaNMZPekSBS+q5ZmJL5FjabiVrdVIlghmuyL1eE88xBr43tImoJIcXtklTdT6a2rDb7xFFO45+HDN7wnTtXAtzRdemF9+OFTOWFRZmT2GdyHJYfglAQp9k4O91kdrofxd+uWVa/Sf/AKkd9ncpmUR3LiEjlKOgZ4/AA1xtzxXfCPRQ3IFV4sZaBS4iIpPsU5kJQ2yQ/ycCGb3NiVjwry1tD10zZT0ldY/bMPpHMcuW+nmczMoXwnZrhx9ugOlvwRsnJLjgeVEKTYIJ3i/G9Sw/QLD8mfg6YW+vP/eGQM1QhGdxz3Wlo/9KiMn/aGvMT5Wv/JQc47ESo3WVm1oTC8G332NiX9kRTdUW5j1H6nJ+rZprblyMpTp2HUH47yd5L9s2N3EDX7x4gIiU7+nTnZ1lVNAxsGoei+gQR+ZQmKM0/6WFhaTAER/fUrJmCusY95V/4oW2gwCTk+FuO9Gk1bWSNLTcGwniV6PwaJ/tPilPSsWNSgFFlcxuGhvBh493tGIecOa5Y54lblypl/IaEqTRC4bb/6g1PMPPayjmDzskHMwpb59yRcAp/xthkP+qZK49x/tcjUgz4NF6CiJEJGQsGZtVOIWj/2bUIimSkG9Q3DiyC1ftEF/bmkK0F0eu237PcrquPoLVhfco84jE6VzyHNtrs9tTuVdbwNpyCoxzpVzb+jdEryleOAjziuy2wRrDQmfkZeRxpe7GTb3aoybC+iEZ4XvBL/Z4udYh6ZbC3rn0RMymkFGHC8rqmKZRGQ3ajnN/ETr7IaMxCRvz9zmW1uZs/NoOUGc+lv4pcvA5c6vsZpzLLVpG7Vsw4EgeoWksfFBYiRSZ4TFLUfGtCUojrzWaGKNPuCrEvrc WFz+tlf7 UtRtEQzzec7wvoLp1MGLMWQ2HWNW/gx9HsnsYg0L8E6FftJ4xQCnid8Ncs7/7k0MPiCrLxClaVMrVaDyXiyL3JfVP7h8GrBvEVgvzb3eLOBVg2gQF2may5rXCQnJfBanUyddrIVaHoNOqPQ/SXdKsJbkgOnL+/xDrBT5v4AfnuCI2E/0mtXz/ANpfm5eWAO6oybkC6lUGNI8AoRBjb4JhVabP7Ubadch+sK8f7iFle9WqNqdNC5Ex6BTswTCoLED8f7x09zuH/nxQaf7PL0NZ0F6I6X3gJ6o+Xwj7O3GP80rIDsl0AZYDnveEVtnQ1V7GrTjxl1xPjkJX94TQhvkOq0YaE9RtcQDQHtY1BONe/GJUWdOByLEP0/bCeiHEgINVMUgthL/cd7NIkXvU1UjCUkb3aQ== 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: Hello On Thu, Jun 29, 2023 at 3:30=E2=80=AFAM Dominique Martinet wrote: > > Jeff Xu wrote on Wed, Jun 28, 2023 at 09:33:27PM -0700: > > > > BTW I find the current behaviour rather hard to use: setting this t= o 2 > > > > should still set NOEXEC by default in my opinion, just refuse anyth= ing > > > > that explicitly requested EXEC. > > > > > > And I just noticed it's not possible to lower the value despite havin= g > > > CAP_SYS_ADMIN: what the heck?! I have never seen such a sysctl and it > > > just forced me to reboot because I willy-nilly tested in the init pid > > > namespace, and quite a few applications that don't require exec broke > > > exactly as I described below. > > > > > > If the user has CAP_SYS_ADMIN there are more container escape methods > > > than I can count, this is basically free pass to root on main namespa= ce > > > anyway, you're not protecting anything. Please let people set the sys= ctl > > > to what they want. > > > > Yama has a similar setting, for example, 3 (YAMA_SCOPE_NO_ATTACH) > > will not allow downgrading at runtime. > > > > Since this is a security feature, not allowing downgrading at run time > > is part of the security consideration. I hope you understand. > > I didn't remember yama had this stuck bit; that still strikes me as > unusual, and if you require a custom LSM rule for memfd anyway I don't > see why it couldn't enforce that the sysctl is unchanged, but sure. > > Please, though: > - I have a hard time thinking of 1 as a security flag in general (even > if I do agree a sloppy LSM rule could require it); I would only lock 2 > - please make it clear, I don't see any entry in the sysctl > documentation[1] about memfd_noexec, there should be one and you can > copy the wording from yama's doc[2]: "Once set, this sysctl value cannot > be changed" > [1] Documentation/admin-guide/sysctl/vm.rst > [2] Documentation/admin-guide/LSM/Yama.rst > Thanks for the suggestion. Yes, it would be good to have some documentation. I will send patch to update Documentation/admin-guide/sysctl/vm.rst > > Either way as it stands I still don't think one can expect most > userspace applications to be converted until some libc wrapper takes > care of the retry logic and a couple of years, so I'll go look for > another way of filtering this (and eventually setting this to 1) as you > suggested. > I'll leave the follow-up up to you and won't bother you more. > Not bothered at all! and thanks for reporting the bug to improve the quality of memfd_noexec ! Much appreciated. -Jeff > Thanks, > -- > Dominique Martinet | Asmadeus