From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A58DC352A3 for ; Mon, 10 Feb 2020 13:32:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA67820714 for ; Mon, 10 Feb 2020 13:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581341556; bh=QAZXJ/sae3h0vsMDXh6DwTtV4mUQUtgNoAGVanXsHw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GIl9eqQpcIwu+STylEuwktTw7QtJWFyu0Xhq9kvmB8QUiceS9iTy4eR9lbLNBpyAj eXntF9Z8viTLwrB/ishrKBz0F+za6ZMZblfW1ZXAqw+RMLtEbXFn6ihLlMnFvcVSqt XfspaotoCH6odjC6ezy1re7OYXIjfhLGFXYubAiA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728086AbgBJMfo (ORCPT ); Mon, 10 Feb 2020 07:35:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:52582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727916AbgBJMf0 (ORCPT ); Mon, 10 Feb 2020 07:35:26 -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 8EC7A24650; Mon, 10 Feb 2020 12:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338125; bh=QAZXJ/sae3h0vsMDXh6DwTtV4mUQUtgNoAGVanXsHw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ARY9er1s3RD2TY7ACucpQnalbILBmUuOmXW0QraB05HNNqe7Cb7etej0nRH4sZ3xG xL1BxPPfNDBlw/ziEr8ZpDHJ8uSgfEgd0lovA95xn0kDJymDt5LH4aU2B3qiXIW9Qy c4yzd9exVc0M87W39SsntZSG1yDnavdAVMs4IFQA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers Subject: [PATCH 4.19 065/195] ubifs: dont trigger assertion on invalid no-key filename Date: Mon, 10 Feb 2020 04:32:03 -0800 Message-Id: <20200210122312.195454150@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122305.731206734@linuxfoundation.org> References: <20200210122305.731206734@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 @@ -242,6 +242,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 {