Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1671404imm; Fri, 22 Jun 2018 23:47:41 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK5BIz4PBlEQcJ2jBNvPmK/jHKIxtzlixTF0rIr/wj8dNHW1T7zG5Ur7PB6fsdgLa5dFC3I X-Received: by 2002:a17:902:758e:: with SMTP id j14-v6mr4394651pll.160.1529736461809; Fri, 22 Jun 2018 23:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529736461; cv=none; d=google.com; s=arc-20160816; b=uJ7WOrMBOgKEgMFfJfU29s2tFrnXhpNYihyWQtjnqp14e4gRmDsxHGrn8hFuGTv4cs DjWDTK9UqHopaKsynQiEPGFeTFQqTjVFfkpRzABkDAEzPqWW2eUqAR7HsC/05C0ypjvM YB8i3LkevGelPpI/d9+a1DEcBnHSO4PMv2QMrWQ8CjKDAsVLh9ce6Vrosb3v+vy7Onaf cXJxP+Yn7NMfDgQKpFV4zK4sAv7ozjSPaXWgOftd87X0EMRfr9QS4gqvDahJWNodQ8pr IS4yj4Bi8TFCuCspGpClPeHpfYUqWlTCMT231apynmnXADVP9peT6iXdOuXda7WqFRmy QK3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=dDyeZ4LA7O7Wd1s6SPWPRsNYk5kQs50BWG+spo+LcmE=; b=FpPHUqwhwCWc7HAewaj7u1QbgY+4JZl0iD5TJWzm9+jW3P84UxeUKCkLEUfURlkK2A aRik1dbWC8b7WJRh6Uv7KHg4EN4HHNuZcIh+fTTaNG2qjuRiqIn3+xujc4tGKD9UwiLb gYOF+sNUX5AWxzUCCtMdwV6k4ELIx2qczmWbPHI4BOBqqFgiqoAUz8T98a2ekS4+Q8Hd 3zrQP4Dq33RaUJJujXaH9omOzY2yJtA/meWIRagzVqxkg5RqESA8SIuw21xaeBuUgctg emMrhFOQGUYsbTiCZgLignbnfZ/l2/qp1oJyLLoZTJF4vQLUBIUQo0pEpwXr7MtrQiIp LTuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gpCrMWX4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t87-v6si9180943pfk.228.2018.06.22.23.47.14; Fri, 22 Jun 2018 23:47:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gpCrMWX4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751478AbeFWGqL (ORCPT + 99 others); Sat, 23 Jun 2018 02:46:11 -0400 Received: from mail-yw0-f196.google.com ([209.85.161.196]:41108 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751300AbeFWGqJ (ORCPT ); Sat, 23 Jun 2018 02:46:09 -0400 Received: by mail-yw0-f196.google.com with SMTP id s201-v6so3146125ywg.8; Fri, 22 Jun 2018 23:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=dDyeZ4LA7O7Wd1s6SPWPRsNYk5kQs50BWG+spo+LcmE=; b=gpCrMWX4kgunXgJSNnWl+Ygo8a7EjDzJUcFDnvElrSVZS3a0unHVT+lhC8btbagaH/ M7d0aC/NGbvh9XxzzqrgF5UQcpu+Fv4YnimyT+Pc4JV7wWCQ63BvX/SDRU1GwE6dmIKh yFWe6kj6QkXdWYiJ+dCYz2WLp4ZsSxKnLAN47h87En2BfoctQeclxCFH9Gf9/F/MTn/5 EKSWRxrbkt03qdSI/WINy13I7yiZNRHyPdx+7+2R4ydRmweL+3C9K4YhkDoGTNjQ/VRu 3imdtJxNqtFDgbgVd31EyLBXG0t0OnHvcx2GTvP/rxetoAijHDUp3qbzoIg5+5u2//XS DOxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=dDyeZ4LA7O7Wd1s6SPWPRsNYk5kQs50BWG+spo+LcmE=; b=i+U3BNnOjqn/LIX3YdS609ncbGSjC64IO5tXDS7ZtIbavOc1lEHZYPyJnb10iT+ASm LJZGu0WVbao+Yl/8X+ObkAITaKygv18yKQbq6IjpOhop45FcAs4K6q8DGiyIHEIvgakO /bA/ttMnEKdVNbGa9hQBaghclZ+v5lbp3AouHyAATnp81hOLObdb7MVLIYFqySxw8OLq eLLE8KF8ea1HikVu4LlQUaaeK3curpW2W94hWFma1hCas0Qicg3sA47F9VJ1UgsNWGyX sP7hVQtZAvAk+goTWz/GwD2qwxfwH3i0X3gjhGNx3lDaIkgdgkL0JI4hhlmpXrfGaBXC BJXQ== X-Gm-Message-State: APt69E1epIf91jpzNlJTRlVdBgRACl1CPOTBO96nRrot8eot9l4TqDFn Ivs/GVm/TUxiLQFU4FpFDmszcNfDmmZLO6uwseA= X-Received: by 2002:a0d:d84c:: with SMTP id a73-v6mr2182759ywe.379.1529736368422; Fri, 22 Jun 2018 23:46:08 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a81:1b04:0:0:0:0:0 with HTTP; Fri, 22 Jun 2018 23:46:07 -0700 (PDT) In-Reply-To: <20180622171605.52989-1-salyzyn@android.com> References: <20180622171605.52989-1-salyzyn@android.com> From: Amir Goldstein Date: Sat, 23 Jun 2018 09:46:07 +0300 Message-ID: Subject: Re: [PATCH v4] overlayfs: override_creds=off option bypass creator_cred To: Mark Salyzyn Cc: linux-kernel , Miklos Szeredi , Jonathan Corbet , Vivek Goyal , "Eric W . Biederman" , Randy Dunlap , overlayfs , linux-doc@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 22, 2018 at 8:16 PM, Mark Salyzyn wrote: > By default, all access to the upper, lower and work directories is the > recorded mounter's MAC and DAC credentials. The incoming accesses are > checked against the caller's credentials. > > If the principles of least privilege are applied, the mounter's > credentials might not overlap the credentials of the caller's when > accessing the overlayfs filesystem. For example, a file that a lower > DAC privileged caller can execute, is MAC denied to the generally > higher DAC privileged mounter, to prevent an attack vector. > > We add the option to turn off override_creds in the mount options; all > subsequent operations after mount on the filesystem will be only the > caller's credentials. This option default is set in the CONFIG > OVERLAY_FS_OVERRIDE_CREDS or in the module option override_creds. > > The module boolean parameter and mount option override_creds is also > added as a presence check for this "feature" by checking existence of > /sys/module/overlay/parameters/overlay_creds. This will allow user > space to determine if the option can be supplied successfully to the > mount(2) operation. > > Signed-off-by: Mark Salyzyn > Cc: Miklos Szeredi > Cc: Jonathan Corbet > Cc: Vivek Goyal > Cc: Eric W. Biederman > Cc: Amir Goldstein > Cc: Randy Dunlap > Cc: linux-unionfs@vger.kernel.org > Cc: linux-doc@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > > --- > v2: > - Forward port changed attr to stat, resulting in a build error. > - altered commit message. > > v3: > - Change name from caller_credentials / creator_credentials to the > boolean override_creds. > - Changed from creator to mounter credentials. > - Updated and fortified the documentation. > - Added CONFIG_OVERLAY_FS_OVERRIDE_CREDS > > v4: > - spelling and grammar errors in text > > Documentation/filesystems/overlayfs.txt | 17 +++++++++++++++++ > fs/overlayfs/Kconfig | 20 ++++++++++++++++++++ > fs/overlayfs/copy_up.c | 2 +- > fs/overlayfs/dir.c | 9 +++++---- > fs/overlayfs/inode.c | 16 ++++++++-------- > fs/overlayfs/namei.c | 6 +++--- > fs/overlayfs/overlayfs.h | 1 + > fs/overlayfs/ovl_entry.h | 1 + > fs/overlayfs/readdir.c | 4 ++-- > fs/overlayfs/super.c | 21 +++++++++++++++++++++ > fs/overlayfs/util.c | 12 ++++++++++-- > 11 files changed, 89 insertions(+), 20 deletions(-) > > diff --git a/Documentation/filesystems/overlayfs.txt b/Documentation/filesystems/overlayfs.txt > index 72615a2c0752..18e6d70ea4c9 100644 > --- a/Documentation/filesystems/overlayfs.txt > +++ b/Documentation/filesystems/overlayfs.txt > @@ -106,6 +106,23 @@ Only the lists of names from directories are merged. Other content > such as metadata and extended attributes are reported for the upper > directory only. These attributes of the lower directory are hidden. > > +credentials > +----------- > + > +By default, all access to the upper, lower and work directories is the > +recorded mounter's MAC and DAC credentials. The incoming accesses are > +checked against the caller's credentials. > + > +If the principles of least privilege are applied, the mounter's > +credentials might not overlap the credentials of the caller's when > +accessing the overlayfs filesystem. For example, a file that a lower > +DAC privileged caller can execute, is MAC denied to the generally > +higher DAC privileged mounter, to prevent an attack vector. One > +option is to turn off override_creds in the mount options; all > +subsequent operations after mount on the filesystem will be only the > +caller's credentials. This option default is set in the CONFIG > +OVERLAY_FS_OVERRIDE_CREDS or in the module option override_creds. > + Mark, Thanks for the properly documented patch, but this documentation it missing the caveats of this config option and there are severe caveats as was discussed on earlier version of the patch. You should mention the not so minor detail that this option can result in inability to delete files/directories from overlay and there me be other side effects. This is one of those features that should be warning unconditionally that user should really know what user is doing. You did not address my concern that the test for setting trusted xattr on mount (ovl_make_workdir) should emit a different kind of warning when override_creds=off. In fact, I think it should emit a warning when override_creds=off unconditionally to indicate that weird things can be expected and we "really hope you know what you are doing". A new security concern I just noticed - overlayfs calls some vfs functions directly to perform operations that are typically not allowed to unprivileged users without checking credentials. In those cases your patch introduces a security vulnerability. Examples: - overlayfs calls exportfs_decode_fh() on underlying fs without checking CAP_DAC_READ_SEARCH - overlayfs calls vfs_whiteout() which calls underlying fs mknod without checking CAP_MKNOD Those examples could be easily fixed and you may righfully claim that they are bugs, but the fact is that those "bugs" are harmless until someone creates an irregular security model without capabilities to mount, without capability to mknod. What's worse is that you have to audit the overlayfs code and find all these potential bugs and fix them before changing the assumptions that were made over the years about mounter credentials. Thanks, Amir.