From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63611C433E0 for ; Sat, 30 May 2020 15:08:09 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2EDC220715; Sat, 30 May 2020 15:08:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="c1kBgkdh"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="CuxxQrMZ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="QU8rTwEO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2EDC220715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jf35j-0001Gs-S8; Sat, 30 May 2020 15:08:07 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jf35j-0001Gl-EP for linux-f2fs-devel@lists.sourceforge.net; Sat, 30 May 2020 15:08:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=eVesJ8cPCjkj5eG79k6N0na8z3E+d5AAUAYTSPL1o0M=; b=c1kBgkdhg5Nk1hM1LNJFIC7jk+ fk/IRpFweqUjgjK1iLnJ6s5PqaYOpqHmVRrptm2xR4Y0DRVGn2bQ6OxK8Gpkee6dsIOZQf9RwmjLp KwbRastkrHdiibrS9TdvWhRXB/Q2DzDhdzhEUbSSYE6Gc7eAOFnUXerCimAff56KO2Kc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=eVesJ8cPCjkj5eG79k6N0na8z3E+d5AAUAYTSPL1o0M=; b=CuxxQrMZKpHfFYs0/yqDd6KZ7k k4122BlPxy1LRcd3vIm2LZjfimEo3heKl22i1bgldD2gYgcKPbJOU3h6xS77aQ92XPX4Oz/1eoEvd QGg/Fc+3hzAcnGLxRKz+vPOQWQPCYAqlRZxQ7m2wq99oUE6sVP/NWLLOVN8jAOjbusC8=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jf35f-00120r-Tl for linux-f2fs-devel@lists.sourceforge.net; Sat, 30 May 2020 15:08:07 +0000 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 Message-ID: <20200530150750.GA184700@google.com> References: <20200530060418.221707-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200530060418.221707-1-ebiggers@kernel.org> X-Headers-End: 1jf35f-00120r-Tl Subject: Re: [f2fs-dev] [PATCH] f2fs: avoid utf8_strncasecmp() with unstable name X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Rosenberg , stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Al Viro , linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Gabriel Krisman Bertazi Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel