Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1575383pxb; Mon, 22 Feb 2021 05:47:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpLPryMjhcreujl+4VqOzU6UKR/aXXSwpmzK2VpWjftr276SR8vnzqP8MNs9bCpdDWqUIb X-Received: by 2002:a17:906:8474:: with SMTP id hx20mr1033979ejc.129.1614001631552; Mon, 22 Feb 2021 05:47:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614001631; cv=none; d=google.com; s=arc-20160816; b=lGOqn07BEivzH/GJqsX2HHPqnSn1hqNFN1KEYYsN6JNJzV8k9BOznkBO+qF5GipAxQ gyav5cw1gI5QD0iyq1XF2HtB/YYo9GUHhtE5W8hPYmDN6XYXHSWE7i2/hn2SRDvfeg4I QmasA+lCTgKCW5U+blGMGJ0g4vHLH0louTUMX1aGl6UrvwWDhrvfh7YPW/a7uxXUZBi/ H4C58hpClapjc5EdPNshg0YtuQBTwC91u/mT3Esdw/8oHulo28gOHjy3a6/DfBmEPWjs hCJWB4OLCvtIhLCZkENMtxN1PiyuU2hq8SZ4HeOWgm60rBb3Oqykr4QC/1MSUJG7KMRw G9sQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aDsF81gRCismvLKAG74z4FK1Doww2AyyogkN1A8RzOI=; b=Dj3nlmu3WoVvqYThRyM+/yjAM2KNe+53AJhliOLZ4tFlwh5n0K5fKu/45eHIAXbRBI eIsZNQuVZT8kgpna2yZ3Sgdo+wa8Ebub8USeKOd6QX+G5ctZFSkib4n+l/fU5WXyNxV+ FxilLfZf8zNXF+cZAf3hLyODsryxDW8PCDSvtWea1Gf6eXufsjym5enqotBM84ku8QPj HzjIWx+3XroNkqqzFtu0GKMtgIidvUo+ddMIgsH96tBDnBUA4Mkb+wYyzKeyzTnZMLjU 9UI2KeyFoGZEneBLiMoWCHODD/28KfC7ukKXqhH6tC49WrQ/o9s17fvjAQEBgwzS97dE y6tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WXALvOMJ; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a26si11565928edx.311.2021.02.22.05.46.49; Mon, 22 Feb 2021 05:47:11 -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=@linuxfoundation.org header.s=korg header.b=WXALvOMJ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231262AbhBVNoK (ORCPT + 99 others); Mon, 22 Feb 2021 08:44:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:53774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbhBVMnn (ORCPT ); Mon, 22 Feb 2021 07:43:43 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2F73464F10; Mon, 22 Feb 2021 12:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613997673; bh=QUtKFAoRPJZHXQ+GnyQafka6VaqnzUHT5+fH1ToKpJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WXALvOMJAzKGHk8yRAsZfEFPrCjIUOFG9C3UJtOS9Ol72E4xA5mzZ80uVz9PKVQqf efyTmrCMn/FnNyYxTOO9/pwGDI6RS0W4lJgbDcKtK+UNyucNqE3CdrL0E5BGX2kpRi b+QwzH7Ge1dyBNvQgc1OD22qH5AaJMthxe0nwG94= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Labriola , Amir Goldstein , Miklos Szeredi , Sasha Levin Subject: [PATCH 4.9 21/49] ovl: skip getxattr of security labels Date: Mon, 22 Feb 2021 13:36:19 +0100 Message-Id: <20210222121026.477741173@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210222121022.546148341@linuxfoundation.org> References: <20210222121022.546148341@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 @@ retry: 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