diff mbox series

virtiofs: include a newline in sysfs tag

Message ID 20240425104400.30222-1-bfoster@redhat.com (mailing list archive)
State New
Headers show
Series virtiofs: include a newline in sysfs tag | expand

Commit Message

Brian Foster April 25, 2024, 10:44 a.m. UTC
The internal tag string doesn't contain a newline. Append one when
emitting the tag via sysfs.

Signed-off-by: Brian Foster <bfoster@redhat.com>
---

Hi all,

I just noticed this and it seemed a little odd to me compared to typical
sysfs output, but maybe it was intentional..? Easy enough to send a
patch either way.. thoughts?

Brian

 fs/fuse/virtio_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Vivek Goyal April 25, 2024, 12:42 p.m. UTC | #1
On Thu, Apr 25, 2024 at 06:44:00AM -0400, Brian Foster wrote:
> The internal tag string doesn't contain a newline. Append one when
> emitting the tag via sysfs.
> 
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> ---
> 
> Hi all,
> 
> I just noticed this and it seemed a little odd to me compared to typical
> sysfs output, but maybe it was intentional..? Easy enough to send a
> patch either way.. thoughts?

In my initial patch I had added a newline char. Then someone gave examples
where sysfs output did not have newline char. So I got rid of it. After
that Stefan posted a new patch series that did not include newline. So
yes it was intentional.

I am sitting on the fence on this one. Don't have a strong preference
either way. Others might have good arguments one way or the other.

Thanks
Vivek

> 
> Brian
> 
>  fs/fuse/virtio_fs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
> index 322af827a232..bb3e941b9503 100644
> --- a/fs/fuse/virtio_fs.c
> +++ b/fs/fuse/virtio_fs.c
> @@ -170,7 +170,7 @@ static ssize_t tag_show(struct kobject *kobj,
>  {
>  	struct virtio_fs *fs = container_of(kobj, struct virtio_fs, kobj);
>  
> -	return sysfs_emit(buf, fs->tag);
> +	return sysfs_emit(buf, "%s\n", fs->tag);
>  }
>  
>  static struct kobj_attribute virtio_fs_tag_attr = __ATTR_RO(tag);
> -- 
> 2.44.0
>
Stefan Hajnoczi April 30, 2024, 5:34 p.m. UTC | #2
On Thu, Apr 25, 2024 at 06:44:00AM -0400, Brian Foster wrote:
> The internal tag string doesn't contain a newline. Append one when
> emitting the tag via sysfs.
> 
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> ---
> 
> Hi all,
> 
> I just noticed this and it seemed a little odd to me compared to typical
> sysfs output, but maybe it was intentional..? Easy enough to send a
> patch either way.. thoughts?

Hi Brian,
Orthogonal to the newline issue, sysfs_emit(buf, "%s", fs->tag) is
needed to prevent format string injection. Please mention this in the
commit description. I'm afraid I introduced that bug, sorry!

Regarding newline, I'm concerned that adding a newline might break
existing programs. Unless there is a concrete need to have the newline,
I would keep things as they are.

Stefan

> 
> Brian
> 
>  fs/fuse/virtio_fs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
> index 322af827a232..bb3e941b9503 100644
> --- a/fs/fuse/virtio_fs.c
> +++ b/fs/fuse/virtio_fs.c
> @@ -170,7 +170,7 @@ static ssize_t tag_show(struct kobject *kobj,
>  {
>  	struct virtio_fs *fs = container_of(kobj, struct virtio_fs, kobj);
>  
> -	return sysfs_emit(buf, fs->tag);
> +	return sysfs_emit(buf, "%s\n", fs->tag);
>  }
>  
>  static struct kobj_attribute virtio_fs_tag_attr = __ATTR_RO(tag);
> -- 
> 2.44.0
>
diff mbox series

Patch

diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 322af827a232..bb3e941b9503 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -170,7 +170,7 @@  static ssize_t tag_show(struct kobject *kobj,
 {
 	struct virtio_fs *fs = container_of(kobj, struct virtio_fs, kobj);
 
-	return sysfs_emit(buf, fs->tag);
+	return sysfs_emit(buf, "%s\n", fs->tag);
 }
 
 static struct kobj_attribute virtio_fs_tag_attr = __ATTR_RO(tag);