Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5329080pxu; Wed, 21 Oct 2020 22:05:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqzJhUMc9PHE1hBboofrmTn74kouytsDj1nuLdPCB29RNgMlMMeMf4wz27OfJUuUS6jhT/ X-Received: by 2002:a17:906:1e45:: with SMTP id i5mr620769ejj.203.1603343106229; Wed, 21 Oct 2020 22:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603343106; cv=none; d=google.com; s=arc-20160816; b=mPBZ5B0ns4NXmMWIAnMv6pHCgWTwDTe69KOfqA0g4UeWiZNW6adb/XGPpIKaPC7Xgc 9WISkldQyuEoN56xpoha2Yvt5FIKZjf64Tj3ZAv7RZ2EhqSGHV49V/MtA1/iqwolNlQU MFHUk0ayNdzlWn737TdZlUBMsbAZyAINZDZA2afRgYojSbeWXoyk1Bb7Ko7mMYeMYRs5 o2DlwRnr3Lfty+vt9UbBRbnRg/Zn/Ao4+yHvmVwWCNFX55Q4wxcqu2jxApzS02zbkLyi 7RhCblafeTiP3gdjog4+3/4zj2tZrPH8o3odJNJCJY2XMu4ZJRe5EK+gUJzmSyEazQA4 QnpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AaLxoMYWxby/CcFJviQRdg6riGgNtKHzl1ULFWsI1LU=; b=JsjOcoJGLad/5m79goimlATz8+DTI8ffIJzGRAGf5mWsxhxFvK45ALTdm/GMPVZElV tMlCo5lST5DD21o9UzghQ/x88YunROcZwpiwtk24PyxaFtYiVIbBqPIZGSfh3XNQRHSN WsM0iVWAZBSO/pQHF3JDOyNKu1G6V+LJHcVcn9oYu/UpBrlvxxgVomhODLsFJLHdd8k1 IJzZs1pDbsaUhva5nnTW6GFf+F/7+0mj19k/3DjiH+kAetMXuE8vYRNJdVVQUNBWPveR wcwlh0VLzuKbTC6+T+/UCaCj/T+DCRAjLU//yUUp7hSBMwZRw7ktHEMHkkxQ0RStMxuO P1Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b="J2o/jSbB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i7si312643eds.110.2020.10.21.22.04.43; Wed, 21 Oct 2020 22:05:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b="J2o/jSbB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502363AbgJUPUB (ORCPT + 99 others); Wed, 21 Oct 2020 11:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502326AbgJUPT5 (ORCPT ); Wed, 21 Oct 2020 11:19:57 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00731C0613D6 for ; Wed, 21 Oct 2020 08:19:55 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id f19so1652957pfj.11 for ; Wed, 21 Oct 2020 08:19:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AaLxoMYWxby/CcFJviQRdg6riGgNtKHzl1ULFWsI1LU=; b=J2o/jSbBc93JMBnXrzu/phYX6M/NVWFfTlIA7OpoP8cQJHqsH1fCfmioEEyczBIa7H 1TFUxCzNLaAGKRzJMNumqjwy4jAyQeuH3pff4X5POz2WE7+BfxXpGQRGhXHMeR541M1V MTqFoSeAcqpFTA/Ac43tqn1ASzryjx+KJJHa8wh0wAj6uczbum4x1dEOTP8G+J88LpcX dPrAdWYC5Thl3GZjL3y369rWz+CdA9MbfU/zyrtKYOwEO5N7ZOEpqtZ1e7R9MmTg3I50 aH1irSDRlOVgdIaFldJx4BtF7KaVq7IGByGXW1SEyh6HMTRRhQTUnTowNiXCC6F0LpyM +66g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AaLxoMYWxby/CcFJviQRdg6riGgNtKHzl1ULFWsI1LU=; b=jPTK8lHF9REg5AH/FojW9pwDovRqUeoD04qVvB0Gna+f/oMbhPc89z03sGlvzLqzex YZGziP1hsojrNxTsPApkQLDjFE4jForf57WCAljVDgvoW9QnxUpPRGgER7xMY4v4VqH5 zoiWyCYrA9mRr7hsFuaDiFPbl6TLOm30eN6KTnlGSUqN8EzT7nUuS2CGtuFckiDD/OiQ WJkMBcSlM88ClUSVzwha/ciHCYr5uLw1E2kW9cuP+iGeAFtJCeJMgB8rd6j6TaKfuYh+ LMNa7UumGLkdVvcCRVQbtyalqt0D4ppzPkjIiuovLQgp0gE3BIMaAtXYLM6jdaeq1qXx zDWw== X-Gm-Message-State: AOAM531xPRLbZBHHnMAuFVuSC09AgRJQYeK9hp5VDYgLWUq13SAvxdCS iK/0PBFXRh1OjydoVDyrJhq7Ki5Cldwmiw== X-Received: by 2002:a65:5a0d:: with SMTP id y13mr3864078pgs.436.1603293595298; Wed, 21 Oct 2020 08:19:55 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([2620:15c:211:200:4a0f:cfff:fe35:d61b]) by smtp.gmail.com with ESMTPSA id s10sm2409646pji.7.2020.10.21.08.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 08:19:54 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, Mark Salyzyn , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Stephen Smalley , linux-security-module@vger.kernel.org, Miklos Szeredi , Jonathan Corbet , Vivek Goyal , "Eric W . Biederman" , Amir Goldstein , linux-doc@vger.kernel.org, selinux@vger.kernel.org Subject: [RESEND PATCH v18 2/4] overlayfs: handle XATTR_NOSECURITY flag for get xattr method Date: Wed, 21 Oct 2020 08:19:01 -0700 Message-Id: <20201021151903.652827-3-salyzyn@android.com> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201021151903.652827-1-salyzyn@android.com> References: <20201021151903.652827-1-salyzyn@android.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Because of the overlayfs getxattr recursion, the incoming inode fails to update the selinux sid resulting in avc denials being reported against a target context of u:object_r:unlabeled:s0. Solution is to respond to the XATTR_NOSECURITY flag in get xattr method that calls the __vfs_getxattr handler instead so that the context can be read in, rather than being denied with an -EACCES when vfs_getxattr handler is called. For the use case where access is to be blocked by the security layer. The path then would be security(dentry) -> __vfs_getxattr({dentry...XATTR_NOSECURITY}) -> handler->get({dentry...XATTR_NOSECURITY}) -> __vfs_getxattr({realdentry...XATTR_NOSECURITY}) -> lower_handler->get({realdentry...XATTR_NOSECURITY}) which would report back through the chain data and success as expected, the logging security layer at the top would have the data to determine the access permissions and report back to the logs and the caller that the target context was blocked. For selinux this would solve the cosmetic issue of the selinux log and allow audit2allow to correctly report the rule needed to address the access problem. Check impure, opaque, origin & meta xattr with no sepolicy audit (using __vfs_getxattr) since these operations are internal to overlayfs operations and do not disclose any data. This became an issue for credential override off since sys_admin would have been required by the caller; whereas would have been inherently present for the creator since it performed the mount. This is a change in operations since we do not check in the new ovl_do_getxattr function if the credential override is off or not. Reasoning is that the sepolicy check is unnecessary overhead, especially since the check can be expensive. Because for override credentials off, this affects _everyone_ that underneath performs private xattr calls without the appropriate sepolicy permissions and sys_admin capability. Providing blanket support for sys_admin would be bad for all possible callers. For the override credentials on, this will affect only the mounter, should it lack sepolicy permissions. Not considered a security problem since mounting by definition has sys_admin capabilities, but sepolicy contexts would still need to be crafted. It should be noted that there is precedence, __vfs_getxattr is used in other filesystems for their own internal trusted xattr management. Signed-off-by: Mark Salyzyn Cc: linux-fsdevel@vger.kernel.org Cc: linux-unionfs@vger.kernel.org Cc: Stephen Smalley Cc: linux-kernel@vger.kernel.org Cc: linux-security-module@vger.kernel.org Cc: kernel-team@android.com Cc: Miklos Szeredi Cc: Jonathan Corbet Cc: Vivek Goyal Cc: Eric W. Biederman Cc: Amir Goldstein Cc: Stephen Smalley Cc: linux-doc@vger.kernel.org Cc: selinux@vger.kernel.org v18 - correct inode argument to __vfs_getxattr v17 - rebase and add inode argument to __vfs_getxattr v16 - rebase and merge internal getxattr operations patch v15 - revert to v13 because xattr_gs_args rejected. v14 - rebase to use xattr_gs_args. v13 - rebase to use __vfs_getxattr flags option. v12 - Added back to patch series as get xattr with flag option. v11 - Squashed out of patch series and replaced with per-thread flag solution. v10 - Added to patch series as __get xattr method. --- fs/overlayfs/inode.c | 5 +++-- fs/overlayfs/overlayfs.h | 6 ++++-- fs/overlayfs/super.c | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index b584dca845ba..2b14291beb86 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -378,7 +378,7 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, } int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, - void *value, size_t size) + void *value, size_t size, int flags) { ssize_t res; const struct cred *old_cred; @@ -386,7 +386,8 @@ int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, ovl_i_dentry_upper(inode) ?: ovl_dentry_lower(dentry); old_cred = ovl_override_creds(dentry->d_sb); - res = vfs_getxattr(realdentry, name, value, size); + res = __vfs_getxattr(realdentry, d_inode(realdentry), name, + value, size, flags); revert_creds(old_cred); return res; } diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index f8880aa2ba0e..06db4cf87f55 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -184,7 +184,9 @@ static inline ssize_t ovl_do_getxattr(struct ovl_fs *ofs, struct dentry *dentry, size_t size) { const char *name = ovl_xattr(ofs, ox); - return vfs_getxattr(dentry, name, value, size); + struct inode *ip = d_inode(dentry); + + return __vfs_getxattr(dentry, ip, name, value, size, XATTR_NOSECURITY); } static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry, @@ -439,7 +441,7 @@ int ovl_permission(struct inode *inode, int mask); int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, const void *value, size_t size, int flags); int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, - void *value, size_t size); + void *value, size_t size, int flags); ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size); struct posix_acl *ovl_get_acl(struct inode *inode, int type); int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags); diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index f41353ba1e68..d447958badc2 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -930,7 +930,7 @@ ovl_posix_acl_xattr_get(const struct xattr_handler *handler, struct dentry *dentry, struct inode *inode, const char *name, void *buffer, size_t size, int flags) { - return ovl_xattr_get(dentry, inode, handler->name, buffer, size); + return ovl_xattr_get(dentry, inode, handler->name, buffer, size, flags); } static int __maybe_unused @@ -1012,7 +1012,7 @@ static int ovl_other_xattr_get(const struct xattr_handler *handler, const char *name, void *buffer, size_t size, int flags) { - return ovl_xattr_get(dentry, inode, name, buffer, size); + return ovl_xattr_get(dentry, inode, name, buffer, size, flags); } static int ovl_other_xattr_set(const struct xattr_handler *handler, -- 2.29.0.rc1.297.gfa9743e501-goog