Skip to contentSkip to conversation

fuse: Apply flags2 only when userspace set the FUSE_INIT_EXT flag

PATCH In review Bernd Schubert 4 participants 9 messages Apr 15, 2022 – Apr 26, 2022 1 message not in the archive

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

PATCH 1/1 fuse: Apply flags2 only when userspace set the FUSE_INIT_EXT flag

This is just a safety precaution to avoid checking flags on memory that was initialized on the user space side. libfuse zeroes struct fuse_init_out outarg, but this is not guranteed to be done in all implementations. Better is to act on flags and to only apply flags2 when FUSE_INIT_EXT is set.

There is a risk with this change, though - it might break existing user space libraries, which are already using flags2 without setting FUSE_INIT_EXT.

The corresponding libfuse patch is here
https://github.com/libfuse/libfuse/pull/662

---
 fs/fuse/inode.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/fuse/inode.c +4 -1
index 9ee36aa73251..8115a06d5fbb 100644
@@ -1115,7 +1115,10 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 		process_init_limits(fc, arg);
 
 		if (arg->minor >= 6) {
-			u64 flags = arg->flags | (u64) arg->flags2 << 32;
+			u64 flags = arg->flags;
+
+			if (flags & FUSE_INIT_EXT)
+				flags |= (u64) arg->flags2 << 32;
 
 			ra_pages = arg->max_readahead / PAGE_SIZE;
 			if (flags & FUSE_ASYNC_READ)
maintainer
#1 lore raw
Quoted 12 lines · Bernd Schubert

This is just a safety precaution to avoid checking flags on memory that was initialized on the user space side. libfuse zeroes struct fuse_init_out outarg, but this is not guranteed to be done in all implementations. Better is to act on flags and to only apply flags2 when FUSE_INIT_EXT is set.

There is a risk with this change, though - it might break existing user space libraries, which are already using flags2 without setting FUSE_INIT_EXT.

Quoted 5 lines

The corresponding libfuse patch is here
https://github.com/libfuse/libfuse/pull/662

Agreed, this is a good change. Applied.

Just one comment: please consider adding "Fixes:" and "Cc:
<stable@....>" tags next time. I added them now.

Thanks,
Miklos

#2 lore raw
Quoted 4 lines · Miklos Szeredi

Agreed, this is a good change. Applied.

Just one comment: please consider adding "Fixes:" and "Cc:
<stable@....>" tags next time. I added them now.

Thank you! And sorry, sure, I will do next time.

#3 lore raw
In reply to Miklos Szeredi
Quoted 17 lines · Miklos Szeredi
Quoted 16 lines · Bernd Schubert

This is just a safety precaution to avoid checking flags on memory that was initialized on the user space side. libfuse zeroes struct fuse_init_out outarg, but this is not guranteed to be done in all implementations. Better is to act on flags and to only apply flags2 when FUSE_INIT_EXT is set.

There is a risk with this change, though - it might break existing user space libraries, which are already using flags2 without setting FUSE_INIT_EXT.

The corresponding libfuse patch is here
https://github.com/libfuse/libfuse/pull/662

Quoted 6 lines
Quoted 1 line

Agreed, this is a good change. Applied.

Just one comment: please consider adding "Fixes:" and "Cc:
<stable@....>" tags next time. I added them now.

I am afraid that this probably will break both C and rust version of virtiofsd. I had a quick look and I can't seem to find these implementations setting INIT_EXT flag in reply to init.

I am travelling. Will check it more closely when I return next week. If virtiofsd implementations don't set INIT_EXT, I would rather prefer to not do this change and avoid breaking it.

Thanks
Vivek

A message that is not in the archive (sent off-list or not yet received): DM5PR1901MB20375D0CF53C5F7D338154D0B5F99@DM5PR1901MB2037.namprd19.prod.outlook.com

#5 lore raw
Quoted 1 line · Bernd Schubert

I'm also traveling, but I had checked a bit the links you had given and even created github issue for the rust-fuse because it uses conflicting flags - seems to rely on non-upstream kernel.

FYI at least the C version virtiofsd ([email protected]:qemu/qemu.git master) doesn't set FUSE_INIT_EXT on the reply to FUSE_INIT. I didn't check the Rust version, since I'm not familiar with Rust so far...

I guess Vivek was referring to [1] when he mentioned the rust version of virtiofsd. This is the rust version developed by the RedHat.

As for the "rust-fuse" Bernd Schubert mentioned, actually it's [2] developed by the Alibaba folks. We tried to make this fuse daemon support the per-inode DAX feature when the feature is still in the progress of upstreaming kernel. Later when the feature finally gets merged to mainline kernel, the position of the FUSE_HAS_INODE_DAX flag bit is a little different with the initial implementation. Sadly we forget to fix this, and the fuse daemon keeps using the flag bit different from the mainline version. Sorry for that. Thanks for pointing it out and we are going to fix it. Thanks.

[1] https://gitlab.com/virtio-fs/virtiofsd
[2] https://github.com/cloud-hypervisor/fuse-backend-rs

Quoted 46 lines

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: Vivek Goyal <[email protected]>
Sent: Sunday, April 24, 2022 10:29:25 AM
To: Miklos Szeredi <[email protected]>
Cc: Bernd Schubert <[email protected]>; [email protected] <[email protected]>; Jeffle Xu <[email protected]>; Dharmendra Singh <[email protected]>; Dr. David Alan Gilbert <[email protected]>; German Maglione <[email protected]>
Subject: Re: [PATCH] fuse: Apply flags2 only when userspace set the FUSE_INIT_EXT flag

Quoted 17 lines · Miklos Szeredi
Quoted 16 lines · Bernd Schubert

This is just a safety precaution to avoid checking flags on memory that was initialized on the user space side. libfuse zeroes struct fuse_init_out outarg, but this is not guranteed to be done in all implementations. Better is to act on flags and to only apply flags2 when FUSE_INIT_EXT is set.

There is a risk with this change, though - it might break existing user space libraries, which are already using flags2 without setting FUSE_INIT_EXT.

The corresponding libfuse patch is here
https://github.com/libfuse/libfuse/pull/662

Quoted 6 lines
Quoted 1 line

Agreed, this is a good change. Applied.

Just one comment: please consider adding "Fixes:" and "Cc:
<stable@....>" tags next time. I added them now.

I am afraid that this probably will break both C and rust version of virtiofsd. I had a quick look and I can't seem to find these implementations setting INIT_EXT flag in reply to init.

I am travelling. Will check it more closely when I return next week. If virtiofsd implementations don't set INIT_EXT, I would rather prefer to not do this change and avoid breaking it.

Thanks
Vivek

Signature · 2 lines
Thanks,
Jeffle
maintainer
#6 lore raw
In reply to Vivek Goyal
Quoted 26 lines · Vivek Goyal
Quoted 17 lines · Miklos Szeredi
Quoted 16 lines · Bernd Schubert

This is just a safety precaution to avoid checking flags on memory that was initialized on the user space side. libfuse zeroes struct fuse_init_out outarg, but this is not guranteed to be done in all implementations. Better is to act on flags and to only apply flags2 when FUSE_INIT_EXT is set.

There is a risk with this change, though - it might break existing user space libraries, which are already using flags2 without setting FUSE_INIT_EXT.

The corresponding libfuse patch is here
https://github.com/libfuse/libfuse/pull/662

Quoted 6 lines
Quoted 1 line

Agreed, this is a good change. Applied.

Just one comment: please consider adding "Fixes:" and "Cc:
<stable@....>" tags next time. I added them now.

Quoted 7 lines

I am afraid that this probably will break both C and rust version of virtiofsd. I had a quick look and I can't seem to find these implementations setting INIT_EXT flag in reply to init.

I am travelling. Will check it more closely when I return next week. If virtiofsd implementations don't set INIT_EXT, I would rather prefer to not do this change and avoid breaking it.

Okay, let's postpone this kernel patch until libfuse and virtiofsd implementations are updated.

Thanks,
Miklos

#7 lore raw
Quoted 31 lines · Miklos Szeredi
Quoted 30 lines · Vivek Goyal
Quoted 17 lines · Miklos Szeredi
Quoted 16 lines · Bernd Schubert

This is just a safety precaution to avoid checking flags on memory that was initialized on the user space side. libfuse zeroes struct fuse_init_out outarg, but this is not guranteed to be done in all implementations. Better is to act on flags and to only apply flags2 when FUSE_INIT_EXT is set.

There is a risk with this change, though - it might break existing user space libraries, which are already using flags2 without setting FUSE_INIT_EXT.

The corresponding libfuse patch is here
https://github.com/libfuse/libfuse/pull/662

Quoted 6 lines
Quoted 1 line

Agreed, this is a good change. Applied.

Just one comment: please consider adding "Fixes:" and "Cc:
<stable@....>" tags next time. I added them now.

I am afraid that this probably will break both C and rust version of virtiofsd. I had a quick look and I can't seem to find these implementations setting INIT_EXT flag in reply to init.

Quoted 6 lines
Quoted 3 lines

I am travelling. Will check it more closely when I return next week. If virtiofsd implementations don't set INIT_EXT, I would rather prefer to not do this change and avoid breaking it.

Okay, let's postpone this kernel patch until libfuse and virtiofsd implementations are updated.

Ok. I will work on fixing virtiofsd implementation. Even if we fix it, then older versions will still be broken with newer kernels. I am wondering, which clients are not setting flags2 to zero. And if they are not setting it to zero, it sounds like a bug to me in fuse servers instead and should probably be fixed there without breaking things for existing users.

Agree that it probably is a nice change if we had introduced this in the beginning itself. Its like extra saftey net. But now if we add it, it will break things which is not nice. So at this point of time, it probably is better to fix fuse servers instead and set ->flags2 to zero, IMHO.

Thanks
Vivek

maintainer
#8 lore raw
Quoted 4 lines · Vivek Goyal

Agree that it probably is a nice change if we had introduced this in the beginning itself. Its like extra saftey net. But now if we add it, it will break things which is not nice. So at this point of time, it probably is better to fix fuse servers instead and set ->flags2 to zero, IMHO.

I think the question is whether the "unfixed" virtiofsd implementations made it into any sort of release or not.

If not, then I think it's fine to break unreleased versions, since they are ephemeral anyway.

Thanks,
Miklos

#9 lore raw
Quoted 9 lines · Miklos Szeredi
Quoted 4 lines · Vivek Goyal

Agree that it probably is a nice change if we had introduced this in the beginning itself. Its like extra saftey net. But now if we add it, it will break things which is not nice. So at this point of time, it probably is better to fix fuse servers instead and set ->flags2 to zero, IMHO.

I think the question is whether the "unfixed" virtiofsd implementations made it into any sort of release or not.

Existing unfixed versions are already released in various releses. C version of virtiofsd is already being used in RHEL8 release and some fedora releases. And rust version of virtiofsd is supposed to be in RHEL9 beta.

Hence if we change it now, it is possible older virtiofsd (unfixed one) is running on host and trying to boot a newer guest kernel and that leads to breaking things.

Thanks
Vivek

Quoted 8 lines

If not, then I think it's fine to break unreleased versions, since they are ephemeral anyway.

Thanks,
Miklos