All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Linus Torvalds <torvalds@linuxfoundation.org>
Cc: "Darrick J. Wong" <djwong@kernel.org>,
	"Josef Bacik" <josef@toxicpanda.com>,
	ansgar.loesser@kom.tu-darmstadt.de,
	"Christoph Hellwig" <hch@lst.de>,
	"Amir Goldstein" <amir73il@gmail.com>,
	"Mark Fasheh" <mark@fasheh.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Miklos Szeredi" <mszeredi@redhat.com>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	"Security Officers" <security@kernel.org>,
	"Max Schlecht" <max.schlecht@informatik.hu-berlin.de>,
	"Björn Scheuermann" <scheuermann@kom.tu-darmstadt.de>
Subject: [PATCH] fs/remap: constrain dedupe of EOF blocks
Date: Wed, 13 Jul 2022 17:49:15 +1000	[thread overview]
Message-ID: <20220713074915.GD3600936@dread.disaster.area> (raw)
In-Reply-To: <20220713064631.GC3600936@dread.disaster.area>

From: Dave Chinner <dchinner@redhat.com>

If dedupe of an EOF block is not constrainted to match against only
other EOF blocks with the same EOF offset into the block, it can
match against any other block that has the same matching initial
bytes in it, even if the bytes beyond EOF in the source file do
not match.

Fix this by constraining the EOF block matching to only match
against other EOF blocks that have identical EOF offsets and data.
This allows "whole file dedupe" to continue to work without allowing
eof blocks to randomly match against partial full blocks with the
same data.

Reported-by: Ansgar Lößer <ansgar.loesser@tu-darmstadt.de>
Fixes: 1383a7ed6749 ("vfs: check file ranges before cloning files")
Link: https://lore.kernel.org/linux-fsdevel/a7c93559-4ba1-df2f-7a85-55a143696405@tu-darmstadt.de/
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---

This is tested against the case provided in the initial report. Old
kernel:

$ ./dedupe.sh |less
secret
$

Patched kernel:

$ ./dedupe.sh
dedupe-bug: t.c:90: main: Assertion `status != FILE_DEDUPE_RANGE_DIFFERS' failed.
./dedupe.sh: line 11:  4831 Aborted /home/dave/dedupe-bug $MNT/writeonly.txt $MNT/test.tmp
$

So now it fails with FILE_DEDUPE_RANGE_DIFFERS because it can't use
short files to discover the dedupe character match one byte at a
time.

It also passes fstests ismoke tests via running the './check -g
dedupe' test group, so the fix doesn't obviously break anything.

 fs/remap_range.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/remap_range.c b/fs/remap_range.c
index e112b5424cdb..881a306ee247 100644
--- a/fs/remap_range.c
+++ b/fs/remap_range.c
@@ -71,7 +71,8 @@ static int generic_remap_checks(struct file *file_in, loff_t pos_in,
 	 * Otherwise, make sure the count is also block-aligned, having
 	 * already confirmed the starting offsets' block alignment.
 	 */
-	if (pos_in + count == size_in) {
+	if (pos_in + count == size_in &&
+	    (!(remap_flags & REMAP_FILE_DEDUP) || pos_out + count == size_out)) {
 		bcount = ALIGN(size_in, bs) - pos_in;
 	} else {
 		if (!IS_ALIGNED(count, bs))

  reply	other threads:[~2022-07-13  7:49 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 12:11 Information Leak: FIDEDUPERANGE ioctl allows reading writeonly files Ansgar Lößer
2022-07-12 17:33 ` Linus Torvalds
2022-07-12 18:43   ` Matthew Wilcox
2022-07-12 18:47     ` Linus Torvalds
2022-07-12 18:51       ` Linus Torvalds
2022-07-12 19:02   ` Josef Bacik
2022-07-12 19:07     ` Linus Torvalds
2022-07-12 19:23       ` Linus Torvalds
2022-07-12 20:03       ` Josef Bacik
2022-07-12 20:48         ` Linus Torvalds
2022-07-13  0:48           ` Darrick J. Wong
2022-07-13  2:58             ` Linus Torvalds
2022-07-13  4:14               ` Linus Torvalds
2022-07-13  6:46               ` Dave Chinner
2022-07-13  7:49                 ` Dave Chinner [this message]
2022-07-13  8:19                   ` [PATCH] fs/remap: constrain dedupe of EOF blocks Linus Torvalds
2022-07-13 17:18                   ` Ansgar Lößer
2022-07-13 17:26                     ` Linus Torvalds
2022-07-13 18:51                       ` [PATCH] vf/remap: return the amount of bytes actually deduplicated Ansgar Lößer
2022-07-13 19:09                         ` Linus Torvalds
2022-07-14  0:22                         ` Dave Chinner
2022-07-14  1:03                           ` Linus Torvalds
2022-07-16 21:15                           ` Mark Fasheh
2022-07-14 22:32                         ` Dave Chinner
2022-07-14 22:42                           ` Linus Torvalds
2022-07-14 23:15                             ` Dave Chinner
2022-07-13  8:16                 ` Information Leak: FIDEDUPERANGE ioctl allows reading writeonly files Linus Torvalds
2022-07-13 23:48                   ` Dave Chinner
2022-07-13 17:17                 ` Ansgar Lößer
2022-07-13 17:16             ` Ansgar Lößer
2022-07-13 22:43               ` Dave Chinner
2022-07-13 17:14   ` Ansgar Lößer
2022-07-13 18:03     ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220713074915.GD3600936@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=amir73il@gmail.com \
    --cc=ansgar.loesser@kom.tu-darmstadt.de \
    --cc=djwong@kernel.org \
    --cc=hch@lst.de \
    --cc=josef@toxicpanda.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mark@fasheh.com \
    --cc=max.schlecht@informatik.hu-berlin.de \
    --cc=mszeredi@redhat.com \
    --cc=scheuermann@kom.tu-darmstadt.de \
    --cc=security@kernel.org \
    --cc=torvalds@linuxfoundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.