Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2294638ybl; Sun, 19 Jan 2020 23:47:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxhap8h/m9OohrQBQj07UUf/GcpCqZDQkHpdtOwXCAtMrMJAZk5ZQ6AycWydSETlfs7Odmf X-Received: by 2002:aca:b286:: with SMTP id b128mr3546885oif.147.1579506424515; Sun, 19 Jan 2020 23:47:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579506424; cv=none; d=google.com; s=arc-20160816; b=HtUe4K4SUYRJpiMooBFMXRh9GJIRB568ydxVM2j0t1iuOY+tKVwxeETnqhp0Ust0x8 sWfxBMVD2VviPc9owrppzVNyEVjW54xn6WfqOVDrBF5WcNoZyhOWWYv6CisBSk7eVcA9 CDIXwWj9MSnsjc2wGY/PEoTMjDa9fLgXr9V28GZfVx0hkgbYsK3+ZeHSfXR1j3fl3QXL juqdYBA9uDJcSRdBO0Xup0tQZT/XHvp5Kg6oAtHRgEJvFtOz4/Emrgjik0DaBU7VFUB+ 05BQUpd3NXRsw94J7OXaEQVl80WAi/5DGSxK8v/IeQOB34drzl2ABpNcZ+E2B6f4ACBe kHcg== 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=U7hfmlqvgEdgRgHWuowCuln6amLAG9DwKTqmAz5e7hk=; b=ignBAB5soVb6rF8b++szICEB+8w6qv3BRqyZJNTto3L+xtdU0S7K1A8JSPHVhbT2zL JECAEN78wnAN5Vy9H8jbgmMgqYOw83htYViSGgiwy5J1bhSgJ+VEbV+c+bSpf5Aii0Om XdY7/7aNu/DD1opX6u8tATqo2XfPyc9/ivx0/Rzf+bFfRBQ/Tg44IS8siL4/0QKJAe4F znl1FvBU+J4B8yKu+j8qiYY2+yRewobJLglV83zYBWfy1nz1S83lAruTbjOUJw4P944a zvtsCyrJmm0ym9zsI/oSZ8ZDFR0opdGHxgZBgAPUlLZZYq6kRH5VESD47HIu+d6N8CL9 pODA== 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 v6si8324246ote.41.2020.01.19.23.46.53; Sun, 19 Jan 2020 23:47:04 -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 S1726421AbgATHqB (ORCPT + 99 others); Mon, 20 Jan 2020 02:46:01 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:44828 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725872AbgATHqB (ORCPT ); Mon, 20 Jan 2020 02:46:01 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1itRl0-00Btkf-JV; Mon, 20 Jan 2020 07:45:58 +0000 Date: Mon, 20 Jan 2020 07:45:58 +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 Subject: Re: vfat: Broken case-insensitive support for UTF-8 Message-ID: <20200120074558.GA8904@ZenIV.linux.org.uk> References: <20200119221455.bac7dc55g56q2l4r@pali> <87sgkan57p.fsf@mail.parknet.co.jp> <20200120073040.GZ8904@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200120073040.GZ8904@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: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...