Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1189143rdb; Fri, 19 Jan 2024 10:48:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4Qfi6tRZJleNmPTRUrQ1Qkgd0/rXGw6LDqclj/OXgeZFKKkkCi9GJ+xaVsUG22z0v7aGB X-Received: by 2002:a05:6e02:1a8d:b0:360:fe84:1ee9 with SMTP id k13-20020a056e021a8d00b00360fe841ee9mr253929ilv.120.1705690115055; Fri, 19 Jan 2024 10:48:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705690115; cv=pass; d=google.com; s=arc-20160816; b=sIirGCkZdT8qwPciFiUxJAgUiS2QAb3HvC13I2UC1YnmaFsha1i4nciIA7/ikC2iGh oHpBKOiT8MjzEkXsf7tcvuFVmyxXIyTFjUMGGu7B3p9yJGi4TZtcUu72ImgBLCA0ttkI kWiTwr8X5YWcqmcqBtyjqp49HLJ8nszwyiJvdGOKK4pfzvmY2yFVo6H63LjrPOmGWcRl U7NsrudrqZ7QMD4TbCgemL1V7IqiPRajVT4zIs8n3OCNROJHItewfajVgBu4TmCQmGzA OMSvSOPs7J0j/4sPYVu0rLmsPNeEbpSpBC6W45gcz7JS5BQgWLkvs910A74uq3KwkF/v AY7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=noWIkV7tDOxT+ahoicDZr82jxDDniPzXUm/ClBuwL34=; fh=TR5Gg30v3tsunp9zlnj9BCAk32Yv/gHGLFfg9mPqX30=; b=N94CYGD43b90FgqNGSVGLHvVXm/wdgJprFWGgAip8AAUG5QbQbt2JsAataJD4WIOn2 ryoUke9VOgzK/Tos4jRjJIbJJZcUCO+cIhrw5u2fxLhdnUDhHBiPojXkf2uhyMxB/rOh ErjcJeMjzbUV6wFPwj5mOUgrfyvlBN+uVs8NmHRigutdfKtsORV/RWmfha79DNwqOpep IUUNy3DJgTtyrXAr8zAMh5TLmzgEJ7iex70YYL3tshvp4XzeAI48v+9L7ckltWSEswKX DprMlI2srMVBv5O/UqKJXW82v4QbH78iD8KGWogAa9qF/Fhs9+kcQmIjIxX31bmTRMEd UK1g== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id w24-20020a63fb58000000b005c1c489bfc6si3735356pgj.627.2024.01.19.10.48.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 10:48:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DC76EB227E4 for ; Fri, 19 Jan 2024 18:48:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 816AE5644C; Fri, 19 Jan 2024 18:47:58 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE3181E4A4; Fri, 19 Jan 2024 18:47:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705690078; cv=none; b=Iua9djba8xfpSLy0/NRM798iVVPjKSBHyt/dDpA7pHKS786ESOOyZh5oWhUThCAKs5qLBG1SOkrvkSgvZeCACthctw0njZBMoEi81Xs5zl4hvHFFYCALZPUWfikdm6O9rt3k3cdsVlkz4PJxYhMplLLWaw7pBdPE9VSSeolHPa0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705690078; c=relaxed/simple; bh=X5Jgt+N6ji2u24/9He1pGbDjBEc3M4jXNPgutqt9npo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t6SL1tsrQluBVu9i6qfIQCn9h0q1E8kPDqmxH6iTeDM34+mKlRavE9ONhGwB3Zc5kL8aZzcmZptWe5K+nEuIimjtXg64iv/JDau28H6++45Hi1282w1gQet8DwfyJxRkQO77KJZ5XlsGXUeYugqgIqG5lIDGmzBoQtjpwg23yZ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 11E241F809; Fri, 19 Jan 2024 18:47:55 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 92474136F5; Fri, 19 Jan 2024 18:47:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id YGWeEdrDqmU8DAAAD6G6ig (envelope-from ); Fri, 19 Jan 2024 18:47:54 +0000 From: Gabriel Krisman Bertazi To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org, tytso@mit.edu Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, amir73il@gmail.com, Gabriel Krisman Bertazi Subject: [PATCH v3 01/10] ovl: Reject mounting case-insensitive filesystems Date: Fri, 19 Jan 2024 15:47:33 -0300 Message-ID: <20240119184742.31088-2-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119184742.31088-1-krisman@suse.de> References: <20240119184742.31088-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 11E241F809 X-Spam-Flag: NO overlayfs relies on the filesystem setting DCACHE_OP_HASH or DCACHE_OP_COMPARE to reject mounting over case-insensitive directories. Since commit bb9cd9106b22 ("fscrypt: Have filesystems handle their d_ops"), we set ->d_op through a hook in ->d_lookup, which means the root dentry won't have them, causing the mount to accidentally succeed. In v6.7-rc7, the following sequence will succeed to mount, but any dentry other than the root dentry will be a "weird" dentry to ovl and fail with EREMOTE. mkfs.ext4 -O casefold lower.img mount -O loop lower.img lower mount -t overlay -o lowerdir=lower,upperdir=upper,workdir=work ovl /mnt Mounting on a subdirectory fails, as expected, because DCACHE_OP_HASH and DCACHE_OP_COMPARE are properly set by ->lookup. Fix by explicitly rejecting superblocks that allow case-insensitive dentries. While there, re-sort the entries to have more descriptive error messages first. Fixes: bb9cd9106b22 ("fscrypt: Have filesystems handle their d_ops") Signed-off-by: Gabriel Krisman Bertazi Acked-by: Amir Goldstein --- changes since v2: - Re-sort checks to trigger more descriptive error messages first (Amir) - Add code comment (Amir) --- fs/overlayfs/params.c | 13 ++++++++++--- include/linux/fs.h | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c index 3fe2dde1598f..09a4973f26f9 100644 --- a/fs/overlayfs/params.c +++ b/fs/overlayfs/params.c @@ -280,12 +280,19 @@ static int ovl_mount_dir_check(struct fs_context *fc, const struct path *path, { struct ovl_fs_context *ctx = fc->fs_private; - if (ovl_dentry_weird(path->dentry)) - return invalfc(fc, "filesystem on %s not supported", name); - if (!d_is_dir(path->dentry)) return invalfc(fc, "%s is not a directory", name); + /* + * Root dentries of case-insensitive filesystems might not have + * the dentry operations set, but still be incompatible with + * overlayfs. Check explicitly to prevent post-mount failures. + */ + if (sb_has_encoding(path->mnt->mnt_sb)) + return invalfc(fc, "case-insensitive filesystem on %s not supported", name); + + if (ovl_dentry_weird(path->dentry)) + return invalfc(fc, "filesystem on %s not supported", name); /* * Check whether upper path is read-only here to report failures diff --git a/include/linux/fs.h b/include/linux/fs.h index 98b7a7a8c42e..e6667ece5e64 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3203,6 +3203,15 @@ extern int generic_check_addressable(unsigned, u64); extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); +static inline bool sb_has_encoding(const struct super_block *sb) +{ +#if IS_ENABLED(CONFIG_UNICODE) + return !!sb->s_encoding; +#else + return false; +#endif +} + int may_setattr(struct mnt_idmap *idmap, struct inode *inode, unsigned int ia_valid); int setattr_prepare(struct mnt_idmap *, struct dentry *, struct iattr *); -- 2.43.0