Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5040836pxu; Wed, 21 Oct 2020 11:37:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhKCQtr/X75VBHzemiODzQ02uuhXm5BQ0krq7AHyowhTGIaZD0/pJ1cZjhMqtTdJ8qkvIw X-Received: by 2002:a17:906:6a8b:: with SMTP id p11mr1592895ejr.470.1603305437546; Wed, 21 Oct 2020 11:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603305437; cv=none; d=google.com; s=arc-20160816; b=ZVyUdlce5sq+HADpfS5BOtXp+D34bpmsTo4rX+hjbwt8Ewz4gBdgoNrnINDGXvxhHN Pm6Q2d7fGEaftnVlblsKh+anAA95mvbIC9YXxinFJSVy28+6A2+mF8VfIZMHf7yp1VQs V+1l+wFgzIGPgzrP4SrVO8Ab4aIizAGADV9HqoqKcNXvaj4LqZTWF7lnb3uN4OoHBsWE 4RpLWg8UiCHsnw6tav80z+g7WmyE5kZJI+wr5d4+CPswIQp/YsOXM3KhinGYGe939bi8 DfBnl2awHJoHXZAWUfotLTWFm7hN+rALjm4GhAmfpkQOiJbArK2t8iBFZhH7xfd4mVJZ BmAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=pEyd0fTbwnGq1j4mR/39y5YMzLAxT1RpmVEZDz9Z3mQ=; b=Ivmx/Tj2ZELthG2TH5NRkVKqj8dRWV3YpDVlo0/S0qD0iZcMMI9WF8b90i7A1wL++M /4hYCZNP4aH2IBmXiA6/gW1o/T5NzkfabrXdKbWzvWaLZ1HaO/ZrnL0K7YEbupAfaogV Anyao6OtflmZ1QL758fXjVrNNmfrmUIxqAxFWYUfxuxmyq+uOIJ4VeH6uFY8GIHhcifz Xg08Q+iYcYnax2GURzWToZSu3wCT240uDsi7I8di6SebDBvnwP6f5wjU+MEA0LqRTmBG qy73fNPWSr159MKHOGY+qx/XYoi68q74KVjLpydrfbv7mxitCUbrKfl19Jtd832cwAfN PF0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=WLDBkCPq; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u25si2000351eds.353.2020.10.21.11.36.55; Wed, 21 Oct 2020 11:37:17 -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=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=WLDBkCPq; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439871AbgJUBRc (ORCPT + 99 others); Tue, 20 Oct 2020 21:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439859AbgJUBRb (ORCPT ); Tue, 20 Oct 2020 21:17:31 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4E4FC0613CE for ; Tue, 20 Oct 2020 18:17:29 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id t21so696948eds.6 for ; Tue, 20 Oct 2020 18:17:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pEyd0fTbwnGq1j4mR/39y5YMzLAxT1RpmVEZDz9Z3mQ=; b=WLDBkCPqHeYGcvqVhE7x9bAwmmbNPSjZFwkxdnIXYyihDcvr7Ied3PFcAWuOZMUt7H ttvHpMCHf7p78/P4JtZXkxn597jQPI3QK0FMgKjVYiLwdB5OIPdlkT7BdBNLhfiNeOKA oN6kMul/uY1QudZ/RePQhfnOQwxxpxiLok0HkKqZknh+hYt70CFQ3BYE0nmviM0ZuFK+ jaO+SYy/PzU2xyE9b2QYVqwwB9FLMsfn+oty4XlUF059oF48ga+hnN9tS3tkOSFqiN+u qQNzyiec3KRhgxJj5JNnPabHRk1MItkwIGNL6xdGQOIcr30FdB+2IZ7Juv1dKehTw+i7 LZiA== 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; bh=pEyd0fTbwnGq1j4mR/39y5YMzLAxT1RpmVEZDz9Z3mQ=; b=L+PerpoS3CgFtYIVe6Lp+28I/PN5cudoeJ1rdne92+JFxIujvdrvFTaHcCnTnic0iN Bi3By6Hfi7hS455oU4aFAvGQZeqwfxsT4l10aFO+lTDqYVtblpg5BxRrqCukEISNwHyI C4q3kYt475JOqvma5qK/xKeXOzegDqz211l0n9hXD2rl1L8c9uGV5H3HW+f0K35hG+mg B05fDPG4Lu8J4/C6aOSknSb19AN48Aut70kJhFt6xjkkfDT4yq/Ym5CMadzA1ChMpWJ2 T+noUZo6Hrp1jP/LV+YWybgFElbNuXmbU10a7RWyJr1fgCEEP6ivsWvUEicI0mz2jOuj xtCQ== X-Gm-Message-State: AOAM530v8xGF7eH2U8Z4TCJNaGtbPiZLhxyBe02ilTpF0mxqmgdOnNb/ YN4DKPBTntVa0Ot+yAghc+WHZ6CJl4xQo+5zZUuiOOH17g== X-Received: by 2002:aa7:d7ca:: with SMTP id e10mr647617eds.269.1603243047445; Tue, 20 Oct 2020 18:17:27 -0700 (PDT) MIME-Version: 1.0 References: <20201020191732.4049987-1-salyzyn@android.com> <20201020191732.4049987-2-salyzyn@android.com> In-Reply-To: <20201020191732.4049987-2-salyzyn@android.com> From: Paul Moore Date: Tue, 20 Oct 2020 21:17:16 -0400 Message-ID: Subject: Re: [PATCH v17 1/4] Add flags option to get xattr method paired to __vfs_getxattr To: Mark Salyzyn Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Jan Kara , Jeff Layton , David Sterba , "Darrick J . Wong" , Mike Marshall , Stephen Smalley , linux-security-module@vger.kernel.org, selinux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 20, 2020 at 3:17 PM Mark Salyzyn wrote: > > Add a flag option to get xattr method that could have a bit flag of > XATTR_NOSECURITY passed to it. XATTR_NOSECURITY is generally then > set in the __vfs_getxattr path when called by security > infrastructure. > > This handles the case of a union filesystem driver that is being > requested by the security layer to report back the xattr data. > > For the use case where access is to be blocked by the security layer. > > The path then could be security(dentry) -> > __vfs_getxattr(dentry...XATTR_NOSECURITY) -> > handler->get(dentry...XATTR_NOSECURITY) -> > __vfs_getxattr(lower_dentry...XATTR_NOSECURITY) -> > lower_handler->get(lower_dentry...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 the target > context that was blocked. > > Without the get handler flag, the path on a union filesystem would be > the errant security(dentry) -> __vfs_getxattr(dentry) -> > handler->get(dentry) -> vfs_getxattr(lower_dentry) -> nested -> > security(lower_dentry, log off) -> lower_handler->get(lower_dentry) > which would report back through the chain no data, and -EACCES. > > For selinux for both cases, this would translate to a correctly > determined blocked access. In the first case with this change a correct avc > log would be reported, in the second legacy case an incorrect avc log > would be reported against an uninitialized u:object_r:unlabeled:s0 > context making the logs cosmetically useless for audit2allow. > > This patch series is inert and is the wide-spread addition of the > flags option for xattr functions, and a replacement of __vfs_getxattr > with __vfs_getxattr(...XATTR_NOSECURITY). > > Signed-off-by: Mark Salyzyn > Reviewed-by: Jan Kara > Acked-by: Jan Kara > Acked-by: Jeff Layton > Acked-by: David Sterba > Acked-by: Darrick J. Wong > Acked-by: Mike Marshall > To: linux-fsdevel@vger.kernel.org > To: 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 ... > diff --git a/fs/xattr.c b/fs/xattr.c > index cd7a563e8bcd..d6bf5a7e2420 100644 > --- a/fs/xattr.c > +++ b/fs/xattr.c > @@ -345,7 +345,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value, > return PTR_ERR(handler); > if (!handler->get) > return -EOPNOTSUPP; > - error = handler->get(handler, dentry, inode, name, NULL, 0); > + error = handler->get(handler, dentry, inode, name, NULL, 0, 0); > if (error < 0) > return error; > > @@ -356,32 +356,20 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value, > memset(value, 0, error + 1); > } > > - error = handler->get(handler, dentry, inode, name, value, error); > + error = handler->get(handler, dentry, inode, name, value, error, 0); > *xattr_value = value; > return error; > } > > ssize_t > __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name, > - void *value, size_t size) > + void *value, size_t size, int flags) > { > const struct xattr_handler *handler; > - > - handler = xattr_resolve_name(inode, &name); > - if (IS_ERR(handler)) > - return PTR_ERR(handler); > - if (!handler->get) > - return -EOPNOTSUPP; > - return handler->get(handler, dentry, inode, name, value, size); > -} > -EXPORT_SYMBOL(__vfs_getxattr); > - > -ssize_t > -vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) > -{ > - struct inode *inode = dentry->d_inode; > int error; > > + if (flags & XATTR_NOSECURITY) > + goto nolsm; > error = xattr_permission(inode, name, MAY_READ); > if (error) > return error; > @@ -403,7 +391,19 @@ vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) > return ret; > } > nolsm: > - return __vfs_getxattr(dentry, inode, name, value, size); > + handler = xattr_resolve_name(inode, &name); > + if (IS_ERR(handler)) > + return PTR_ERR(handler); > + if (!handler->get) > + return -EOPNOTSUPP; > + return handler->get(handler, dentry, inode, name, value, size, flags); > +} > +EXPORT_SYMBOL(__vfs_getxattr); > + > +ssize_t > +vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) > +{ > + return __vfs_getxattr(dentry, dentry->d_inode, name, value, size, 0); > } > EXPORT_SYMBOL_GPL(vfs_getxattr); [NOTE: added the SELinux list to the CC line] I'm looking at this patchset in earnest for the first time and I'm a little uncertain about the need for the new XATTR_NOSECURITY flag; perhaps you can help me understand it better. Looking over this patch, and quickly looking at the others in the series, it seems as though XATTR_NOSECURITY is basically used whenever a filesystem has to call back into the vfs layer (e.g. overlayfs, ecryptfs, etc). Am I understanding that correctly? If that assumption is correct, I'm not certain why the new XATTR_NOSECURITY flag is needed; why couldn't _vfs_getxattr() be used by all of the callers that need to bypass DAC/MAC with vfs_getxattr() continuing to perform the DAC/MAC checks? If for some reason _vfs_getxattr() can't be used, would it make more sense to create a new stripped/special getxattr function for use by nested filesystems? Based on the number of revisions to this patchset, I'm sure it can't be that simple so please educate me :) -- paul moore www.paul-moore.com