From patchwork Thu Aug 1 14:02:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Mosnacek X-Patchwork-Id: 11070791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB3F1746 for ; Thu, 1 Aug 2019 14:02:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDAA5286F2 for ; Thu, 1 Aug 2019 14:02:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC129286FB; Thu, 1 Aug 2019 14:02:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A845286F2 for ; Thu, 1 Aug 2019 14:02:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731468AbfHAOCx (ORCPT ); Thu, 1 Aug 2019 10:02:53 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51074 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730581AbfHAOCw (ORCPT ); Thu, 1 Aug 2019 10:02:52 -0400 Received: by mail-wm1-f68.google.com with SMTP id v15so64798738wml.0 for ; Thu, 01 Aug 2019 07:02:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q9l8o0YUUYULIRBa/EVzGkj6Ut5sD4tK2q63xppuwv8=; b=ieZB/kcfBSeK5fJqRGAQi5VsPZpAWoCuY8W7nzQSbDowR9U1U399/mXxpQ5FDQFTes 6y6CnwdZYEaPHCThpOo4ShlZUkO5pzJNUsn26iWEjX+T+urtZ307bvdHTMHNZQIqyAAO X8uOMIG894pLSAQgD1u9O+D4b8mEgPT/dljNrfzY7KLnkt2O10pEvwaq//DYRvKEXWnb QYZI2HKHhWon9qC4iOaomFGGqiwKrIhaKq9di7HKrMusRJfQTZRfEJgTxTVNy9hE27/o wVrS+QU+HS4dAvG16ZLPRx8PUFgVZxxc+RskeBtCDO0CdwhieEkZ/5oJy+ibUGdxY6Zs mDsQ== X-Gm-Message-State: APjAAAV1lW/PbGSrvegIEMU+MqIuqOzP8FXt1SkiJAn/8CKfeiB5dZ3R W5uqbwGSDr6tEdARpcE+hXNLxzEmQ8g= X-Google-Smtp-Source: APXvYqzXEb+285MZOoJB+6F3vWCSdWbbUe7nEOtmuU/D3ChtMO2hzcI+kZ/rCC+3PLbqLbag6JyNaQ== X-Received: by 2002:a1c:f018:: with SMTP id a24mr113136377wmb.66.1564668169963; Thu, 01 Aug 2019 07:02:49 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id z7sm69909162wrh.67.2019.08.01.07.02.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 07:02:49 -0700 (PDT) From: Ondrej Mosnacek To: selinux@vger.kernel.org, Paul Moore Cc: Al Viro , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 4/4] selinux: use d_genocide_safe() in selinuxfs Date: Thu, 1 Aug 2019 16:02:43 +0200 Message-Id: <20190801140243.24080-5-omosnace@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190801140243.24080-1-omosnace@redhat.com> References: <20190801140243.24080-1-omosnace@redhat.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Letting the following set of commands run long enough on a machine with at least 3 CPU threads causes soft lockups in the kernel: (cd /sys/fs/selinux/; while true; do find >/dev/null 2>&1; done) & (cd /sys/fs/selinux/; while true; do find >/dev/null 2>&1; done) & (cd /sys/fs/selinux/; while true; do find >/dev/null 2>&1; done) & while true; do load_policy; echo -n .; sleep 0.1; done The problem is that sel_remove_entries() removes the old selinuxfs entries using d_genocide() + shrink_dcache_parent(), which is not safe to do on live trees that are still exposed to userspace. Specifically, it races with dcache_readdir(), which expects that while a dentry's inode is locked, its (positive) children cannot get unlisted, because both unlink() and rmdir() lock the parent inode first. Therefore, use the newly introduced d_genocide_safe() instead of d_genocide(), which fixes this issue. Bug tracker links: * SELinux GitHub: https://github.com/SELinuxProject/selinux-kernel/issues/42 * Red Hat Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1510603 Fixes: ad52184b705c ("selinuxfs: don't open-code d_genocide()") Signed-off-by: Ondrej Mosnacek --- security/selinux/selinuxfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index e6c7643c3fc0..58d1949e5faf 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -1317,7 +1317,7 @@ static const struct file_operations sel_commit_bools_ops = { static void sel_remove_entries(struct dentry *de) { - d_genocide(de); + d_genocide_safe(de); shrink_dcache_parent(de); }