Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3772045pxv; Mon, 19 Jul 2021 08:23:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt3JvPjpUZbt9VRqFe+6t/5pddvIimX+XNpO3JWqh3+cDN+A4NjLaqQ1aQo1uREhjrAx+S X-Received: by 2002:a5e:8519:: with SMTP id i25mr18651604ioj.152.1626708210863; Mon, 19 Jul 2021 08:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626708210; cv=none; d=google.com; s=arc-20160816; b=RLRM5dCiwRYtxnvsHKFAVBQThGzSK9ShortEd8+yVRtY5+QsqQmFLEfCnsyL+R/j0h Q1r7jEzZ4kyGKgM6s4T/bTkChKo+Nv/LwVv+RfIFKTdlmn7qKDeH/1NJRzMdhwFFkD+b aBd7I+qOLhNVpYbRCExE1WjVxZ5aGvI/kM83VdvLf1YBY4lltCfD1VHDIYvvMrUyNzsG vZccJsy+Hj5pfntdRlVQ+1dfZekL0XwfGDjJwpEn4ZhrDZ1Mi3rwdS3GmZWxPo4EbPHt kUb+rCBX3zyUkd5GWKJboLBzUI7l1Bb7qcOtjxkIQVznoMT97npKG10uddN1ABjYwR0h 9WUw== 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=6hW95a10Zo1wsS+zuNQfQIR16HKSNXzadCEivdqTmE8=; b=Rp9DeAUf0/b1cz0zVnsmLgYErdlN+Pc+1zYedwfnLtSRo9cjubxFg8cngfjFRIlk61 brN49GjkYIdAQQxw8iaeuqFvCndO+HEpJe5bmqXfY+JdGFDZa8W1gEBZEMxiCZJW6jg5 FYKVFs0c1X8UFNOPB9E6LuyF9Z/sg1XvwC/+Rof8xxnIW3VA9kBNmqMjT7R7Y1CNWeSx 7qd1jrvYsLyDO/ZdiK0IQEgB10jeAJpEo51SMUae1tay+VwOyTH1iii5CDRky11z61Gd 2lFfYlFUED8T6oQIa776p+RgymAt2RfzBgdb4K3yRSe5+bRaxJoJrmkPFhdb6lRpZCUl cWTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UiVKBlLU; 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 q11si19518257ilv.18.2021.07.19.08.23.17; Mon, 19 Jul 2021 08:23:30 -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=UiVKBlLU; 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 S244995AbhGSOli (ORCPT + 99 others); Mon, 19 Jul 2021 10:41:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:46568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244197AbhGSOaq (ORCPT ); Mon, 19 Jul 2021 10:30:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ADBA860720; Mon, 19 Jul 2021 15:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707485; bh=L0zgcQIKVkliCKL0ngoGDlHZIUlPMjmbdue2oigr6pI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UiVKBlLULIV/f1yk1azfeD8+FYVPngAwWimyOM3kWfXrL57fyrR6XEq8PwI7X79GI OcdKiaZviLtZh09+SOjwwP//rGJuRpaEsTarkAcddtbbvRPzhPsspdN/0+U0XIgrC4 jQmu4K45FLESyVRrtrCmPXQpQU638ylN7Mgtq/O0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers Subject: [PATCH 4.9 184/245] fscrypt: dont ignore minor_hash when hash is 0 Date: Mon, 19 Jul 2021 16:52:06 +0200 Message-Id: <20210719144946.348022472@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@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 | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) --- a/fs/crypto/fname.c +++ b/fs/crypto/fname.c @@ -294,12 +294,8 @@ int fscrypt_fname_disk_to_usr(struct ino oname->name); return 0; } - if (hash) { - memcpy(buf, &hash, 4); - memcpy(buf + 4, &minor_hash, 4); - } else { - memset(buf, 0, 8); - } + memcpy(buf, &hash, 4); + memcpy(buf + 4, &minor_hash, 4); memcpy(buf + 8, iname->name + ((iname->len - 17) & ~15), 16); oname->name[0] = '_'; oname->len = 1 + digest_encode(buf, 24, oname->name + 1);