Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1475605pxu; Thu, 8 Oct 2020 12:23:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxr4bdCwvJM4YHBYz0uzxDruEuoxnTiH3gmBcaU07vHaB9aGQdiVY7dWm76KEyBLoDWOqcN X-Received: by 2002:a17:906:647:: with SMTP id t7mr8185591ejb.428.1602185019132; Thu, 08 Oct 2020 12:23:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602185019; cv=none; d=google.com; s=arc-20160816; b=ya1ekHdwA9fXCm6SwDJgOBn9fSAI34ZXo+0sqV/1NhMHYQ2h2/moCnccGe0E7C63+d zkTLnVoUFA0VeKAahyUIpw7mmrHvt5GRzLpzewhbgvHn2nadAF6+BNPsfU8fN3Rfivhr /jpc7w1laQSh0r6gEf8ntBDLHUzy/nIXxMZibgkQdC2idJkKvcWz+1TTdhcDmPtrehnV ArHiywMM9293pCsvJh0B7KGUEZ/s8UgR8303acrknxNd9wu4tGoakPzw0VdXyccipl4B hbo3pCsqeZn6SexHc181LdYiMNIOfSMGzENLQPIBXObkv04fd2XQ/xtGKqAX/IoKHtLg vFLw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=n7KS2L6PN3krMBY5ATxY3SGA2G7c97FyL8qU1PJ4Ebk=; b=TNtvZyBZdyatuCr0jYlfFj7U7t1pJ88pe2zFLCSYlzYt2oYkRQ+YLaNUoDuZ88yK91 cxfUS8eW6Id/eSQuOdmTmp+qh5syH1iMAGhFOkn8K0Iyp2PXakVnJEucwXFKHbob/7M2 A6RZnpVr9IFlHw9rYl/zmh4BJ9lyBEv1jQzF2Ntn3RBJY83yhnWZ+CaOllm3g1M+TZFb pgFBKa8TNybZrYKzzz2BV/c8ZyZZnBtIVbCP5rmNPeNeEspXSCuF2B9xrAONrmP+pMlx UqYkGxK9amE4s03zi7/5uJVcHbRAl8Ar3OsLvsjPf1L92MS8p5Kt0WpDQJ21+QDIOdvn mIVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qKGAlpbG; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c15si4248918edx.256.2020.10.08.12.23.15; Thu, 08 Oct 2020 12:23:39 -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=@kernel.org header.s=default header.b=qKGAlpbG; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729872AbgJHTQu (ORCPT + 99 others); Thu, 8 Oct 2020 15:16:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:59290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729883AbgJHTQt (ORCPT ); Thu, 8 Oct 2020 15:16:49 -0400 Received: from ebiggers-linuxstation.mtv.corp.google.com (unknown [104.132.1.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 868C021789; Thu, 8 Oct 2020 19:16:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602184608; bh=lexhJREGzh+/V1ER4S2AHbrxdRthtEv6r0KJwlclks0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qKGAlpbG4OOoEJ39yOZrI0Ynhku9gSvjjvr3ZOqu0wyOMpdNnsWm2vKqewWp6GWdI mXQvmSp84eTaMtPevuVefKdF/knNC4TkPArkM1ZVcOuBcOFvL1UHFq53AwuiaeAl47 hbrrO6ioBdX0157aAcfbyMzkPVkmx92CEZyaJUgw= From: Eric Biggers To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Cc: Daniel Rosenberg , Gabriel Krisman Bertazi , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, syzkaller-bugs@googlegroups.com, syzbot+05139c4039d0679e19ff@syzkaller.appspotmail.com Subject: [PATCH] f2fs: reject CASEFOLD inode flag without casefold feature Date: Thu, 8 Oct 2020 12:15:22 -0700 Message-Id: <20201008191522.1948889-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.28.0.1011.ga647a8990f-goog In-Reply-To: <00000000000085be6f05b12a1366@google.com> References: <00000000000085be6f05b12a1366@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers syzbot reported: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] CPU: 0 PID: 6860 Comm: syz-executor835 Not tainted 5.9.0-rc8-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:utf8_casefold+0x43/0x1b0 fs/unicode/utf8-core.c:107 [...] Call Trace: f2fs_init_casefolded_name fs/f2fs/dir.c:85 [inline] __f2fs_setup_filename fs/f2fs/dir.c:118 [inline] f2fs_prepare_lookup+0x3bf/0x640 fs/f2fs/dir.c:163 f2fs_lookup+0x10d/0x920 fs/f2fs/namei.c:494 __lookup_hash+0x115/0x240 fs/namei.c:1445 filename_create+0x14b/0x630 fs/namei.c:3467 user_path_create fs/namei.c:3524 [inline] do_mkdirat+0x56/0x310 fs/namei.c:3664 do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x44/0xa9 [...] The problem is that an inode has F2FS_CASEFOLD_FL set, but the filesystem doesn't have the casefold feature flag set, and therefore super_block::s_encoding is NULL. Fix this by making sanity_check_inode() reject inodes that have F2FS_CASEFOLD_FL when the filesystem doesn't have the casefold feature. Reported-by: syzbot+05139c4039d0679e19ff@syzkaller.appspotmail.com Fixes: 2c2eb7a300cd ("f2fs: Support case-insensitive file name lookups") Signed-off-by: Eric Biggers --- fs/f2fs/inode.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 2ed935c13aed..d5664bc7d6c6 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -287,6 +287,13 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page) return false; } + if ((fi->i_flags & F2FS_CASEFOLD_FL) && !f2fs_sb_has_casefold(sbi)) { + set_sbi_flag(sbi, SBI_NEED_FSCK); + f2fs_warn(sbi, "%s: inode (ino=%lx) has casefold flag, but casefold feature is off", + __func__, inode->i_ino); + return false; + } + if (f2fs_has_extra_attr(inode) && f2fs_sb_has_compression(sbi) && fi->i_flags & F2FS_COMPR_FL && F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, base-commit: db40330b0de9a9d9939178f48cd5fc5e3fab14de -- 2.28.0.1011.ga647a8990f-goog