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_vfs_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 <saly...@android.com> Cc: Miklos Szeredi <mik...@szeredi.hu> Cc: Jonathan Corbet <cor...@lwn.net> Cc: Vivek Goyal <vgo...@redhat.com> Cc: Eric W. Biederman <ebied...@xmission.com> Cc: Amir Goldstein <amir7...@gmail.com> Cc: Randy Dunlap <rdun...@infradead.org> Cc: Stephen Smalley <s...@tycho.nsa.gov> Cc: linux-unio...@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: linux-ker...@vger.kernel.org Cc: kernel-t...@android.com Cc: Eric Van Hensbergen <eri...@gmail.com> Cc: Latchesar Ionkov <lu...@ionkov.net> Cc: Dominique Martinet <asmad...@codewreck.org> Cc: David Howells <dhowe...@redhat.com> Cc: Chris Mason <c...@fb.com> Cc: Josef Bacik <jo...@toxicpanda.com> Cc: David Sterba <dste...@suse.com> Cc: Jeff Layton <jlay...@kernel.org> Cc: Sage Weil <s...@redhat.com> Cc: Ilya Dryomov <idryo...@gmail.com> Cc: Steve French <sfre...@samba.org> Cc: Tyler Hicks <tyhi...@canonical.com> Cc: Jan Kara <j...@suse.com> Cc: Theodore Ts'o <ty...@mit.edu> Cc: Andreas Dilger <adilger.ker...@dilger.ca> Cc: Jaegeuk Kim <jaeg...@kernel.org> Cc: Chao Yu <yuch...@huawei.com> Cc: Bob Peterson <rpete...@redhat.com> Cc: Andreas Gruenbacher <agrue...@redhat.com> Cc: David Woodhouse <dw...@infradead.org> Cc: Richard Weinberger <rich...@nod.at> Cc: Dave Kleikamp <sha...@kernel.org> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Tejun Heo <t...@kernel.org> Cc: Trond Myklebust <trond.mykleb...@hammerspace.com> Cc: Anna Schumaker <anna.schuma...@netapp.com> Cc: Mark Fasheh <m...@fasheh.com> Cc: Joel Becker <jl...@evilplan.org> Cc: Joseph Qi <joseph...@linux.alibaba.com> Cc: Mike Marshall <hub...@omnibond.com> Cc: Martin Brandenburg <mar...@omnibond.com> Cc: Alexander Viro <v...@zeniv.linux.org.uk> Cc: Phillip Lougher <phil...@squashfs.org.uk> Cc: Darrick J. Wong <darrick.w...@oracle.com> Cc: linux-...@vger.kernel.org Cc: Hugh Dickins <hu...@google.com> Cc: David S. Miller <da...@davemloft.net> Cc: Andrew Morton <a...@linux-foundation.org> Cc: Mathieu Malaterre <ma...@debian.org> Cc: Ernesto A. Fernández <ernesto.mnd.fernan...@gmail.com> Cc: Vyacheslav Dubeyko <sl...@dubeyko.com> Cc: v9fs-develo...@lists.sourceforge.net Cc: linux-...@lists.infradead.org Cc: linux-bt...@vger.kernel.org Cc: ceph-de...@vger.kernel.org Cc: linux-c...@vger.kernel.org Cc: samba-techni...@lists.samba.org Cc: ecryp...@vger.kernel.org Cc: linux-e...@vger.kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net Cc: linux-fsde...@vger.kernel.org Cc: cluster-de...@redhat.com Cc: linux-...@lists.infradead.org Cc: jfs-discuss...@lists.sourceforge.net Cc: linux-...@vger.kernel.org Cc: ocfs2-de...@oss.oracle.com Cc: de...@lists.orangefs.org Cc: reiserfs-de...@vger.kernel.org Cc: linux...@kvack.org Cc: net...@vger.kernel.org Cc: linux-security-mod...@vger.kernel.org Cc: sta...@vger.kernel.org # 4.4, 4.9, 4.14 & 4.19 --- v13 - rebase to use __vfs_getxattr flags option v12 - rebase v11 - switch name to ovl_do_vfs_getxattr, fortify comment v10 - added to patch series --- fs/overlayfs/namei.c | 12 +++++++----- fs/overlayfs/overlayfs.h | 2 ++ fs/overlayfs/util.c | 25 ++++++++++++++++--------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index 9702f0d5309d..a4a452c489fa 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -106,10 +106,11 @@ int ovl_check_fh_len(struct ovl_fh *fh, int fh_len) static struct ovl_fh *ovl_get_fh(struct dentry *dentry, const char *name) { - int res, err; + ssize_t res; + int err; struct ovl_fh *fh = NULL; - res = vfs_getxattr(dentry, name, NULL, 0); + res = ovl_do_vfs_getxattr(dentry, name, NULL, 0); if (res < 0) { if (res == -ENODATA || res == -EOPNOTSUPP) return NULL; @@ -123,7 +124,7 @@ static struct ovl_fh *ovl_get_fh(struct dentry *dentry, const char *name) if (!fh) return ERR_PTR(-ENOMEM); - res = vfs_getxattr(dentry, name, fh, res); + res = ovl_do_vfs_getxattr(dentry, name, fh, res); if (res < 0) goto fail; @@ -141,10 +142,11 @@ static struct ovl_fh *ovl_get_fh(struct dentry *dentry, const char *name) return NULL; fail: - pr_warn_ratelimited("overlayfs: failed to get origin (%i)\n", res); + pr_warn_ratelimited("overlayfs: failed to get origin (%zi)\n", res); goto out; invalid: - pr_warn_ratelimited("overlayfs: invalid origin (%*phN)\n", res, fh); + pr_warn_ratelimited("overlayfs: invalid origin (%*phN)\n", + (int)res, fh); goto out; } diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index ab3d031c422b..9d26d8758513 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -205,6 +205,8 @@ int ovl_want_write(struct dentry *dentry); void ovl_drop_write(struct dentry *dentry); struct dentry *ovl_workdir(struct dentry *dentry); const struct cred *ovl_override_creds(struct super_block *sb); +ssize_t ovl_do_vfs_getxattr(struct dentry *dentry, const char *name, void *buf, + size_t size); struct super_block *ovl_same_sb(struct super_block *sb); int ovl_can_decode_fh(struct super_block *sb); struct dentry *ovl_indexdir(struct super_block *sb); diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index f5678a3f8350..c588c0d66d8c 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -40,6 +40,13 @@ const struct cred *ovl_override_creds(struct super_block *sb) return override_creds(ofs->creator_cred); } +ssize_t ovl_do_vfs_getxattr(struct dentry *dentry, const char *name, void *buf, + size_t size) +{ + return __vfs_getxattr(dentry, d_inode(dentry), name, buf, size, + XATTR_NOSECURITY); +} + struct super_block *ovl_same_sb(struct super_block *sb) { struct ovl_fs *ofs = sb->s_fs_info; @@ -537,9 +544,9 @@ void ovl_copy_up_end(struct dentry *dentry) bool ovl_check_origin_xattr(struct dentry *dentry) { - int res; + ssize_t res; - res = vfs_getxattr(dentry, OVL_XATTR_ORIGIN, NULL, 0); + res = ovl_do_vfs_getxattr(dentry, OVL_XATTR_ORIGIN, NULL, 0); /* Zero size value means "copied up but origin unknown" */ if (res >= 0) @@ -550,13 +557,13 @@ bool ovl_check_origin_xattr(struct dentry *dentry) bool ovl_check_dir_xattr(struct dentry *dentry, const char *name) { - int res; + ssize_t res; char val; if (!d_is_dir(dentry)) return false; - res = vfs_getxattr(dentry, name, &val, 1); + res = ovl_do_vfs_getxattr(dentry, name, &val, 1); if (res == 1 && val == 'y') return true; @@ -837,13 +844,13 @@ int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir) /* err < 0, 0 if no metacopy xattr, 1 if metacopy xattr found */ int ovl_check_metacopy_xattr(struct dentry *dentry) { - int res; + ssize_t res; /* Only regular files can have metacopy xattr */ if (!S_ISREG(d_inode(dentry)->i_mode)) return 0; - res = vfs_getxattr(dentry, OVL_XATTR_METACOPY, NULL, 0); + res = ovl_do_vfs_getxattr(dentry, OVL_XATTR_METACOPY, NULL, 0); if (res < 0) { if (res == -ENODATA || res == -EOPNOTSUPP) return 0; @@ -852,7 +859,7 @@ int ovl_check_metacopy_xattr(struct dentry *dentry) return 1; out: - pr_warn_ratelimited("overlayfs: failed to get metacopy (%i)\n", res); + pr_warn_ratelimited("overlayfs: failed to get metacopy (%zi)\n", res); return res; } @@ -878,7 +885,7 @@ ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value, ssize_t res; char *buf = NULL; - res = vfs_getxattr(dentry, name, NULL, 0); + res = ovl_do_vfs_getxattr(dentry, name, NULL, 0); if (res < 0) { if (res == -ENODATA || res == -EOPNOTSUPP) return -ENODATA; @@ -890,7 +897,7 @@ ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value, if (!buf) return -ENOMEM; - res = vfs_getxattr(dentry, name, buf, res); + res = ovl_do_vfs_getxattr(dentry, name, buf, res); if (res < 0) goto fail; } -- 2.22.0.770.g0f2c4a37fd-goog _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel