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 X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28A7BC4BA21 for ; Wed, 26 Feb 2020 20:29:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1F482072D for ; Wed, 26 Feb 2020 20:29:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uVGxei6e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727457AbgBZU3p (ORCPT ); Wed, 26 Feb 2020 15:29:45 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:46919 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727350AbgBZU3p (ORCPT ); Wed, 26 Feb 2020 15:29:45 -0500 Received: by mail-ot1-f66.google.com with SMTP id g96so677427otb.13 for ; Wed, 26 Feb 2020 12:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=UBBYCrKEWuOTMe5EyAwkmAIoT9VVH7fpRYrxe98vHCY=; b=uVGxei6e9yF0ykQTCRbpF1Xcix7hidQzKjxKmA1TAaLMeWBjYprbRURWAhfm37DnMO ALgX0i/omp1eS4k0RzspH50ykrH6+tYuInb+/v3+dsQydB2Gf1JHLwkVAh7PVr7+/vRd FEXucDxG2gKpfW36N9FsDf3SO19ksbFgC8vKl0aQmSTLblf+uGgXkO2fWfA4XxFM+8Js jMnrrdCbNQqqzS+mSb6pWZJeJ7i2esnsfJ3vaxuZQhlQ6v6KWz6UIlXWOgBKqvTBvuUx ppCNzmE84DNL1pPvauf2ZbbPd7pYXUAe4jXhVazh2kQtXxxw/ibvY1NOsCYPKL926wLL APqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=UBBYCrKEWuOTMe5EyAwkmAIoT9VVH7fpRYrxe98vHCY=; b=TGyRAlZAuVvvJ0busbg8qEPuEI8Eo/ixshTJ9Tk+8zGkG4A4L/HLZ5o1kyzjRjmRbc ilQhEPWFqxig8Vb3AX5tPRgz+Rz2lgE0u8snvsOI+mmEh18J1cDbdgL4lAzj8hhOHOmr 2gfXlljg8oq3hMmFN+GH6xKz28yRVFqXjDURVuoaKcOjuphhQIvyTnlsvaWykpqoSNnS f4FeMIgwQPCU1hKAlMNCLAABMOUVVh6krHsZsFIo/CCZiaCQ7sq8ORATnD6SNJZTcsTc NEn9cLpmg3v2jtyM6eo8w6rfqFXjxJxe9JnLCrYbr7PH8wAaCtMtTsWRcEZvY5QD9ehL 9/Og== X-Gm-Message-State: APjAAAWvgDJLKFh3A8+WX17wCZadI/MQ7NKo4igDxZ4eR/ydezdgKx+x ihAuFPndSb/uRolZ37Qr64oh+tz0V0Sgu1hDT9/rPQ== X-Google-Smtp-Source: APXvYqy7E7A1017OqCy2OgReSsVvINF1u2X33Ne5TrenikJqc56r0qDxjZlM9E+pAKGCyqxj9LTAbiG86jPOqxjX13k= X-Received: by 2002:a05:6830:1219:: with SMTP id r25mr502917otp.180.1582748984487; Wed, 26 Feb 2020 12:29:44 -0800 (PST) MIME-Version: 1.0 References: <20200224160215.4136-1-mic@digikod.net> <20200224160215.4136-6-mic@digikod.net> In-Reply-To: <20200224160215.4136-6-mic@digikod.net> From: Jann Horn Date: Wed, 26 Feb 2020 21:29:18 +0100 Message-ID: Subject: Re: [RFC PATCH v14 05/10] fs,landlock: Support filesystem access-control To: =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Cc: kernel list , Al Viro , Andy Lutomirski , Arnd Bergmann , Casey Schaufler , Greg Kroah-Hartman , James Morris , Jann Horn , Jonathan Corbet , Kees Cook , Michael Kerrisk , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , "Serge E . Hallyn" , Shuah Khan , Vincent Dagonneau , Kernel Hardening , Linux API , linux-arch , linux-doc@vger.kernel.org, linux-fsdevel , "open list:KERNEL SELFTEST FRAMEWORK" , linux-security-module , "the arch/x86 maintainers" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Mon, Feb 24, 2020 at 5:03 PM Micka=C3=ABl Sala=C3=BCn = wrote: > +static inline u32 get_mem_access(unsigned long prot, bool private) > +{ > + u32 access =3D LANDLOCK_ACCESS_FS_MAP; > + > + /* Private mapping do not write to files. */ > + if (!private && (prot & PROT_WRITE)) > + access |=3D LANDLOCK_ACCESS_FS_WRITE; > + if (prot & PROT_READ) > + access |=3D LANDLOCK_ACCESS_FS_READ; > + if (prot & PROT_EXEC) > + access |=3D LANDLOCK_ACCESS_FS_EXECUTE; > + return access; > +} When I do the following, is landlock going to detect that the mmap() is a read access, or is it incorrectly going to think that it's neither read nor write? $ cat write-only.c #include #include #include int main(void) { int fd =3D open("/etc/passwd", O_RDONLY); char *ptr =3D mmap(NULL, 0x1000, PROT_WRITE, MAP_PRIVATE, fd, 0); printf("'%.*s'\n", 4, ptr); } $ gcc -o write-only write-only.c -Wall $ ./write-only 'root' $