Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2494831rdb; Wed, 21 Feb 2024 09:14:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVByTskDhd24oe9TUXnqewXb/xB22H6O0Z3FdsQLCzWG+DjA613C5UW7c01G0EDJSUh9G55BXy0+Ix7PPpW3fTRJ+GswXhDaUEX7k1ruw== X-Google-Smtp-Source: AGHT+IEqje5jDPEpDgDnJbB7fs245hfmzk8Dm2xp+yPWMBSjsUsaYmaCj5XOA7ydWg7KceGg3L2J X-Received: by 2002:a05:6808:201f:b0:3c1:5749:d9ae with SMTP id q31-20020a056808201f00b003c15749d9aemr9973756oiw.33.1708535675190; Wed, 21 Feb 2024 09:14:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708535675; cv=pass; d=google.com; s=arc-20160816; b=u/TEJ8++fa2dyzKKXOKCyoyN44yZwO71BkH4DT1SkCejRGX0zY5bdTXwaLmfJgmDu/ 61ZadOLfOqKjsnxRuL89HpdBf189yg/AcaWLGyp2zo0VgOsLPrPkMEZEIBJPbU6bo3wg vuA1H5cwyERTYYZGDkr6CkhzVsULId5hwN4Tq3QsU1WnvmS9d9fxc+ivsysObTDya1Fr rKYILM+sF0Xh/KhuS6PZ53MMWkempldAWGXJ6EV3XP0dns8x2sI3h/cQ6WRFx6xSdKd6 O3uK4HnM94S3Yt5KVZqXNJqsQzd1AxrVEaa7fe6CBa0FyX9KvoydcbyJJrB8xDDe/FH+ tAKA== 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:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=D59OP2BUYYvV4JTaStIU9zARbS/Uaxo74njoDI27EFI=; fh=8tdzVCq0eMaTapAm4yEzDtdxr6Vp38VIgLMUbBssKM0=; b=GOg/g6x4uByvmNXxzcN1NiG0AQxaE8JXF2sUZdiOqS2TR3wshCgY+MFWlLw3S8ixZl hD1KqQKTaZqoU63DNaagcuXYIGIA308FntsPOncVcSt+ic32i+TbcKyyHLtQgJvkLuTI EO3IbhewxdDIHbbXJYlewILpHOqCeQ3hPBM2+wKYl2t+IzHU/uc0fip7Yowt7Nt4sdoY s0LO0yyqxZmb5WepfCmsJAqGNh4zr9AReajGkBurjcSBB+Wlh751P/TWdcRqgC70s+DZ 2HAD/5yhYCo8KDENxfAO8dRkWYo+Q5gSe8TSmh/YVO4V1bE5SWu86HnPktunUNCsYYAE //cQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fxGinss5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fxGinss5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-1342-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1342-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t4-20020ad45bc4000000b0068f6f85b1e2si7086596qvt.543.2024.02.21.09.14.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 09:14:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1342-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fxGinss5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fxGinss5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-1342-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1342-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (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 ny.mirrors.kernel.org (Postfix) with ESMTPS id DBAB21C22A20 for ; Wed, 21 Feb 2024 17:14:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1648D83CB7; Wed, 21 Feb 2024 17:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fxGinss5"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="L0SSkGuk"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fxGinss5"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="L0SSkGuk" 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 7314982D9E; Wed, 21 Feb 2024 17:14:22 +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=1708535664; cv=none; b=huhOpkFtngc8zgjDKYBxvYYnRyWSrRVWzCxMWTIrvnf2ce0JCAjs5axeK9Wo6KfVusPZUpY3/x+Uv0lwq5D0JdmpPAMydXPlLU7K6Vt+9ut/+SuoRHLxMLHWrvpDu4SfyBt7jcsQf0Pqaz+j99JxVJjUwc+JA3OL2ZOlJALi6Uw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708535664; c=relaxed/simple; bh=7+dsiojWXQnyMkcnZ66iDi2GpW5QMmMk/n+bMml/AvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lk3+brv8H4v+YBRuFlLzqjC2EUuuAhqDKocGehKK4VuDuAnhBleFzL/TIreRoqTRwZeEH5gV2aX8IwyH1ELw++vEA/9eJqxYuH3lRWgK4JQQQ49OA/5I0vTGNE0s3priQqnTSr1k+K//+rDSjfOINMLU9vRRv/LFyEwtcv36teg= 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; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fxGinss5; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=L0SSkGuk; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fxGinss5; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=L0SSkGuk; 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 [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 8CCBB1FB68; Wed, 21 Feb 2024 17:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708535660; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D59OP2BUYYvV4JTaStIU9zARbS/Uaxo74njoDI27EFI=; b=fxGinss5NOrVv11Xxz6pbfMVuP6wfziqwx7CBwFH8PN8T+8/D1BhanxmKWrY5nhe/R+XuP Mvh9UgRKc7n6URmqGV+VnEsfXqyEW78KYP+6F2i6bR199jU1tP4EvTiZruTJyH8HstpS7U gbqwUZwAraX29EKg/ivVETAJ9D79+mg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708535660; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D59OP2BUYYvV4JTaStIU9zARbS/Uaxo74njoDI27EFI=; b=L0SSkGuk7siARVi7AITudvHVAfNU0ePPtfeg67WVfm7wge6+mgskltRm2hE5jQOufq5npz TQYlUnGwxzygrtBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708535660; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D59OP2BUYYvV4JTaStIU9zARbS/Uaxo74njoDI27EFI=; b=fxGinss5NOrVv11Xxz6pbfMVuP6wfziqwx7CBwFH8PN8T+8/D1BhanxmKWrY5nhe/R+XuP Mvh9UgRKc7n6URmqGV+VnEsfXqyEW78KYP+6F2i6bR199jU1tP4EvTiZruTJyH8HstpS7U gbqwUZwAraX29EKg/ivVETAJ9D79+mg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708535660; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D59OP2BUYYvV4JTaStIU9zARbS/Uaxo74njoDI27EFI=; b=L0SSkGuk7siARVi7AITudvHVAfNU0ePPtfeg67WVfm7wge6+mgskltRm2hE5jQOufq5npz TQYlUnGwxzygrtBg== 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 4EC56139D0; Wed, 21 Feb 2024 17:14:20 +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 pj7WDGwv1mVQKgAAD6G6ig (envelope-from ); Wed, 21 Feb 2024 17:14:20 +0000 From: Gabriel Krisman Bertazi To: ebiggers@kernel.org, viro@zeniv.linux.org.uk, jaegeuk@kernel.org Cc: tytso@mit.edu, amir73il@gmail.com, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, brauner@kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v7 01/10] ovl: Always reject mounting over case-insensitive directories Date: Wed, 21 Feb 2024 12:14:03 -0500 Message-ID: <20240221171412.10710-2-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240221171412.10710-1-krisman@suse.de> References: <20240221171412.10710-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 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[10]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[mit.edu,gmail.com,vger.kernel.org,lists.sourceforge.net,kernel.org,suse.de]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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. Yes, this will be solved when we move d_op configuration back to ->s_d_op. Yet, we better have an explicit fix to avoid messing up again. 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 v5: - summary line again (eric) changes since v3: - Case insensitive filesystem ->Case insensitive capable filesystem (eric) - clarify patch summary line changes since v2: - Re-sort checks to trigger more descriptive error messages first (Amir) - Add code comment (Amir) --- fs/overlayfs/params.c | 14 +++++++++++--- include/linux/fs.h | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c index 3fe2dde1598f..488f920f79d2 100644 --- a/fs/overlayfs/params.c +++ b/fs/overlayfs/params.c @@ -280,12 +280,20 @@ 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 capable 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 capable 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