Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1536996pxb; Mon, 22 Feb 2021 04:46:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6MZQeRFRMm8uxaAoDGWJLvBgk1f2Lbz5/ZV8tXVGzfXnVB7o8aQXjNgNF6KoSZpLdceAU X-Received: by 2002:aa7:cb8f:: with SMTP id r15mr22659708edt.130.1613998012695; Mon, 22 Feb 2021 04:46:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613998012; cv=none; d=google.com; s=arc-20160816; b=onpe1bW979eGs3/zTBsWG7BQ4AeR3U8TBDi8vtp1dhW8S+/YY1ovvYLqJLVMW/aKq0 CKdCCc68Zl10QGBaz/n2ZYDVz8X6Wwts2Fo3Wqy9UdAoVvJ53m3zxhWnIP/xE6Q3mBbZ lD08tSkNBsCEGVmtFjNlc7D/rp0C77c1Gj0VDV3jcfzY08uxqsvYkjfpYQCSftOvq4XV pR69XCtQ4ZSK/+gt/PI24xrs6kNOlUlcjE16OWVOVLr2PM8x5L3jAyQJqoiaOjWLNoHG 5BQyciGOWqEHYQ6IWyy3PHWEgc85Lvq/9dhw3qN/KEu4ZOeGF/q3LuUavdTTJ0yiApuf S7JA== 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=Zf1suMyHZI02YnxWtiXy6W5MwvqeQ2QGaHYSlSCIUeE=; b=ebmbW7beH+/7v+ebaAbg9ELaJPq07547l9pJI9S4tXObj2p+nBzkfNoT/kTbtNpMI+ MWT8AfEkQr7tmyGcleJqi7yrkHL00q0LunCN2f1DJc5iu00hmZXBfrJT/6L8EfpXN2Q/ AckunEokjojWFcsl5bfjHixFO3/Y+oYIyHBzRjnpUWOIMMqi4DHV6PsmWAnRigusEEmi avsXuwnyQ7PZmtpbeVe28AkhnoVCEOFsaVgtt1kL97n87jfpvpUpXVAnVxw/ghwfADF/ n9GNBFbtFHLwa5AJMWySCOaJ+rQDF9ifJZMr7RhPZ4DaZw6LGC2KWvNa41lxKar9yQgj L9hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tV6zr2TY; 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 ga26si6849284ejb.236.2021.02.22.04.46.30; Mon, 22 Feb 2021 04:46:52 -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=tV6zr2TY; 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 S231628AbhBVMnb (ORCPT + 99 others); Mon, 22 Feb 2021 07:43:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:47000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbhBVMRo (ORCPT ); Mon, 22 Feb 2021 07:17:44 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D842B64F00; Mon, 22 Feb 2021 12:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613996223; bh=/xmGoCgABF1f5UabHb4jBUvs5ctjYKuG4H3qs4tdsI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tV6zr2TY2htwPwbdaru2J5CG4j5Iu7NnnKFOZUZ6kLYgSTTm5OAT2upGnnLP59ofg 2JosM+KBhqm4jk827HzSuaOa2wvYojLWrHzedFNMhFna3VZY7tsQoYLiWVFvwLnaXX oM2sP2TP+5hZH4+phpn8cvsbGqCjO26QO72zAZcM= 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.19 08/50] ovl: skip getxattr of security labels Date: Mon, 22 Feb 2021 13:12:59 +0100 Message-Id: <20210222121021.769360483@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210222121019.925481519@linuxfoundation.org> References: <20210222121019.925481519@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 6eb0b882ad231..e164f489d01d9 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -79,6 +79,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) @@ -102,13 +110,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