Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5029160pxb; Mon, 15 Feb 2021 07:45:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0PjUMCqIlextyvZh3p36EPt7/QBhlA+7+IMTPw45o9+8trjKfl/Z0bpsZOgIv/cpNpUDE X-Received: by 2002:a05:6402:883:: with SMTP id e3mr2389457edy.336.1613403901398; Mon, 15 Feb 2021 07:45:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613403901; cv=none; d=google.com; s=arc-20160816; b=GdFrHtioxJz6AvqmK6v2ELCoSfwTM9dHTxWTvCA/pH+czg9nJ4xQoRi8VxACCvzpSE 214KYXQEpeuq8DS35vcN46o0qmmJJuTulBbNMjia5YGN6byDgbhsJnrWGekIqUe+hhqd bwmjy8JNMatiBGxuol8kqdvKHflnX7V4J1pfzUpb8+t9OmwbA31ckzVwgE22Ho75L8uA l+UV7ffkgYlNVGLLMWnymolwgXAdEpy32lIWWhmYwFdCEonZ+D73ypuX2Z4S0iOxidxZ 5q+eY8XSUFsl0TubIUrQ0d2Rir+ja0DQSBYTpVLfZ7yOfI7yCYpwKtQOfv7uiE+ln/5/ fPBA== 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=eKrv3zEWtsR6s7X7PZzOvJIF8ZAGo7S/lAI3FgEDNok=; b=BuyT7+BEXjGfy5xfZWoJWTMZnZj48XbO74e8NCAmri4zOk34kGQjGh8UF+pPNNAzFC FT0y/AgZ9EgFBAqGOEYW/q0XJUGCG5Pm5LHHsd9w1Wln5yZZK3bXY2HsQwbj/dcq8Q8h TMLEatDi+BptSfcP5EBoaxcWEQdRGYb7taijo8qrwrpYw/shCgcx3BxxLdTJwNc9Wc0K 57goqlmHnXr9Ek1YTp7ydvDhSORd8nLkZObyWanVY+qHuHU33Sn0nRxBUkKsQC6ypzTA WXGQxtpYEXv+wQFvcGAnvPYjNdS/r/5yc5qhQgkDtcXTLKF4ucAXRKORpp7zYSQfEuZg wSlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1ZphGjU3; 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 os3si12425544ejb.661.2021.02.15.07.44.38; Mon, 15 Feb 2021 07:45: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=@linuxfoundation.org header.s=korg header.b=1ZphGjU3; 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 S230314AbhBOPnn (ORCPT + 99 others); Mon, 15 Feb 2021 10:43:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:45572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231184AbhBOPay (ORCPT ); Mon, 15 Feb 2021 10:30:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 91B3C64DBA; Mon, 15 Feb 2021 15:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613402949; bh=/oBINWDiQUGltYOyt7yACtw2wC0EBHA8BV2LQVzw+3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1ZphGjU3bpajD8jLBIGPeQo7usNiDprjtQKZGxkUWNMwwA7ry01huUDZAlNSY5Aqt gMCqJ/IQW9FZa1V6kFr5cKTMa+Tw90KKA6PIHuOxa4NNaXKCAYZDXYOtU0gMe5IlSi F4iFzGERTspUp/ZrzWlsC9cBq7jyht4azRrs/NAo= 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 5.4 13/60] ovl: skip getxattr of security labels Date: Mon, 15 Feb 2021 16:27:01 +0100 Message-Id: <20210215152715.799220993@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@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 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 @@ 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