Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9042245pxu; Mon, 28 Dec 2020 05:13:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZzAj8r+SumWeHduwQOme0XrvwMh2N/fHBXfdTzOnfU/VMHrnJP2SEFbfcOVy+sqqgpiB3 X-Received: by 2002:a17:907:94c6:: with SMTP id dn6mr41676843ejc.13.1609161194579; Mon, 28 Dec 2020 05:13:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609161194; cv=none; d=google.com; s=arc-20160816; b=tP08urNnFM9wBSIMvZ2J6TB3AXQgXPg0bQjxtCSdTq8GwptHSc5Kz8a+sWF6BNn9A6 s9nh3k/IP/+DdAWSlgc8lFvXvqce0tk/50zXz6DMc7dE4LnlW848BWV7g08BeHcDCp0p D+88gBugU0uDxtWDUKZQBjsowI4N917UzOZMvR3zeNZgpkLytleo3bSriea6MifvoXmY fQN/38IDjSiWPAl6msiFWl7YNL+MyVCWXhMsDLBLIYSsJnwN7fdYJyAHOyzP8qLLkhVP hQWh83F66DW6VTUTdsYpaVePLrO0alqjOvu84R3fJfvGHiYBTAgThzmELzxrH9J5dCa9 CWdQ== 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=jH8wIOgN8OSSDeehMiS1O0+5kulPyDD8h2wq9YuJwys=; b=08MoWaa/1lk6vrnnnGRL/MmM+M1pHClPKA8g/Rjwp7Pu3WtwwqvCI2CVKlsjqnQUxn bNXbGEKPsOfFIovZXKN5nLiDOX2lDBYVIcUH67PPh5pGR4ijFeWsx9WRppoOKmDdMkCR NVxilZ8uegHmv0TPOyLBDwvRJiRFRfwhKNCCCnCJSR9zEaZ8qi6ZKX5ExooRj1nDw/Hn CHgOjJecxsyze25kaZ6hH7cgxbO+ZPIMKUYqV62s1/gJZwJt5sSF11DTW+S1pjPhAKLw PqYaEx8xPmIZRi3B76X6hOKQYzPCMsZVqthOvv7k92qbHD4Se4KzwJc7pPsH6CEw79Oj N1cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hOFdKnqZ; 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 d16si19642845edp.251.2020.12.28.05.12.50; Mon, 28 Dec 2020 05:13:14 -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=hOFdKnqZ; 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 S1731464AbgL1NKx (ORCPT + 99 others); Mon, 28 Dec 2020 08:10:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:38716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731445AbgL1NKw (ORCPT ); Mon, 28 Dec 2020 08:10:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 16F79207C9; Mon, 28 Dec 2020 13:10:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161011; bh=E1Po2a34Nul6cELi0O22gqoF+HdPOMydSDjCgxKwYAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOFdKnqZ7+u6YWyeZszwsIibERg2iFNguSvsgHnV2ue4OpIjT52Z30HcWx9hSOXKf 7vgWtmH+bRUaFYXBwYGdzhqxQwWYCK4ysQIQgdf+A0dH7oOZu2y1nvY7cOedAAcJVo IjrypHXkxGXcRdyjMDTsmg4hqOZX1WsfwM8q40cw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tianyue Ren , Paul Moore , Sasha Levin Subject: [PATCH 4.14 069/242] selinux: fix error initialization in inode_doinit_with_dentry() Date: Mon, 28 Dec 2020 13:47:54 +0100 Message-Id: <20201228124908.081784056@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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: Tianyue Ren [ Upstream commit 83370b31a915493231e5b9addc72e4bef69f8d31 ] Mark the inode security label as invalid if we cannot find a dentry so that we will retry later rather than marking it initialized with the unlabeled SID. Fixes: 9287aed2ad1f ("selinux: Convert isec->lock into a spinlock") Signed-off-by: Tianyue Ren [PM: minor comment tweaks] Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- security/selinux/hooks.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 5def19ec11797..af8ddae0ddedb 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -1569,7 +1569,13 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent * inode_doinit with a dentry, before these inodes could * be used again by userspace. */ - goto out; + isec->initialized = LABEL_INVALID; + /* + * There is nothing useful to jump to the "out" + * label, except a needless spin lock/unlock + * cycle. + */ + return 0; } len = INITCONTEXTLEN; @@ -1677,8 +1683,15 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent * inode_doinit() with a dentry, before these inodes * could be used again by userspace. */ - if (!dentry) - goto out; + if (!dentry) { + isec->initialized = LABEL_INVALID; + /* + * There is nothing useful to jump to the "out" + * label, except a needless spin lock/unlock + * cycle. + */ + return 0; + } rc = selinux_genfs_get_sid(dentry, sclass, sbsec->flags, &sid); dput(dentry); -- 2.27.0