Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp838652ybi; Fri, 12 Jul 2019 05:30:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwhcJvdU5/XwEA0oK68UnuggpFXZRLpai3nK0LjF0PeiUDtPk7zHOl/PQbAQX+Y9cvCWah X-Received: by 2002:a17:902:7202:: with SMTP id ba2mr11366184plb.266.1562934613435; Fri, 12 Jul 2019 05:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934613; cv=none; d=google.com; s=arc-20160816; b=ORUjj98VtiW+zIsxwb4BNZcHUiBtRascjcdwcaJ7YBhpy0/z9x26mMylQUbYeppsdj 5ymCan4gTra1xAzVzOH93RpgL7gajqUVKDoC4Hdq7A1Xs+bzBEUA+JRQ4IgPC5mHkiBr 0C1xbrqghSJV0cCgWKJi80c1j1j0oJRFKm2K6ibJXlelKq7ipRJ/hSpEu3uZKVTKdAWk NUhqLr5/Ngbs3rDj+d4TGoe+O62EC0oINscp3zf15IENxQK2x7A1dRceg6gW3RBuLpFw wAwvpKEKmMOq7KeepZSNkb9Gx96pdG5VlBSrILptuZVzXsxDLtK1QSnfHvZx5eXJnGak 6a9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=su3xy/NlmqC5ExDYHOXLq1cw7YsR4+6trXzEdgPtPOg=; b=ElUhH/51bzmBi4En+GBEXq8WaRRD7Vh6gHVWax9KadvnqrhfV1wFHB/qBnFHgJaywC uigcw6WBg4q3hcKOfkdxAQfl7J64TOcL673x7Evu0ano8t08uj2yaK84uxPsLCtS2mWd MqqrF927abvqCcZJSScmLZ6PKej9ewo8tG5dG3aAp6rn4yDfjvJTV59t5zbweGn7MNGT EKg7hYrauEo+QjzXH/j8xIHbb5K8uT4dPOLHOy/90BO+bTAsZY3kRp1BSiLwOSuDkXo2 cu+MU+zdhX+bA60p8xPaf/Rs+pcsypt9nOed97CoM/xOTwizp5PjJNxCm7p8RVEQoNOc ZrTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Vf8Dr2XR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m99si7976886pjb.107.2019.07.12.05.29.58; Fri, 12 Jul 2019 05:30:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Vf8Dr2XR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728902AbfGLM24 (ORCPT + 99 others); Fri, 12 Jul 2019 08:28:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:43350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728890AbfGLM2y (ORCPT ); Fri, 12 Jul 2019 08:28:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7C1762166E; Fri, 12 Jul 2019 12:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934534; bh=NcZZzhaLzdat+yqaF8MIGu8GX/hbheQFPNJEoYo0n4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vf8Dr2XRL64hYlS2wgYCMqdQ1sg9YgAHZnZsvLuEfXtiWQPJllDkiWplBDLHAfyd4 Mh/N1eHnx2ZvVC+6Ubu53alMdUKu74Yw4TwZ7CDkYXcg7HcMMkBp1uyk0QsSjx7NeD Xf/gJPIIdnJ2walqw4Nwkz86SiXWuZJ3zghU59SY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hongjie Fang , Eric Biggers Subject: [PATCH 5.1 088/138] fscrypt: dont set policy for a dead directory Date: Fri, 12 Jul 2019 14:19:12 +0200 Message-Id: <20190712121632.121875906@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hongjie Fang commit 5858bdad4d0d0fc18bf29f34c3ac836e0b59441f upstream. The directory may have been removed when entering fscrypt_ioctl_set_policy(). If so, the empty_dir() check will return error for ext4 file system. ext4_rmdir() sets i_size = 0, then ext4_empty_dir() reports an error because 'inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2)'. If the fs is mounted with errors=panic, it will trigger a panic issue. Add the check IS_DEADDIR() to fix this problem. Fixes: 9bd8212f981e ("ext4 crypto: add encryption policy and password salt support") Cc: # v4.1+ Signed-off-by: Hongjie Fang Signed-off-by: Eric Biggers Signed-off-by: Greg Kroah-Hartman --- fs/crypto/policy.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -81,6 +81,8 @@ int fscrypt_ioctl_set_policy(struct file if (ret == -ENODATA) { if (!S_ISDIR(inode->i_mode)) ret = -ENOTDIR; + else if (IS_DEADDIR(inode)) + ret = -ENOENT; else if (!inode->i_sb->s_cop->empty_dir(inode)) ret = -ENOTEMPTY; else