Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1413891ybm; Sat, 30 May 2020 08:09:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDImriwuk6TnU2jCZt4s5vGAVRTiDdb6pApHVHc5HfESe40QR50uIehHIqMxM5dF4mwaZa X-Received: by 2002:aa7:da8c:: with SMTP id q12mr13616494eds.334.1590851371326; Sat, 30 May 2020 08:09:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590851371; cv=none; d=google.com; s=arc-20160816; b=Q+89ZKcCJSOegwFbvX4tPrQNjAkT8VAjzQpIyz5+WiJY7LykRVE5j0LqZd6pTbjDZb pd9rwEOTLwRIhfJx4j6BWEk6UX9W/lLzJdXw6GoFdL6iw+MISXcR3NzGDLgwM4BOOGHb xvNz2wF8ho9d9GCsDmDYYE9zpQXp7GhcBuRjnzKGFuUel2UOG2iFRcjZ9fKYz+v4y1zc mhlf9+GtEqan7RxXfmjYtAiqlanCj7WfiwYVIWo+qsyNmh5KdD3Bi9kaXl+Y/OGR/XnN sr47QS1dcdJoGJnBvlzgj1kBE0LuIL361Ij294uK3Cl91EHyeHTb8WQI+4QP0DVtZvJb +VDw== 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=eVesJ8cPCjkj5eG79k6N0na8z3E+d5AAUAYTSPL1o0M=; b=hdu+AmLWNOD3Fz0T5iDzeNMsJ4hxFbbpymH486jias5RCwo1InaxAqce5JB4BiC1Jv 5ADp1XTtVNgOXaDMHR/adDQ9ny4bkaQ4rHG/H1t3vpZvWreNl4iaCo2egp4Wv5n6ca9m eMxYEy7MfgGiBriOcHAUJs521aHh9kXyiJV3y1wgXTfG1PuuDeOJFXWd9deef15RzTZo b5W6NQk+M2ZkbwqDgx+qMVOrOkSnuBOlWOCjIBsG/ejbJn8lf5jvYmnT1dkvgRBcTFRA EqOVaCHla5tlyK9WNzgzKAE9ztkmP9vXc0N9wKvXUkLqmMiVGm2zdjIF8KeF4lv84LeE F1ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QU8rTwEO; 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 w14si7401513ede.41.2020.05.30.08.08.54; Sat, 30 May 2020 08:09:31 -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=QU8rTwEO; 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 S1728989AbgE3PHw (ORCPT + 99 others); Sat, 30 May 2020 11:07:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:51698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728927AbgE3PHv (ORCPT ); Sat, 30 May 2020 11:07:51 -0400 Received: from localhost (unknown [104.132.1.66]) (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 0848E20715; Sat, 30 May 2020 15:07:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590851271; bh=VFC2e2QDPFdOJxydI3qWtpXTrKif7HwS+5L0IvnfvA0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QU8rTwEO5UY8g832e8Juk2CySLLj8tTS0HmL+BgnaqGyakKYO97n+mG84Saq0PngC /WZEjiLYtZ1/USS/PLqjOliTkCoDlk+W0hOmpe28n4Lqhlz5N7ZhIfkOqWp0Z67lBF XwZdlN/y1PeZAE7UNpeDCouJg7qdIcMa8qkvHYTA= Date: Sat, 30 May 2020 08:07:50 -0700 From: Jaegeuk Kim To: Eric Biggers Cc: linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Al Viro , Daniel Rosenberg , Gabriel Krisman Bertazi Subject: Re: [PATCH] f2fs: avoid utf8_strncasecmp() with unstable name Message-ID: <20200530150750.GA184700@google.com> References: <20200530060418.221707-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200530060418.221707-1-ebiggers@kernel.org> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On 05/29, Eric Biggers wrote: > From: Eric Biggers > > If the dentry name passed to ->d_compare() fits in dentry::d_iname, then > it may be concurrently modified by a rename. This can cause undefined > behavior (possibly out-of-bounds memory accesses or crashes) in > utf8_strncasecmp(), since fs/unicode/ isn't written to handle strings > that may be concurrently modified. > > Fix this by first copying the filename to a stack buffer if needed. > This way we get a stable snapshot of the filename. > > Fixes: 2c2eb7a300cd ("f2fs: Support case-insensitive file name lookups") > Cc: # v5.4+ > Cc: Al Viro > Cc: Daniel Rosenberg > Cc: Gabriel Krisman Bertazi > Signed-off-by: Eric Biggers Acked-by: Jaegeuk Kim > --- > fs/f2fs/dir.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c > index 44bfc464df787..5c179b72eb8a8 100644 > --- a/fs/f2fs/dir.c > +++ b/fs/f2fs/dir.c > @@ -1083,6 +1083,7 @@ static int f2fs_d_compare(const struct dentry *dentry, unsigned int len, > struct qstr qstr = {.name = str, .len = len }; > const struct dentry *parent = READ_ONCE(dentry->d_parent); > const struct inode *inode = READ_ONCE(parent->d_inode); > + char strbuf[DNAME_INLINE_LEN]; > > if (!inode || !IS_CASEFOLDED(inode)) { > if (len != name->len) > @@ -1090,6 +1091,22 @@ static int f2fs_d_compare(const struct dentry *dentry, unsigned int len, > return memcmp(str, name->name, len); > } > > + /* > + * 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; > + } > + > return f2fs_ci_compare(inode, name, &qstr, false); > } > > -- > 2.26.2