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=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 7555DC433E6 for ; Mon, 8 Feb 2021 18:05:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4800A64E54 for ; Mon, 8 Feb 2021 18:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235399AbhBHSFc (ORCPT ); Mon, 8 Feb 2021 13:05:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:47386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234608AbhBHSDA (ORCPT ); Mon, 8 Feb 2021 13:03:00 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4547464E54; Mon, 8 Feb 2021 17:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612807150; bh=ap1IUf3l3kOGAnjvPyfn/TaxqnlnIUVbMCDPOcRniQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p1j9u+6irsV+hfWzzhTla2Wwq5vHmnJzT3gA2ZDIYdnRhOA3WkR86NmNEqDT+ZQWJ 6WDI5iDLYaeVMrPTUSDejrlO2s7l6Bb6uiAqfHEtsYPogEsozhGjE32O3NohMbqWL3 TqCqKwlK7btQ4SMIbOR9h3OAZm4KYHqb4MEucyA9qiDB6YcsqQgOXnRmfoj4ppX0xz vv24NhHuCuv+DaA05cjRF9ZQvXI2e2VKxoUyRBqiHJmhjb7gnsGhGFi7+8CVOAPiDL W5IF0EsRPpt+u3KWLFFIJNh8tX0mHgWmD5EBQPguPAuWuurfje0NyWpxVu/QszBae6 eKW8DO/7qIYig== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Amir Goldstein , Michael Labriola , Miklos Szeredi , Sasha Levin , linux-unionfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 08/19] ovl: skip getxattr of security labels Date: Mon, 8 Feb 2021 12:58:47 -0500 Message-Id: <20210208175858.2092008-8-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210208175858.2092008-1-sashal@kernel.org> References: <20210208175858.2092008-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-unionfs@vger.kernel.org From: Amir Goldstein [ Upstream commit 03fedf93593c82538b18476d8c4f0e8f8435ea70 ] When inode has no listxattr op of its own (e.g. squashfs) vfs_listxattr calls the LSM inode_listsecurity hooks to list the xattrs that LSMs will intercept in inode_getxattr hooks. When selinux LSM is installed but not initialized, it will list the security.selinux xattr in inode_listsecurity, but will not intercept it in inode_getxattr. This results in -ENODATA for a getxattr call for an xattr returned by listxattr. This situation was manifested as overlayfs failure to copy up lower files from squashfs when selinux is built-in but not initialized, because ovl_copy_xattr() iterates the lower inode xattrs by vfs_listxattr() and vfs_getxattr(). ovl_copy_xattr() skips copy up of security labels that are indentified by inode_copy_up_xattr LSM hooks, but it does that after vfs_getxattr(). Since we are not going to copy them, skip vfs_getxattr() of the security labels. Reported-by: Michael Labriola Tested-by: Michael Labriola Link: https://lore.kernel.org/linux-unionfs/2nv9d47zt7.fsf@aldarion.sourceruckus.org/ Signed-off-by: Amir Goldstein Signed-off-by: Miklos Szeredi Signed-off-by: Sasha Levin --- fs/overlayfs/copy_up.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index ec5eca5a96f41..7b758d623b5bd 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -76,6 +76,14 @@ int ovl_copy_xattr(struct dentry *old, struct dentry *new) if (ovl_is_private_xattr(name)) continue; + + error = security_inode_copy_up_xattr(name); + if (error < 0 && error != -EOPNOTSUPP) + break; + if (error == 1) { + error = 0; + continue; /* Discard */ + } retry: size = vfs_getxattr(old, name, value, value_size); if (size == -ERANGE) @@ -99,13 +107,6 @@ int ovl_copy_xattr(struct dentry *old, struct dentry *new) goto retry; } - error = security_inode_copy_up_xattr(name); - if (error < 0 && error != -EOPNOTSUPP) - break; - if (error == 1) { - error = 0; - continue; /* Discard */ - } error = vfs_setxattr(new, name, value, size, 0); if (error) break; -- 2.27.0