From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 D95513F4831 for ; Mon, 27 Jul 2026 10:48:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785149337; cv=none; b=mETWkV/22wW3E24Fjwdc6jalqFRdHPs2dY8me4xlRsSi45Y9fwnUMWT11sZmWfi/cImQ6KCLrrB5IGOPCL8qwWP4NAc5IFEO1qY9tHep16d5xkLS57J/lYjkIBGGTSy2wLmKrGMFYWNTXkH5re+KcnhSw5qnt+CnOp4kNv0pnPE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785149337; c=relaxed/simple; bh=eCRRircvREoM/iKBqnGOOGYYVHjFVnNml43mqCwm7tk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=etQD5XovqFRXoNQPnWxg6hesQOwdgLzE76unJQoWp9ABoLTwwGUBOGswhaVXlGeJBGl0s4ji+hRNfQTOX8ebPpzkMoYYzg0YHFVlkP/ORPBPzOg/ndWMOUI8YYBvJ4nVlLwjD4HVB9+1Z6vtZpTgkLlirV75kloO6Z4+Zwo6I/o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EUXDxWwa; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EUXDxWwa" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-47f97d310caso1757769f8f.2 for ; Mon, 27 Jul 2026 03:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785149331; x=1785754131; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=neqsEsWHuKT6LwcChvXBKjF2Wl4AED5GjZjnD9EI9lc=; b=EUXDxWwazk3tKbvGSvIdU9cWxFMs+nCf5sAAshNj4rtn8uuQ3KjX/e8yHjs7+6a1nv 5p6N+oom3WpzziIXpUt+NRZfD6XvbdnyKsBS27dhLTkJJMbaJMD9Ut2exU/QiqaoX+lf cQ7/69yAK3Gu0QjMInD/VQ9YecbxRzJ2svxvUS0RINi9Yxxr1+ypBaBXkeQQ86pyUl+X UDk8b1c1hwvZh6ly2a0aZIkcK1qCaS9nMTT3GSwdBBT9iK6/mdVgjcYLxRGx6nlSG2gr 6nuXltQg9SlIB8azAKM2bcfW4BstigHyZA2sE2OzK+ZIsnWrVYmltRA21bGzrhkg+eSN L3Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785149331; x=1785754131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=neqsEsWHuKT6LwcChvXBKjF2Wl4AED5GjZjnD9EI9lc=; b=EpYfqY2BoYblReOzg2h8uog8EOFjeiH0XH1Xiia9LDNbHd3rl6eWbwMXIq9jGXAR9H HceQ6hPSlmDJp0uK9ZQ85DZ7cONU9LgmtHCpiD8zYuZXsEBF1hIdKxFCPRSFfamCD417 Ve/Mb2OaDTwM/BdjO6NLy8Zta9XFc68pknPAM0YBPhDaagm1SJOa+45wVBmnWStxCj6C s5UzfK0S99zhzmswyICpkDluNdV//Tt94G3BZ25DAtFVfp7/J0w+PqTzuFlHXIxydowC G8/nTzXB8PNUjxX6LuixpiebKyDWhYYeLtfUhiDPdgUW4ZGLy4CzHUABGq7rTisxMx5b aZjQ== X-Forwarded-Encrypted: i=1; AHgh+RoZBab6ldZHCpime1NqAk01LLzySscoAkAzus90acjUoEOdphzQ6I3W+398VZ5d9iiPDy71QUi8xqtCDAY=@vger.kernel.org X-Gm-Message-State: AOJu0YxhnFV7ydmsFBsw2LpjB6l5bcN03GXfFSKb6lb5MsLdGIujPC9J 6r4RQFiQlD5i8vHAKt3y7/Ll/fqhWAzxSF+VN0eOiktZj6unYMtq1Iyb X-Gm-Gg: AR+sD133TUYVlAttHWhQTb93eyynTTv/WUt8lnwzVKO0cMpJccPNfV8tvmYCeVmeqk+ DQs7eQV1NLCBWmLxU93kBoBnKSgwqXelo96qLAmVUGYviObMQLIrlX5PW1EE7xGy7tK0vNIj2Y3 H5ovQ9W6rWJSl+PWwxPPyBkY07FI2fjWoTTMwlrEW7qnDGYBm8R5YfCgBTe6qyhch+5XVGsMdCw oO3zxijptDrVrt044TeXGnQqu+WaVzImDc+QqI9+RMMqhth/oSZkYHeXY0VsjAi2I0V2IisCWYC ddJRoKIGRrOLkbcA8onGHD7dJ2NBKtbyHDiLyV2qtsLNJg29QmBAXPCeheDKWrfFnsKrgpZeJ+M ZOQeheg1SFEJN+9UzFG96+Jw8FYwzCxvb77pfZ6kkPDRgucpY7GK7CiIeYdFNaIjZ9CYtgM25hk tsl4sDDQ== X-Received: by 2002:a5d:5d09:0:b0:472:7dce:d8c7 with SMTP id ffacd0b85a97d-47f9fe9e8bbmr10201283f8f.36.1785149330834; Mon, 27 Jul 2026 03:48:50 -0700 (PDT) Received: from spark.Home ([2001:8a0:7280:4000:53fe:effd:424:fa7e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85b9a659sm49056188f8f.6.2026.07.27.03.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2026 03:48:49 -0700 (PDT) From: Eric Curtin To: Alexander Viro , Christian Brauner Cc: Jan Kara , Jonathan Corbet , Shuah Khan , Eric Biggers , "Theodore Y . Ts'o" , Gao Xiang , Chao Yu , fsverity@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Curtin Subject: [RFC PATCH v2 2/4] erofs: use fs_context source_file for file-backed mounts when given Date: Mon, 27 Jul 2026 11:48:43 +0100 Message-ID: <20260727104845.2607444-3-ericcurtin17@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260727-gepaukt-eislauf-waran-7c03f0e47609@brauner> References: <20260727-gepaukt-eislauf-waran-7c03f0e47609@brauner> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit erofs_fc_get_tree() falls back to filp_open(fc->source, ...) itself when get_tree_bdev_flags() reports the source isn't a block device. That is the only way to reach erofs's file-backed mount support today, which means an in-kernel caller that already opened and validated (e.g. fsverity-checked) that exact file has no way to make erofs mount it: it can only hand over the path again and trust erofs's independent lookup to land on the same file, which it has no way to guarantee. Check fc->source_file first and use it directly when set, taking a reference and skipping the independent filp_open(fc->source) entirely (fc->source is unset in this case). This has no effect on the existing path-based fsconfig()/mount(2) flow, since userspace has no way to set fc->source_file (see the previous patch); it only enables in-kernel callers such as the following init/do_mounts.c change. Signed-off-by: Eric Curtin --- fs/erofs/super.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 802add6652fd..b6cd4fde3ca2 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -799,6 +799,25 @@ static int erofs_fc_get_tree(struct fs_context *fc) if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid) return get_tree_nodev(fc, erofs_fc_fill_super); + /* + * An in-kernel caller (see path_mount_file()) has handed us the + * exact, already-open file to mount, rather than a path for us to + * resolve ourselves: use it directly instead of independently + * re-opening fc->source (which isn't set in this case), so that + * whatever the caller validated about this file - e.g. an fsverity + * digest - is guaranteed to still apply to what actually gets + * mounted. + */ + if (fc->source_file) { + if (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE)) + return invalf(fc, "File-backed mounts not supported"); + if (!S_ISREG(file_inode(fc->source_file)->i_mode) || + !fc->source_file->f_mapping->a_ops->read_folio) + return invalf(fc, "Source file is not a plain, read-foliable file"); + sbi->dif0.file = get_file(fc->source_file); + return get_tree_nodev(fc, erofs_fc_fill_super); + } + ret = get_tree_bdev_flags(fc, erofs_fc_fill_super, IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) ? GET_TREE_BDEV_QUIET_LOOKUP : 0); -- 2.43.0