Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2113261pxb; Sun, 18 Apr 2021 19:30:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBcqx8u8lwhRay9K71LpoxEOeutMyR/hC6UeLCgrah+Xg2mOiiW8VyHLACNMZAinHHUHb3 X-Received: by 2002:a17:907:94ca:: with SMTP id dn10mr19432188ejc.123.1618799435085; Sun, 18 Apr 2021 19:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618799435; cv=none; d=google.com; s=arc-20160816; b=syFF3dAuj6f0bcLCy84Z6pEeNIkXoTaHblwDjR6oqBsbZhlxY07sDpxxOYiqbEWPxE Jm0In26DloJa+ou0w6j6iKa/Q2sBkTGjKk7v2mTAyPpnkUF/+RwuALax1kWxnGD75AtK bKrDDqLT+/obukxXI0aFZwtkqQNqEYEYfJs7E4I0jn6f1A9cY9CkE2GqRxfQ+4Q3231Z lIv67jLAGwZGSO5PZooKktbrxcCNxgEacKtuzdCMmvGQ1UXcPOxGvQjqqFvx71HOmDxa LO0+ji+RLTqy3eraStztkkQlzuP1v8oqHNXpzCIqzQ1zbN6OfsIcKeFC7+KtWV4vneLd Go3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=bZBVykDy+CbPTq5GPknPQk24ko2Dt8qX06614cxzmoI=; b=uAwz0H17RihK9Hl60NjbSq2iTyj/zNtZ6G8V+1fekqNV7adY9OnVNTNOzt0+3CsdmO ELbUYweTgI+mPr9K0XhIOGjqKcQeUfGBM4QWYFlwDuVmRKcklDJZ/K9poqIw6tD0TQEv B9S6CIv2cA4QzA57sFsNbWRiez81c8jSOd/wz5sQ06v7ax6EReU18Mu8gu8bMIXW5dsG M8XaoKUasNHMvCdF7NHE9huootnxBgUaU3AegozFo3x1cJAyAninD+mMHINQHt9FZ1rE 6oikV0HDGZ6JFpbkh1QgnwTTO3EwPZY8Lq1K660mj/PpP2f+0unY33afraPTAWIRbGjm OPjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pmOjuCDa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h13si10889921edt.586.2021.04.18.19.30.10; Sun, 18 Apr 2021 19:30:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@gmail.com header.s=20161025 header.b=pmOjuCDa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233193AbhDSC3j (ORCPT + 99 others); Sun, 18 Apr 2021 22:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbhDSC3i (ORCPT ); Sun, 18 Apr 2021 22:29:38 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6445C06174A; Sun, 18 Apr 2021 19:29:06 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id u15so8351380plf.10; Sun, 18 Apr 2021 19:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bZBVykDy+CbPTq5GPknPQk24ko2Dt8qX06614cxzmoI=; b=pmOjuCDaegOlVXpSgl1lzwSoy//PLBynAvQROra5Oj+O22sUO/1R5ycoyKKiF0V3C9 3cG7pYApIKJpVSz66o01Dn1nKPSDprDCEp1rjmpistU0lbm7sSEExqWEnHXAXvDr5GQB vpPNBJzOPtBcZM/ga3gOacb4x4P2q0KEDP2Cl0kUPzBLMowa1ezLGXx9ZQGFZeAWbJb5 T47V266bPzWsj8bXT91/13X/9XnzhLUosgMO9pwKbyNvRiEFZdwQYKkB2M2BeGoOHLER IbdI2SOE0/MFcN2o5kzd/gkBdNTrATab1XEXYF1JxC1cOk7rkH4ofTKM7RJlCNEui6Tu +v/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bZBVykDy+CbPTq5GPknPQk24ko2Dt8qX06614cxzmoI=; b=ge8tnq5sUSfPY/ZZKDO8HYEogHwIT9+mpmDJoOUuVI0TDukqIrbMQzxiDZls2FuUqq Aekp0L+JaPQPKDrHeEFgb1MoQnu7zK2c8kIe/pEpj1/56GWvB0PmHqHdr8in517X0CeT RciL3bl6I+c8hMpsB/izRaYgn6KlhQoksC0+yp7T5q1rEtzqqxZrEYDCTcZ32ddTwoSS qiWUD30tfrEzO5VCFMu7SemnKDbaoaVcdmhkqtw7eFNZN7KjUUt1z2SUedjoJXxzYtgm 0NAojdHE7VP5sNCA42yUKnLQ6o8RBR7yPMBPLNEGzKiCdHNUZ6/0rcZ+JWlPmMcahARz LK0Q== X-Gm-Message-State: AOAM530CvkGXFfXEHwp35nUQ0nkrFWFPy4VYmCv77EFGSfkiThFaCzwz +94XrUjM89nnq83JBOtsSNA= X-Received: by 2002:a17:90a:a389:: with SMTP id x9mr21888444pjp.232.1618799346177; Sun, 18 Apr 2021 19:29:06 -0700 (PDT) Received: from localhost.localdomain (220-130-175-235.HINET-IP.hinet.net. [220.130.175.235]) by smtp.gmail.com with ESMTPSA id lt11sm12577277pjb.23.2021.04.18.19.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 19:29:05 -0700 (PDT) From: Chung-Chiang Cheng X-Google-Original-From: Chung-Chiang Cheng To: gustavoars@kernel.org, christian.brauner@ubuntu.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: cccheng@synology.com Subject: [PATCH v2] hfsplus: prevent negative dentries when casefolded Date: Mon, 19 Apr 2021 10:29:01 +0800 Message-Id: <20210419022901.193750-1-cccheng@synology.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org hfsplus uses the case-insensitive filenames by default, but VFS negative dentries are incompatible with case-insensitive. For example, the following instructions will get a cached filename 'aaa' which isn't expected. There is no such problem in macOS. touch aaa rm aaa touch AAA This patch takes the same approach to drop negative dentires as vfat does. The dentry is revalidated without blocking and storing to the dentry, and should be safe in rcu-walk. Signed-off-by: Chung-Chiang Cheng --- fs/hfsplus/hfsplus_fs.h | 1 + fs/hfsplus/inode.c | 1 + fs/hfsplus/unicode.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h index 12b20479ed2b..e4f0cdfdac96 100644 --- a/fs/hfsplus/hfsplus_fs.h +++ b/fs/hfsplus/hfsplus_fs.h @@ -528,6 +528,7 @@ int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr, int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str); int hfsplus_compare_dentry(const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name); +int hfsplus_revalidate_dentry(struct dentry *dentry, unsigned int flags); /* wrapper.c */ int hfsplus_submit_bio(struct super_block *sb, sector_t sector, void *buf, diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index 078c5c8a5156..772cad371371 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c @@ -176,6 +176,7 @@ const struct address_space_operations hfsplus_aops = { const struct dentry_operations hfsplus_dentry_operations = { .d_hash = hfsplus_hash_dentry, .d_compare = hfsplus_compare_dentry, + .d_revalidate = hfsplus_revalidate_dentry, }; static void hfsplus_get_perms(struct inode *inode, diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c index 73342c925a4b..e336631334eb 100644 --- a/fs/hfsplus/unicode.c +++ b/fs/hfsplus/unicode.c @@ -10,6 +10,7 @@ */ #include +#include #include #include "hfsplus_fs.h" #include "hfsplus_raw.h" @@ -518,3 +519,34 @@ int hfsplus_compare_dentry(const struct dentry *dentry, return 1; return 0; } + +int hfsplus_revalidate_dentry(struct dentry *dentry, unsigned int flags) +{ + /* + * dentries are always valid when disabling casefold. + */ + if (!test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(dentry->d_sb)->flags)) + return 1; + + /* + * Positive dentries are valid when enabling casefold. + * + * Note, rename() to existing directory entry will have ->d_inode, and + * will use existing name which isn't specified name by user. + * + * We may be able to drop this positive dentry here. But dropping + * positive dentry isn't good idea. So it's unsupported like + * rename("filename", "FILENAME") for now. + */ + if (d_really_is_positive(dentry)) + return 1; + + /* + * Drop the negative dentry, in order to make sure to use the case + * sensitive name which is specified by user if this is for creation. + */ + if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) + return 0; + + return 1; +} -- 2.25.1