Skip to contentSkip to conversation

fsdax: unshare: zero destination if srcmap is HOLE or UNWRITTEN

PATCH Applied Shiyang Ruan 4 participants 11 messages Mar 22, 2023 – Mar 24, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsdax: unshare: zero destination if srcmap is HOLE or UNWRITTEN

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Fixes d984648e428b ("fsdax,xfs: port unshare to fsdax")
---
 fs/dax.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
fs/dax.c +8 -3
index 9800b93ee14d..5d2e9b10030e 100644
@@ -1258,15 +1258,20 @@ static s64 dax_unshare_iter(struct iomap_iter *iter)
 	/* don't bother with blocks that are not shared to start with */
 	if (!(iomap->flags & IOMAP_F_SHARED))
 		return length;
-	/* don't bother with holes or unwritten extents */
-	if (srcmap->type == IOMAP_HOLE || srcmap->type == IOMAP_UNWRITTEN)
-		return length;
 
 	id = dax_read_lock();
 	ret = dax_iomap_direct_access(iomap, pos, length, &daddr, NULL);
 	if (ret < 0)
 		goto out_unlock;
 
+	/* zero the distance if srcmap is HOLE or UNWRITTEN */
+	if (srcmap->flags & IOMAP_F_SHARED || srcmap->type == IOMAP_UNWRITTEN) {
+		memset(daddr, 0, length);
+		dax_flush(iomap->dax_dev, daddr, length);
+		ret = length;
+		goto out_unlock;
+	}
+
 	ret = dax_iomap_direct_access(srcmap, pos, length, &saddr, NULL);
 	if (ret < 0)
 		goto out_unlock;
Signature · 1 line
2.39.2
#1 lore raw
Quoted 3 lines · On Wed, 22 Mar 2023 11:11:09 +0000 Shiyang Ruan <[email protected]> wrote:

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Please provide much more detail on the user-visible effects of the bug. For example, are we leaking kernel memory contents to userspace?

Thanks.

#2 lore raw
Quoted 8 lines · Andrew Morton
Quoted 3 lines · On Wed, 22 Mar 2023 11:11:09 +0000 Shiyang Ruan <[email protected]> wrote:

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Please provide much more detail on the user-visible effects of the bug. For example, are we leaking kernel memory contents to userspace?

This fixes fail of generic/649.

--
Thanks,
Ruan.

Quoted 4 lines

Thanks.

#3 lore raw
Quoted 5 lines · Shiyang Ruan
Quoted 2 lines · Andrew Morton

On Wed, 22 Mar 2023 11:11:09 +0000 Shiyang Ruan <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Please provide much more detail on the user-visible effects of the bug. For example, are we leaking kernel memory contents to userspace?

This fixes fail of generic/649.

Please make a note of easy(ish) reproducers when you know about them, e.g.

"Found by running generic/649 while mounting with -o dax=always on pmem."

So that anyone scanning around for fix backports has an easier time doing an A/B comparison to assess whether or not they need the fix. Especially if there's any chance that person is you circa 2024. ;)

--D

Quoted 9 lines

--
Thanks,
Ruan.

Quoted 4 lines

Thanks.

#4 lore raw
In reply to Shiyang Ruan
Quoted 5 lines · On Thu, 23 Mar 2023 14:50:38 +0800 Shiyang Ruan <[email protected]> wrote:
Quoted 2 lines · Andrew Morton

On Wed, 22 Mar 2023 11:11:09 +0000 Shiyang Ruan <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Please provide much more detail on the user-visible effects of the bug. For example, are we leaking kernel memory contents to userspace?

This fixes fail of generic/649.

OK, but this doesn't really help. I'm trying to determine whether this fix should be backported into -stable kernels and whether it should be fast-tracked into Linus's current -rc tree.

But to determine this I (and others) need to know what effect the bug has upon our users.

