Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3694649ybv; Mon, 10 Feb 2020 04:51:44 -0800 (PST) X-Google-Smtp-Source: APXvYqxTuCqSkxPCT5AsXa/nBWW5YczP6KN5hcaTXxEr2vgPBq1/BcLQfiPVg5UPPy1mUoFJB6KX X-Received: by 2002:a9d:7f8d:: with SMTP id t13mr860058otp.175.1581339104491; Mon, 10 Feb 2020 04:51:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339104; cv=none; d=google.com; s=arc-20160816; b=SeLj9MdgY2ZY05tkq4DweIT8Q28c6ptJYODyrMVPfkvKmaZnnd9nmYc23kuDZTpxaJ XPEOaoe9/ckW3Kglgcy+utHGmgrIJadkYG3U4qV9HVJu35IVT4Mp2q1Qr6HFUXlU43BT MibKl/qoAWXLalBrpCWf8fCEZ744eu8SbRs9u+uqyZsHP6b5LK0f+6GDmpbYt+CwLMm2 VOPjHGmk2ZAyQJJGGAMMHzeD2DTl87/CS6wOiVuOUN3tJwaXFFU85kxM5hM20jGy/hAG whB10il7qCdOW/byEkGv+GAeQLmfKyHuk79B0MVaaZBmb6CnRQJ8LVS5pmW+oG58kgym 8QkA== 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=NywS5FL/wt7KeEcBRchWNxnWkrH7srF4fm2SO9Fngvk=; b=JBt3oYGPjn7wAQJyKiVfEANU59X5glE2/vyfxXb2nMRz2rPYrkVusm5MFfqyD+WA4F 1C/T7hAo2x0XYi/FpYVzozJxKHqORTFP8zkwXYWUiLgXsbh+iNgEpOfrYDEzby0HtT/E 2hMRlCtooOWUDo1mhmvHfsy6N7dBuMVpItJj572b+IKD2W+PtIiIehCfDqWNHYGXW4wO YYl+u3kR+oZf35HyJ//lZ3Fxw2V0ojgl81ksKcH5YGwRX5k9WkNbRc1UmvqqW7WG+Ak6 4WO5GiB6DYXQVUGZKiueJ98/zCQuz1lwjhvtPeh8NlgV59JaMLFWrhWbnjBDWyB43sCr XLmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fo18i+Ot; 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 73si120740oii.60.2020.02.10.04.51.32; Mon, 10 Feb 2020 04:51:44 -0800 (PST) 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=fo18i+Ot; 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 S1728817AbgBJMng (ORCPT + 99 others); Mon, 10 Feb 2020 07:43:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:39178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729604AbgBJMkE (ORCPT ); Mon, 10 Feb 2020 07:40:04 -0500 Received: from localhost (unknown [209.37.97.194]) (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 5FE4220838; Mon, 10 Feb 2020 12:40:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338402; bh=FOHZbTGAvBk6lJvEzRP0bkJy0m/poj8G8okJ9yEAMds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fo18i+Oti5NhJ3uUjzPK66u2YI8nOgm+X/BC34tVDOt4OCufdM3EyUpWoRmMNlWpx xVos6rjFJNmlfKMKuUXkaDSJn+enAdCryjdUXdvCPsc1wxOGYed/yr40ffMNvTMSAs JfCvIRT4BmIAzMs9wTTnUW7u9OoIyodiB8L/r/Ic= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers Subject: [PATCH 5.5 102/367] ubifs: dont trigger assertion on invalid no-key filename Date: Mon, 10 Feb 2020 04:30:15 -0800 Message-Id: <20200210122433.782243999@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@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: Eric Biggers commit f0d07a98a070bb5e443df19c3aa55693cbca9341 upstream. If userspace provides an invalid fscrypt no-key filename which encodes a hash value with any of the UBIFS node type bits set (i.e. the high 3 bits), gracefully report ENOENT rather than triggering ubifs_assert(). Test case with kvm-xfstests shell: . fs/ubifs/config . ~/xfstests/common/encrypt dev=$(__blkdev_to_ubi_volume /dev/vdc) ubiupdatevol $dev -t mount $dev /mnt -t ubifs mkdir /mnt/edir xfs_io -c set_encpolicy /mnt/edir rm /mnt/edir/_,,,,,DAAAAAAAAAAAAAAAAAAAAAAAAAA With the bug, the following assertion fails on the 'rm' command: [ 19.066048] UBIFS error (ubi0:0 pid 379): ubifs_assert_failed: UBIFS assert failed: !(hash & ~UBIFS_S_KEY_HASH_MASK), in fs/ubifs/key.h:170 Fixes: f4f61d2cc6d8 ("ubifs: Implement encrypted filenames") Cc: # v4.10+ Link: https://lore.kernel.org/r/20200120223201.241390-5-ebiggers@kernel.org Signed-off-by: Eric Biggers Signed-off-by: Greg Kroah-Hartman --- fs/ubifs/dir.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -228,6 +228,8 @@ static struct dentry *ubifs_lookup(struc if (nm.hash) { ubifs_assert(c, fname_len(&nm) == 0); ubifs_assert(c, fname_name(&nm) == NULL); + if (nm.hash & ~UBIFS_S_KEY_HASH_MASK) + goto done; /* ENOENT */ dent_key_init_hash(c, &key, dir->i_ino, nm.hash); err = ubifs_tnc_lookup_dh(c, &key, dent, nm.minor_hash); } else {