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 40665C4BA24 for ; Wed, 26 Feb 2020 20:29:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 145C82072D for ; Wed, 26 Feb 2020 20:29:49 +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 S1727466AbgBZU3r (ORCPT ); Wed, 26 Feb 2020 15:29:47 -0500 Received: from mail-ot1-f67.google.com ([209.85.210.67]:34785 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727381AbgBZU3p (ORCPT ); Wed, 26 Feb 2020 15:29:45 -0500 Received: by mail-ot1-f67.google.com with SMTP id j16so756509otl.1 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=nuXeZQsG3xshMgOV3HPIxB0Zr+OgTJjlUhy/vyb1Sw7C4VLAAdWiLIkSuvH9PSAbJ5 qbXwvd69eMQqFHdHBqz9p4U4pOeDSmguqFCS90i8tYTJH95r4r+GJzXze86tnnOV/KAP ukrElNgRw0EKXfwsyjiY4Q5Q4UNcBbWTiJMRQeMGDH4Fig5gtVx7v8L3SD70hLX3H1np HUx33S8Hyw5NZgVvJ/s/k3iUj5MLrY+bu6xxNggCaRI6cZchueuriLqy8D3WnuaRi6ou 2oQSFUSnn/R3BmIrMeCBIWzqn2Xtd7J30RQwwCriHs4qEEYIfOOt5+9iCsydkb+avdZq 99vw== X-Gm-Message-State: APjAAAXzcNLLXBIiQN+wfVL0xnYI3v3GXEbu4oJA3/N/7dURwf1PDgSZ N5De9qSds2euCPmsi71DAo0yLBMwll1fEtFLx7vVVA== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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' $