#5 lore raw
Quoted 14 lines · Andrew Morton
Quoted 12 lines · On Thu, 23 Mar 2023 14:50:38 +0800 Shiyang Ruan <[email protected]> wrote:
Quoted 8 lines · Andrew Morton
Quoted 3 lines · On Wed, 22 Mar 2023 11:11:09 +0000 Shiyang Ruan <[email protected]> wrote:

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Please provide much more detail on the user-visible effects of the bug. For example, are we leaking kernel memory contents to userspace?

Quoted 8 lines
Quoted 1 line

This fixes fail of generic/649.

OK, but this doesn't really help. I'm trying to determine whether this fix should be backported into -stable kernels and whether it should be fast-tracked into Linus's current -rc tree.

But to determine this I (and others) need to know what effect the bug has upon our users.

I didn't get any bug report form users. I just found this by running xfstests. The phenomenon of this problem is: if we funshare a reflinked file which contains HOLE extents, the result of the HOLE extents should be zero but actually not (unexpectable data).

The other patch also has no reports from users.

--
Thanks,
Ruan.

#6 lore raw
Quoted 23 lines · Shiyang Ruan
Quoted 20 lines · Andrew Morton
Quoted 5 lines · On Thu, 23 Mar 2023 14:50:38 +0800 Shiyang Ruan <[email protected]> wrote:
Quoted 2 lines · Andrew Morton

On Wed, 22 Mar 2023 11:11:09 +0000 Shiyang Ruan <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Please provide much more detail on the user-visible effects of the bug. For example, are we leaking kernel memory contents to userspace?

This fixes fail of generic/649.

OK, but this doesn't really help. I'm trying to determine whether this fix should be backported into -stable kernels and whether it should be fast-tracked into Linus's current -rc tree.

Quoted 7 lines
Quoted 2 lines

But to determine this I (and others) need to know what effect the bug has upon our users.

I didn't get any bug report form users. I just found this by running xfstests. The phenomenon of this problem is: if we funshare a reflinked file which contains HOLE extents, the result of the HOLE extents should be zero but actually not (unexpectable data).

You still aren't answering the question. If this did happen to a user, what would they see in the file? Random data? Something somebody else wrote some time ago? A copy of /etc/passwd, perhaps? A copy of your credit card number?

#7 lore raw
Quoted 32 lines · Matthew Wilcox
Quoted 23 lines · Shiyang Ruan
Quoted 20 lines · Andrew Morton
Quoted 5 lines · On Thu, 23 Mar 2023 14:50:38 +0800 Shiyang Ruan <[email protected]> wrote:
Quoted 2 lines · Andrew Morton

On Wed, 22 Mar 2023 11:11:09 +0000 Shiyang Ruan <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Please provide much more detail on the user-visible effects of the bug. For example, are we leaking kernel memory contents to userspace?

This fixes fail of generic/649.

OK, but this doesn't really help. I'm trying to determine whether this fix should be backported into -stable kernels and whether it should be fast-tracked into Linus's current -rc tree.

Quoted 7 lines
Quoted 2 lines

But to determine this I (and others) need to know what effect the bug has upon our users.

I didn't get any bug report form users. I just found this by running xfstests. The phenomenon of this problem is: if we funshare a reflinked file which contains HOLE extents, the result of the HOLE extents should be zero but actually not (unexpectable data).

Quoted 4 lines

You still aren't answering the question. If this did happen to a user, what would they see in the file? Random data? Something somebody else wrote some time ago? A copy of /etc/passwd, perhaps? A copy of your credit card number?

Ok. If this happenned to a user, the HOLE or UNWRITTEN part will be old data of the new allocated extent because it didn't be cleared.

--
Thanks,
Ruan.

#8 lore raw
Quoted 35 lines · Shiyang Ruan
Quoted 32 lines · Matthew Wilcox
Quoted 30 lines · Shiyang Ruan
Quoted 14 lines · Andrew Morton
Quoted 12 lines · On Thu, 23 Mar 2023 14:50:38 +0800 Shiyang Ruan <[email protected]> wrote:
Quoted 8 lines · Andrew Morton
Quoted 3 lines · On Wed, 22 Mar 2023 11:11:09 +0000 Shiyang Ruan <[email protected]> wrote:

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Please provide much more detail on the user-visible effects of the bug. For example, are we leaking kernel memory contents to userspace?

