Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2310544ybl; Mon, 20 Jan 2020 00:08:33 -0800 (PST) X-Google-Smtp-Source: APXvYqygT4ajiTGzc7EhPfw7i0F8UoiYJOnb7f+dFfiHbWWXK4fAm7GDbj1aXSEOrFFNobAch8lV X-Received: by 2002:aca:f10:: with SMTP id 16mr11597690oip.117.1579507713331; Mon, 20 Jan 2020 00:08:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579507713; cv=none; d=google.com; s=arc-20160816; b=gQovh5H1taChYFsiSY4kI6OczDsXyoQLFF5NwNHkd9DK8TZf2G+PB6bdjkGPU/D05T S/QRx/DR9C9NUtkr8T70IVX4yo/99DiyE587ojecimaBoDaRM9SmNHmHWReGPGNpExib A3eB9+8KLN6mbpd+b+muaNygaRWvqppwwOAS2RTnkE8Obrya9+zx5PTI3yA3/rGZOquz D6OrbUqWFn/nca1r46GifyWJH9DHEev15QH2u/FTIEH0kQcllC5Av9vs6UO46NIagmXr yp5Q7P3j+Vm9OvkMchWz8Qk67j+VmfPyihYu9zJvlyDk5ysWaZZsCbNNhJ5fMSlXIe8U Vv/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=I1ZZZDMDQHwnUmq6nHVnQlnf0uNNvbLkk7RuVlMIook=; b=sfvRVXVZ9YgkknyNc8kj1w4fvzVFttOtIJ7wHgkM3jqu7TifrRpcflixxrH387xOqk nSBSglHcb0tnXAmj8ZejrTnvW0iee/ozQOBy5NXYyzRe0PUQcQ9tzChxJxqae5sUY1PD kHKWcXQwVSTjle0T0JwVziTNLRq+dXLl5xB2bkbMZ4rwc95P2agY8a9kkN/oDDDFxE8s mGJW+hhSzY3V3Rv2liUhKgIhY3Zr4/q+Mu4XYssgkG2w7XcJc1ylQlltbANdNtCh7Sy7 H+nOxbnYJTS09wFz52cy7GGGfZsUOxo5Dq47sq7RqeDX921qJsVS/4VRhLRKzBZZNNrc mQBg== ARC-Authentication-Results: i=1; mx.google.com; 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 l18si19896530oth.236.2020.01.20.00.08.21; Mon, 20 Jan 2020 00:08:33 -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; 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 S1726451AbgATIHZ (ORCPT + 99 others); Mon, 20 Jan 2020 03:07:25 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:45080 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726075AbgATIHZ (ORCPT ); Mon, 20 Jan 2020 03:07:25 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1itS5h-00BuDu-HA; Mon, 20 Jan 2020 08:07:21 +0000 Date: Mon, 20 Jan 2020 08:07:21 +0000 From: Al Viro To: OGAWA Hirofumi Cc: Pali =?iso-8859-1?Q?Roh=E1r?= , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Theodore Y. Ts'o" , Namjae Jeon , Gabriel Krisman Bertazi , Linus Torvalds Subject: oopsably broken case-insensitive support in ext4 and f2fs (Re: vfat: Broken case-insensitive support for UTF-8) Message-ID: <20200120080721.GB8904@ZenIV.linux.org.uk> References: <20200119221455.bac7dc55g56q2l4r@pali> <87sgkan57p.fsf@mail.parknet.co.jp> <20200120073040.GZ8904@ZenIV.linux.org.uk> <20200120074558.GA8904@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200120074558.GA8904@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 20, 2020 at 07:45:58AM +0000, Al Viro wrote: > On Mon, Jan 20, 2020 at 07:30:40AM +0000, Al Viro wrote: > > > > > Yup, that bug is there as well, all right. Look: > > #ifdef CONFIG_UNICODE > > static int ext4_d_compare(const struct dentry *dentry, unsigned int len, > > const char *str, const struct qstr *name) > > { > > struct qstr qstr = {.name = str, .len = len }; > > struct inode *inode = dentry->d_parent->d_inode; > > > > if (!IS_CASEFOLDED(inode) || !EXT4_SB(inode->i_sb)->s_encoding) { > > > > Guess what happens if your (lockless) call of ->d_compare() runs > > into the following sequence: > > CPU1: ext4_d_compare() fetches ->d_parent > > CPU1: takes a hardware interrupt > > CPU2: dentry gets evicted by memory pressure; so is its parent, since > > it was the only thing that used to keep it pinned. Eviction of the parent > > calls dentry_unlink_inode() on the parent, which zeroes its ->d_inode. > > CPU1: comes back > > CPU1: fetches parent's ->d_inode and gets NULL > > CPU1: oopses on null pointer dereference. > > > > It's not impossible to hit. Note that e.g. vfat_cmpi() is not vulnerable > > to that problem - ->d_sb is stable and both the superblock and ->nls_io > > freeing is RCU-delayed. > > > > I hadn't checked ->d_compare() instances for a while; somebody needs to > > do that again, by the look of it. The above definitely is broken; > > no idea how many other instaces had grown such bugs... > > f2fs one also has the same bug. Anyway, I'm going down right now, will > check the rest tomorrow morning... We _probably_ can get away with just checking that inode for NULL and buggering off if it is (->d_seq mismatch is guaranteed in that case), but I suspect that we might need READ_ONCE() on both dereferences. I hate memory barriers...