Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4262951pxb; Mon, 8 Feb 2021 11:50:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjVDEU4CRR1JKg3R8ZUisH8Pv7pqQcj3kgbZa6c4Y5/aIGPQ9aawxMKd2aa0D2eK7wgAkC X-Received: by 2002:a17:907:7295:: with SMTP id dt21mr18981385ejc.518.1612813801290; Mon, 08 Feb 2021 11:50:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612813801; cv=none; d=google.com; s=arc-20160816; b=ERTwMDjpsyEh0RHduEVDJHMNWF+oSGErStFH9q+wsGk0jSJV0jSoGH72CLBNkdjXir OMi1PAXfGuZop6ZuaixJkL6EqsJRwR3rMQ8MwFjqmRDPc9ssqUhknS1l9gXcZO3bBt5E iJOOYAMvU+e+W58vC/ugfpAjKS6rXu67HIIhLQYjCzd4zNhKsyVYO4sw4L5l/enRJN67 Tv2jT5NCxzkBF/1+7VapXmIuQUSHHv0P1U47PQPYjpYGQzQ+rrl1+oYrHZqkN0hGfYD6 y7KQ2mryD8vbTjSfXRQTBNkyRLANz0z6RMvtjXljE/p8J30XiHgIPaiX/ujssYVCvHaX xT2Q== 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=acCyTNqdIv7Rsp6jw1w4jOLSW9rZ9RjBDWeDsSgR6hk=; b=iE8E5KPI2pFdUrFDemXdl1VUfz9lBqKEHy0J5zU9VoBPbhqplE3cLasCPbzs2gb6Qf VEv+puUMfSvYZD3nQNeiBT1xhrWbrSCizsE8K9UA4Q8d/EiwuRoO1q0v9iyoj+xfmkzv ABJeR9k5AqJInsRvHuLi7UCe/YaLQHfGWrcfiZTDg3ssZNEY1e+iG2oHfa8t5w6wzcth WY/IS44lYeoBovnp2xDKh1CGTG4u8W546hbn5mfsTd/7vsmHT1p9ISd0WvTSO4TWC6sA Fbr7l33f8Cc1xE20HJmjcGrBYNISCel67b9bCaOZtY+vLQfdeeqUSiVTJYIJitkuYdKd Z9YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jN7Sci2b; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b21si13203673edx.44.2021.02.08.11.49.38; Mon, 08 Feb 2021 11:50:01 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=jN7Sci2b; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236377AbhBHTqj (ORCPT + 99 others); Mon, 8 Feb 2021 14:46:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:49236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235400AbhBHSFd (ORCPT ); Mon, 8 Feb 2021 13:05:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC7BE64EF7; Mon, 8 Feb 2021 18:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612807203; bh=QkB5lHRWO5R1Y6A2oZiR2JHKe5zRWyF3Rwwp+qVBTbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jN7Sci2bW3+rOlYlaF1//E4R//wnUNlSbBsaqD2AKyfqMSzrciE8w95zYoPiqiUAN b4nDPbzdj5f/HL+a4IQ5to12PvoTQdUSlr+JOb8awPVsdtNdUa7IRQvtTHio5U3+6y t/nUkrRsg4FqIXNx41OxqjEwuFWfo3ehEV2xXOCfMYDghlg+3GBSJ1HU0Ac2/0B9pf 4+cYqV7v2LET/sHgHvJsrdstcP2AwGBskTOSxIrUgUPkp4qkMg4L7YuWycboUPiQUw B1oyrnhsTKgGcgejXpVaFqUfyB2vPUd1vWYRFal94ynfy5J+MwkcsxlOQhqM/Oqog+ 6b+0sK4/VyR4w== 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 4.9 2/4] ovl: skip getxattr of security labels Date: Mon, 8 Feb 2021 12:59:58 -0500 Message-Id: <20210208180000.2092497-2-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210208180000.2092497-1-sashal@kernel.org> References: <20210208180000.2092497-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-kernel@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 299dbf59f28f8..3a583aa1fafeb 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -92,6 +92,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) @@ -115,13 +123,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