Quoted 8 lines
Quoted 1 line

This fixes fail of generic/649.

OK, but this doesn't really help. I'm trying to determine whether this fix should be backported into -stable kernels and whether it should be fast-tracked into Linus's current -rc tree.

But to determine this I (and others) need to know what effect the bug has upon our users.

I didn't get any bug report form users. I just found this by running xfstests. The phenomenon of this problem is: if we funshare a reflinked file which contains HOLE extents, the result of the HOLE extents should be zero but actually not (unexpectable data).

Quoted 7 lines
Quoted 4 lines

You still aren't answering the question. If this did happen to a user, what would they see in the file? Random data? Something somebody else wrote some time ago? A copy of /etc/passwd, perhaps? A copy of your credit card number?

Ok. If this happenned to a user, the HOLE or UNWRITTEN part will be old data of the new allocated extent because it didn't be cleared.

ie it's the data that was in whatever file happened to use that space last, so this is a security bug because it's a data leak, and a backport is needed, and you should have indicated that by putting a cc: stable tag on the patch?

#9 lore raw
Quoted 41 lines · Matthew Wilcox
Quoted 40 lines · Shiyang Ruan
Quoted 36 lines · Matthew Wilcox
Quoted 23 lines · Shiyang Ruan
Quoted 20 lines · Andrew Morton
Quoted 5 lines · On Thu, 23 Mar 2023 14:50:38 +0800 Shiyang Ruan <[email protected]> wrote:
Quoted 2 lines · Andrew Morton

On Wed, 22 Mar 2023 11:11:09 +0000 Shiyang Ruan <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the result will be unexpectable.

Please provide much more detail on the user-visible effects of the bug. For example, are we leaking kernel memory contents to userspace?

This fixes fail of generic/649.

OK, but this doesn't really help. I'm trying to determine whether this fix should be backported into -stable kernels and whether it should be fast-tracked into Linus's current -rc tree.

Quoted 7 lines
Quoted 2 lines

But to determine this I (and others) need to know what effect the bug has upon our users.

I didn't get any bug report form users. I just found this by running xfstests. The phenomenon of this problem is: if we funshare a reflinked file which contains HOLE extents, the result of the HOLE extents should be zero but actually not (unexpectable data).

You still aren't answering the question. If this did happen to a user, what would they see in the file? Random data? Something somebody else wrote some time ago? A copy of /etc/passwd, perhaps? A copy of your credit card number?

Quoted 7 lines
Quoted 2 lines

Ok. If this happenned to a user, the HOLE or UNWRITTEN part will be old data of the new allocated extent because it didn't be cleared.

ie it's the data that was in whatever file happened to use that space last, so this is a security bug because it's a data leak, and a backport is needed, and you should have indicated that by putting a cc: stable tag on the patch?

Yes, cc stable is needed. Then should I send a new patch with the tag added?

--
Thanks,
Ruan.

#10 lore raw
Quoted 7 lines · On Fri, 24 Mar 2023 12:28:07 +0800 Shiyang Ruan <[email protected]> wrote:
Quoted 4 lines

ie it's the data that was in whatever file happened to use that space last, so this is a security bug because it's a data leak, and a backport is needed, and you should have indicated that by putting a cc: stable tag on the patch?

Yes, cc stable is needed. Then should I send a new patch with the tag added?

Thanks. I updated the changelog and added cc:stable.

: unshare copies data from source to destination. But if the source is : HOLE or UNWRITTEN extents, we should zero the destination, otherwise : the HOLE or UNWRITTEN part will be user-visible old data of the new : allocated extent because it wasn't cleared.
:
: Found by running generic/649 while mounting with -o dax=always on pmem.