Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp621945pxv; Thu, 15 Jul 2021 11:46:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEr5GMdCM5EkI1jxtEr2LMiD5CdWuMmH4/A8qxuZ4Z0Ptv+EDCIbnXuXLaeIXYN77Z60zY X-Received: by 2002:a05:6e02:1947:: with SMTP id x7mr3726154ilu.85.1626374779629; Thu, 15 Jul 2021 11:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626374779; cv=none; d=google.com; s=arc-20160816; b=tQyHJ+5R/a259eH2gq/Utqwlud9Okk22s1QyQhcBWzBwYWvQKbwk+g8ARYDbt8lZHX SgxOiR89noh+3bEmWgmOX4hg72V/u9Eo+xmuw8jDnqiNpZAkqcDeQDzqBM6gKzCv2XhM ceUl23uRZDaT331mniu6kai4v9BK7YeAvPNXAWAUd3Q3yuIw/UHjx5vJZwWLPL9PCPhS qwpJAlSM92Jk43iCqZfXiGzlkOCwviFWlX0wdXPQZCj0uf1KyEWhzOnMPJ6UgvcOlzIj QKGq3Oc5idF7kYa8sfn3xkviJB1TIzgWl5PZ1DWWxnkxRa2jeG53hugC8YPFrzCqqCuY Me6Q== 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=9imQIFoXKVODibUbfUOGIJdVJqAFGPGGtGlMQdVn5IM=; b=bI9xHGvy3LHBeN1tkOlNQjdruTP7L5PGMEZS+DeD8xyBP2ywOLKjjTLHiEt/fv6eH1 SD/r50bNKtw3kPFnSotVNastLO3t4T1rgiKnrJqL7vJnK9kEpS+KXGU7qlxb6YyCj00s rm0sVLXp0e1kBuhAGnj/ONnZ0pQQHPukjhczlMa/pTOZ5m8jTZCEcVo9ZBrjWjjfd8PG c0K4zKFExgDVSj8adJbtUumCRXcxuxIKEglzhfixxciEFZ4Gk1F0BIT53ykpVuz++Aia loXi8XIveUWWqv0n78D/8Y7W+g02NKxovQ3F8y9nJN0utqmSYggG55CTfB4A/T9D2hoH b5xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MdkJSVvg; 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 w9si7536067jad.35.2021.07.15.11.46.07; Thu, 15 Jul 2021 11:46:19 -0700 (PDT) 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=MdkJSVvg; 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 S238996AbhGOSsd (ORCPT + 99 others); Thu, 15 Jul 2021 14:48:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:48878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238541AbhGOSrD (ORCPT ); Thu, 15 Jul 2021 14:47:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4C550613D2; Thu, 15 Jul 2021 18:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374649; bh=M+F6BmugNILsthoEZGHxwsnnWekLE5M474umSlmbt+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MdkJSVvge4Shl5QgjCQN9XQL+1If+HOSsB94IAFOhGs/aXG9xLUFVCilj6cJhHvNG FpgjKnEbFi9Tz/m6Pd/FlNsJchYMrW81ASHVeQr7GxmWSu9B9+sdIx1D9tApsGGxn5 Czmr5UFapjAyfP1EGXP8rEi0orILGAY0msDKfodg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers Subject: [PATCH 5.4 072/122] fscrypt: dont ignore minor_hash when hash is 0 Date: Thu, 15 Jul 2021 20:38:39 +0200 Message-Id: <20210715182508.798967886@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182448.393443551@linuxfoundation.org> References: <20210715182448.393443551@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: Eric Biggers commit 77f30bfcfcf484da7208affd6a9e63406420bf91 upstream. When initializing a no-key name, fscrypt_fname_disk_to_usr() sets the minor_hash to 0 if the (major) hash is 0. This doesn't make sense because 0 is a valid hash code, so we shouldn't ignore the filesystem-provided minor_hash in that case. Fix this by removing the special case for 'hash == 0'. This is an old bug that appears to have originated when the encryption code in ext4 and f2fs was moved into fs/crypto/. The original ext4 and f2fs code passed the hash by pointer instead of by value. So 'if (hash)' actually made sense then, as it was checking whether a pointer was NULL. But now the hashes are passed by value, and filesystems just pass 0 for any hashes they don't have. There is no need to handle this any differently from the hashes actually being 0. It is difficult to reproduce this bug, as it only made a difference in the case where a filename's 32-bit major hash happened to be 0. However, it probably had the largest chance of causing problems on ubifs, since ubifs uses minor_hash to do lookups of no-key names, in addition to using it as a readdir cookie. ext4 only uses minor_hash as a readdir cookie, and f2fs doesn't use minor_hash at all. Fixes: 0b81d0779072 ("fs crypto: move per-file encryption from f2fs tree to fs/crypto") Cc: # v4.6+ Link: https://lore.kernel.org/r/20210527235236.2376556-1-ebiggers@kernel.org Signed-off-by: Eric Biggers Signed-off-by: Greg Kroah-Hartman --- fs/crypto/fname.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) --- a/fs/crypto/fname.c +++ b/fs/crypto/fname.c @@ -273,13 +273,8 @@ int fscrypt_fname_disk_to_usr(struct ino oname->name); return 0; } - if (hash) { - digested_name.hash = hash; - digested_name.minor_hash = minor_hash; - } else { - digested_name.hash = 0; - digested_name.minor_hash = 0; - } + digested_name.hash = hash; + digested_name.minor_hash = minor_hash; memcpy(digested_name.digest, FSCRYPT_FNAME_DIGEST(iname->name, iname->len), FSCRYPT_FNAME_DIGEST_SIZE);