stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: scrub: reject unsupported scrub flags
@ 2023-04-06  5:00 Qu Wenruo
  2023-04-06  5:36 ` Anand Jain
  2023-04-06 15:01 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Qu Wenruo @ 2023-04-06  5:00 UTC (permalink / raw)
  To: linux-btrfs; +Cc: stable

Since the introduction of scrub interface, the only flag that we support
is BTRFS_SCRUB_READONLY.

Thus there is no sanity checks, if there are some undefined flags passed
in, we just ignore them.

This is problematic if we want to introduce new scrub flags, as we have
no way to determine if such flags are supported.

Thus this patch would address the problem by introducing a check for the
flags, and if unsupported flags are set, return -EOPNOTSUPP to inform
the user space.

This check should be backported for all supported kernels before any new
scrub flags are introduced.

CC: stable@vger.kernel.org
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/ioctl.c           | 5 +++++
 include/uapi/linux/btrfs.h | 1 +
 2 files changed, 6 insertions(+)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index ba769a1eb87a..25833b4eeaf5 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3161,6 +3161,11 @@ static long btrfs_ioctl_scrub(struct file *file, void __user *arg)
 	if (IS_ERR(sa))
 		return PTR_ERR(sa);
 
+	if (sa->flags & ~BTRFS_SCRUB_SUPPORTED_FLAGS) {
+		ret = -EOPNOTSUPP;
+		goto out;
+	}
+
 	if (!(sa->flags & BTRFS_SCRUB_READONLY)) {
 		ret = mnt_want_write_file(file);
 		if (ret)
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index ada0a489bf2b..dbb8b96da50d 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -187,6 +187,7 @@ struct btrfs_scrub_progress {
 };
 
 #define BTRFS_SCRUB_READONLY	1
+#define BTRFS_SCRUB_SUPPORTED_FLAGS	(BTRFS_SCRUB_READONLY)
 struct btrfs_ioctl_scrub_args {
 	__u64 devid;				/* in */
 	__u64 start;				/* in */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: scrub: reject unsupported scrub flags
  2023-04-06  5:00 [PATCH] btrfs: scrub: reject unsupported scrub flags Qu Wenruo
@ 2023-04-06  5:36 ` Anand Jain
  2023-04-06 15:01 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Anand Jain @ 2023-04-06  5:36 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs; +Cc: stable

On 4/6/23 13:00, Qu Wenruo wrote:
> Since the introduction of scrub interface, the only flag that we support
> is BTRFS_SCRUB_READONLY.
> 
> Thus there is no sanity checks, if there are some undefined flags passed
> in, we just ignore them.
> 
> This is problematic if we want to introduce new scrub flags, as we have
> no way to determine if such flags are supported.
> 
> Thus this patch would address the problem by introducing a check for the
> flags, and if unsupported flags are set, return -EOPNOTSUPP to inform
> the user space.
> 
> This check should be backported for all supported kernels before any new
> scrub flags are introduced.
> 
> CC: stable@vger.kernel.org
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Reviewed-by: Anand Jain <anand.jain@oracle.com>


> ---
>   fs/btrfs/ioctl.c           | 5 +++++
>   include/uapi/linux/btrfs.h | 1 +
>   2 files changed, 6 insertions(+)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index ba769a1eb87a..25833b4eeaf5 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -3161,6 +3161,11 @@ static long btrfs_ioctl_scrub(struct file *file, void __user *arg)
>   	if (IS_ERR(sa))
>   		return PTR_ERR(sa);
>   
> +	if (sa->flags & ~BTRFS_SCRUB_SUPPORTED_FLAGS) {
> +		ret = -EOPNOTSUPP;
> +		goto out;
> +	}
> +
>   	if (!(sa->flags & BTRFS_SCRUB_READONLY)) {
>   		ret = mnt_want_write_file(file);
>   		if (ret)
> diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
> index ada0a489bf2b..dbb8b96da50d 100644
> --- a/include/uapi/linux/btrfs.h
> +++ b/include/uapi/linux/btrfs.h
> @@ -187,6 +187,7 @@ struct btrfs_scrub_progress {
>   };
>   
>   #define BTRFS_SCRUB_READONLY	1
> +#define BTRFS_SCRUB_SUPPORTED_FLAGS	(BTRFS_SCRUB_READONLY)
>   struct btrfs_ioctl_scrub_args {
>   	__u64 devid;				/* in */
>   	__u64 start;				/* in */


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: scrub: reject unsupported scrub flags
  2023-04-06  5:00 [PATCH] btrfs: scrub: reject unsupported scrub flags Qu Wenruo
  2023-04-06  5:36 ` Anand Jain
@ 2023-04-06 15:01 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2023-04-06 15:01 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, stable

On Thu, Apr 06, 2023 at 01:00:34PM +0800, Qu Wenruo wrote:
> Since the introduction of scrub interface, the only flag that we support
> is BTRFS_SCRUB_READONLY.
> 
> Thus there is no sanity checks, if there are some undefined flags passed
> in, we just ignore them.
> 
> This is problematic if we want to introduce new scrub flags, as we have
> no way to determine if such flags are supported.
> 
> Thus this patch would address the problem by introducing a check for the
> flags, and if unsupported flags are set, return -EOPNOTSUPP to inform
> the user space.
> 
> This check should be backported for all supported kernels before any new
> scrub flags are introduced.
> 
> CC: stable@vger.kernel.org
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Added to misc-next, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-04-06 15:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06  5:00 [PATCH] btrfs: scrub: reject unsupported scrub flags Qu Wenruo
2023-04-06  5:36 ` Anand Jain
2023-04-06 15:01 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).