Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1146698ybm; Fri, 29 May 2020 23:45:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+YTZGbfaNqexL1BlArPoyOjg9Jcwgxz0FByFIiAPa43KVOYyIxXhfgfR2U39LqK2ZbNjZ X-Received: by 2002:a17:906:9397:: with SMTP id l23mr7671226ejx.79.1590821130359; Fri, 29 May 2020 23:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590821130; cv=none; d=google.com; s=arc-20160816; b=VuAefDAA4xByehfOJKGz0bCb1MDeRgWrWq5BXK1i7HLa/j8/CTpiYbv8LeLzf/TQws VbIUuldbcL+YFWqAeOYIPFUHS6p6+zvDfmvMlnYBHdzCIek8/LgmVYuFtpWU1/VZGSyX u93JSGCYWMcDaeujmlntQVrqJHkjnMlvx1DQ8zASAwvW52LDE0VCNigvbR0ShvV2mrCu qquBEfGngYmg71MZuY+mih4M3pTwIx1HtpYB/izC+dELFd3tVnMxg1t6EaQay/PD6FGQ OvWBeWxNgUQM4RQghi6yiOHRRs9uvcaz6c76BOmF9s6f6+pCmzDv8HrLVDk5gIAbihq6 wWBQ== 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 :dkim-signature; bh=dY/KbrK93QD/g0DSblzOx0Jy/r+hU80HBmXKEIIL+KE=; b=wMvZapBbsxG9s0skLPBzhnSzwAJh/ps+Asx4Qu4XjokQ2QE+1M7/OMq2P1cLvfyOju Ufc8w4idJepaUiRKagGyIlzh3B7bPBawsc6KzaD6VncfvQ37q2fxWEzv42ahnluHZJfJ THI2SrgAxwvkbRjrPTIAjzPD+NVABjXt9SvrcdgzGtHLG6dvGRnCj3ry3WmnWkYKuaVv hZvxB/xfsXOemnW5Q1qaYJSSlT/w2Z0TAhFpo5KaHVedoBBRXc/7cE6QEuKaTonpvllo sLEPC1VvpgF2PtD7N3vb0+xWY7VLooeG8R1KhrV7QGLu+pOnBFq2B3rqVqItcy8tfVlE mZ1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ci/MEcvw"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 k14si5143695edr.351.2020.05.29.23.44.58; Fri, 29 May 2020 23:45:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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="ci/MEcvw"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 S1726843AbgE3Gox (ORCPT + 99 others); Sat, 30 May 2020 02:44:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:42180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbgE3Gow (ORCPT ); Sat, 30 May 2020 02:44:52 -0400 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2EBD12074B; Sat, 30 May 2020 06:44:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590821092; bh=Vfljkewu5yJyeYteJw8SGwaWsoTPtwkSKdk4FvA1jTM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ci/MEcvwk27WjIwHUyNQ7oCgaVEplLP2VEwBZAr5lkXgqQAS+SvzonxWlpup5n43U EsFbxD/pfZrmwbTuEXG1NaWPiOkUevOVpctUFaGlnazdhEtaVNAn+9C2MSp2DtzCnM RL1MUP0n6M572M3b8U2UNMpZwi6kiDxDU+V/oEaA= Date: Fri, 29 May 2020 23:44:50 -0700 From: Eric Biggers To: Gabriel Krisman Bertazi Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, stable@vger.kernel.org, Al Viro , Daniel Rosenberg , Gabriel Krisman Bertazi Subject: Re: [PATCH] ext4: avoid utf8_strncasecmp() with unstable name Message-ID: <20200530064450.GA317593@sol.localdomain> References: <20200530060216.221456-1-ebiggers@kernel.org> <85d06mkkv5.fsf@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <85d06mkkv5.fsf@collabora.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Sat, May 30, 2020 at 02:17:02AM -0400, Gabriel Krisman Bertazi wrote: > > > > + /* > > + * If the dentry name is stored in-line, then it may be concurrently > > + * modified by a rename. If this happens, the VFS will eventually retry > > + * the lookup, so it doesn't matter what ->d_compare() returns. > > + * However, it's unsafe to call utf8_strncasecmp() with an unstable > > + * string. Therefore, we have to copy the name into a temporary buffer. > > + */ > > + if (len <= DNAME_INLINE_LEN - 1) { > > + unsigned int i; > > + > > + for (i = 0; i < len; i++) > > + strbuf[i] = READ_ONCE(str[i]); > > + strbuf[len] = 0; > > + qstr.name = strbuf; > > + } > > + > > Could we avoid this if the casefolded version were cached in the dentry? > Then we could use utf8_strncasecmp_folded which would be safe. Would > this be acceptable for vfs? The VFS assumes that each dentry has one name, the one in d_name. That's what it passes to ->d_compare(), and that's what it updates in __d_move(). So while ext4 and f2fs could put the casefolded name in ->d_fsdata, ->d_compare() wouldn't actually have access to it (unless we added d_fsdata as a parameter to ->d_compare()). Also, the casefolded name would get outdated when __d_move() changes d_name. We could instead make d_name always be the casefolded name. I'm not sure that would be possible, though. For one, I don't think ->lookup() is allowed to just change the dentry name. It would also make getcwd(), /proc/*/fd/, etc. always show casefolded names, which could be problematic. And probably other issues I can't think of off the top of my head. - Eric